forked from test_framework/pytest-bdd
Merge pull request #246 from asottile/mostly_factor_out_py
Mostly factor out `py` module
This commit is contained in:
commit
fb2840391f
|
@ -37,7 +37,7 @@ nosetests.xml
|
|||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
.cache
|
||||
.pytest_cache
|
||||
.ropeproject
|
||||
|
||||
# Sublime
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
"""Cucumber json output formatter."""
|
||||
|
||||
import codecs
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
import py
|
||||
import re
|
||||
import six
|
||||
|
||||
from .feature import force_unicode
|
||||
|
@ -185,8 +185,8 @@ class LogBDDCucumberJSON(object):
|
|||
self.suite_start_time = time.time()
|
||||
|
||||
def pytest_sessionfinish(self):
|
||||
if py.std.sys.version_info[0] < 3:
|
||||
logfile_open = py.std.codecs.open
|
||||
if sys.version_info[0] < 3:
|
||||
logfile_open = codecs.open
|
||||
else:
|
||||
logfile_open = open
|
||||
with logfile_open(self.logfile, "w", encoding="utf-8") as logfile:
|
||||
|
|
|
@ -28,6 +28,9 @@ def migrate_tests_in_file(file_path):
|
|||
content = fd.read()
|
||||
new_content = MIGRATE_REGEX.sub(r"\n@scenario(\2)\ndef \1():\n pass\n", content)
|
||||
if new_content != content:
|
||||
# the regex above potentially causes the end of the file to
|
||||
# have an extra newline
|
||||
new_content = new_content.rstrip('\n') + '\n'
|
||||
fd.seek(0)
|
||||
fd.write(new_content)
|
||||
print("migrated: {0}".format(file_path))
|
||||
|
|
1
setup.py
1
setup.py
|
@ -75,6 +75,7 @@ setup(
|
|||
"Mako",
|
||||
"parse",
|
||||
"parse_type",
|
||||
"py",
|
||||
"pytest>=2.8.1",
|
||||
"six>=1.9.0",
|
||||
],
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import py
|
||||
import textwrap
|
||||
|
||||
|
||||
def test_arg_fixture_mix(testdir):
|
||||
|
||||
subdir = testdir.mkpydir("arg_fixture_mix")
|
||||
subdir.join("test_a.py").write(py.code.Source("""
|
||||
subdir.join("test_a.py").write(textwrap.dedent("""
|
||||
import re
|
||||
import pytest
|
||||
from pytest_bdd import scenario, given, then, parsers
|
||||
|
@ -47,7 +47,7 @@ def test_arg_fixture_mix(testdir):
|
|||
assert foo == "fine"
|
||||
"""))
|
||||
|
||||
subdir.join("test_b.py").write(py.code.Source("""
|
||||
subdir.join("test_b.py").write(textwrap.dedent("""
|
||||
import re
|
||||
import pytest
|
||||
from pytest_bdd import scenario, given, then
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Test no scenarios defined in the feature file."""
|
||||
|
||||
import py
|
||||
import textwrap
|
||||
|
||||
|
||||
|
@ -12,7 +11,7 @@ def test_no_scenarios(testdir):
|
|||
When bar
|
||||
Then baz
|
||||
"""), 'utf-8', ensure=True)
|
||||
testdir.makepyfile(py.code.Source("""
|
||||
testdir.makepyfile(textwrap.dedent("""
|
||||
|
||||
from pytest_bdd import scenarios
|
||||
|
||||
|
@ -34,7 +33,7 @@ def test_only_background_strict_mode(testdir):
|
|||
Given foo
|
||||
When bar
|
||||
"""), 'utf-8', ensure=True)
|
||||
testdir.makepyfile(py.code.Source("""
|
||||
testdir.makepyfile(textwrap.dedent("""
|
||||
|
||||
from pytest_bdd import scenarios
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
"""Code generation and assertion tests."""
|
||||
import itertools
|
||||
import os.path
|
||||
|
||||
import py
|
||||
import textwrap
|
||||
|
||||
from pytest_bdd.scenario import get_python_name_generator
|
||||
|
||||
|
@ -19,7 +18,7 @@ def test_generate_missing(testdir):
|
|||
with open(os.path.join(os.path.dirname(__file__), "generation.feature")) as fd:
|
||||
tests.join('generation.feature').write(fd.read())
|
||||
|
||||
tests.join("test_foo.py").write(py.code.Source("""
|
||||
tests.join("test_foo.py").write(textwrap.dedent("""
|
||||
import functools
|
||||
|
||||
from pytest_bdd import scenario, given
|
||||
|
|
|
@ -3,8 +3,6 @@ import os
|
|||
import sys
|
||||
import textwrap
|
||||
|
||||
import py
|
||||
|
||||
from pytest_bdd.scripts import main
|
||||
|
||||
PATH = os.path.dirname(__file__)
|
||||
|
@ -14,7 +12,7 @@ def test_migrate(monkeypatch, capsys, testdir):
|
|||
"""Test if the code is migrated by a given file mask."""
|
||||
tests = testdir.mkpydir('tests')
|
||||
|
||||
tests.join("test_foo.py").write(py.code.Source('''
|
||||
tests.join("test_foo.py").write(textwrap.dedent('''
|
||||
"""Foo bar tests."""
|
||||
from pytest_bdd import scenario
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import py
|
||||
import textwrap
|
||||
|
||||
|
||||
def test_hooks(testdir):
|
||||
testdir.makeconftest("")
|
||||
|
||||
subdir = testdir.mkpydir("subdir")
|
||||
subdir.join("conftest.py").write(py.code.Source(r"""
|
||||
subdir.join("conftest.py").write(textwrap.dedent(r"""
|
||||
def pytest_pyfunc_call(pyfuncitem):
|
||||
print('\npytest_pyfunc_call hook')
|
||||
|
||||
|
@ -13,7 +13,7 @@ def test_hooks(testdir):
|
|||
print('\npytest_generate_tests hook')
|
||||
"""))
|
||||
|
||||
subdir.join("test_foo.py").write(py.code.Source(r"""
|
||||
subdir.join("test_foo.py").write(textwrap.dedent(r"""
|
||||
from pytest_bdd import scenario
|
||||
|
||||
@scenario('foo.feature', 'Some scenario')
|
||||
|
@ -21,7 +21,7 @@ def test_hooks(testdir):
|
|||
pass
|
||||
"""))
|
||||
|
||||
subdir.join("foo.feature").write(py.code.Source(r"""
|
||||
subdir.join("foo.feature").write(textwrap.dedent(r"""
|
||||
Feature: The feature
|
||||
Scenario: Some scenario
|
||||
"""))
|
||||
|
|
Loading…
Reference in New Issue