Skip to content

Commit 685ae80

Browse files
committed
Mostly factor out py module
Still used for `py.io.TerminalWriter` so I added it to `setup.py`
1 parent 0ac2447 commit 685ae80

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ nosetests.xml
3737
.mr.developer.cfg
3838
.project
3939
.pydevproject
40-
.cache
40+
.pytest_cache
4141
.ropeproject
4242

4343
# Sublime

pytest_bdd/cucumber_json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Cucumber json output formatter."""
22

3+
import codecs
34
import json
45
import math
56
import os
7+
import sys
68
import time
79

8-
import py
9-
import re
1010
import six
1111

1212
from .feature import force_unicode
@@ -185,8 +185,8 @@ def pytest_sessionstart(self):
185185
self.suite_start_time = time.time()
186186

187187
def pytest_sessionfinish(self):
188-
if py.std.sys.version_info[0] < 3:
189-
logfile_open = py.std.codecs.open
188+
if sys.version_info[0] < 3:
189+
logfile_open = codecs.open
190190
else:
191191
logfile_open = open
192192
with logfile_open(self.logfile, "w", encoding="utf-8") as logfile:

pytest_bdd/scripts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def migrate_tests_in_file(file_path):
2828
content = fd.read()
2929
new_content = MIGRATE_REGEX.sub(r"\n@scenario(\2)\ndef \1():\n pass\n", content)
3030
if new_content != content:
31+
# the regex above potentially causes the end of the file to
32+
# have an extra newline
33+
new_content = new_content.rstrip('\n') + '\n'
3134
fd.seek(0)
3235
fd.write(new_content)
3336
print("migrated: {0}".format(file_path))

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def run_tests(self):
7575
"Mako",
7676
"parse",
7777
"parse_type",
78+
"py",
7879
"pytest>=2.8.1",
7980
"six>=1.9.0",
8081
],

tests/args/test_arg_fixture_mix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import py
1+
import textwrap
22

33

44
def test_arg_fixture_mix(testdir):
55

66
subdir = testdir.mkpydir("arg_fixture_mix")
7-
subdir.join("test_a.py").write(py.code.Source("""
7+
subdir.join("test_a.py").write(textwrap.dedent("""
88
import re
99
import pytest
1010
from pytest_bdd import scenario, given, then, parsers
@@ -47,7 +47,7 @@ def foo_should_be_fine(foo):
4747
assert foo == "fine"
4848
"""))
4949

50-
subdir.join("test_b.py").write(py.code.Source("""
50+
subdir.join("test_b.py").write(textwrap.dedent("""
5151
import re
5252
import pytest
5353
from pytest_bdd import scenario, given, then

tests/feature/test_no_scenario.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test no scenarios defined in the feature file."""
22

3-
import py
43
import textwrap
54

65

@@ -12,7 +11,7 @@ def test_no_scenarios(testdir):
1211
When bar
1312
Then baz
1413
"""), 'utf-8', ensure=True)
15-
testdir.makepyfile(py.code.Source("""
14+
testdir.makepyfile(textwrap.dedent("""
1615
1716
from pytest_bdd import scenarios
1817
@@ -34,7 +33,7 @@ def test_only_background_strict_mode(testdir):
3433
Given foo
3534
When bar
3635
"""), 'utf-8', ensure=True)
37-
testdir.makepyfile(py.code.Source("""
36+
testdir.makepyfile(textwrap.dedent("""
3837
3938
from pytest_bdd import scenarios
4039

tests/generation/test_generate_missing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Code generation and assertion tests."""
22
import itertools
33
import os.path
4-
5-
import py
4+
import textwrap
65

76
from pytest_bdd.scenario import get_python_name_generator
87

@@ -19,7 +18,7 @@ def test_generate_missing(testdir):
1918
with open(os.path.join(os.path.dirname(__file__), "generation.feature")) as fd:
2019
tests.join('generation.feature').write(fd.read())
2120

22-
tests.join("test_foo.py").write(py.code.Source("""
21+
tests.join("test_foo.py").write(textwrap.dedent("""
2322
import functools
2423
2524
from pytest_bdd import scenario, given

tests/scripts/test_migrate.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import sys
44
import textwrap
55

6-
import py
7-
86
from pytest_bdd.scripts import main
97

108
PATH = os.path.dirname(__file__)
@@ -14,7 +12,7 @@ def test_migrate(monkeypatch, capsys, testdir):
1412
"""Test if the code is migrated by a given file mask."""
1513
tests = testdir.mkpydir('tests')
1614

17-
tests.join("test_foo.py").write(py.code.Source('''
15+
tests.join("test_foo.py").write(textwrap.dedent('''
1816
"""Foo bar tests."""
1917
from pytest_bdd import scenario
2018

tests/test_hooks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import py
1+
import textwrap
22

33

44
def test_hooks(testdir):
55
testdir.makeconftest("")
66

77
subdir = testdir.mkpydir("subdir")
8-
subdir.join("conftest.py").write(py.code.Source(r"""
8+
subdir.join("conftest.py").write(textwrap.dedent(r"""
99
def pytest_pyfunc_call(pyfuncitem):
1010
print('\npytest_pyfunc_call hook')
1111
1212
def pytest_generate_tests(metafunc):
1313
print('\npytest_generate_tests hook')
1414
"""))
1515

16-
subdir.join("test_foo.py").write(py.code.Source(r"""
16+
subdir.join("test_foo.py").write(textwrap.dedent(r"""
1717
from pytest_bdd import scenario
1818
1919
@scenario('foo.feature', 'Some scenario')
2020
def test_foo():
2121
pass
2222
"""))
2323

24-
subdir.join("foo.feature").write(py.code.Source(r"""
24+
subdir.join("foo.feature").write(textwrap.dedent(r"""
2525
Feature: The feature
2626
Scenario: Some scenario
2727
"""))

0 commit comments

Comments
 (0)