This commit is contained in:
Anatoly Bubenkov 2014-03-14 13:36:36 +01:00
parent c5237a217e
commit d052bbe998
3 changed files with 13 additions and 5 deletions

1
.gitignore vendored
View File

@ -46,3 +46,4 @@ nosetests.xml
/include
/src
/share
/local

View File

@ -1,11 +1,11 @@
"""pytest-bdd scripts."""
import glob
import glob2
import os.path
import re
import sys
MIGRATE_REGEX = re.compile(r'(\w+)\s\=\sscenario\((.+)\)')
MIGRATE_REGEX = re.compile(r'\s?(\w+)\s\=\sscenario\((.+)\)', flags=re.MULTILINE)
def migrate_tests():
@ -14,10 +14,14 @@ def migrate_tests():
print 'Usage: pytestbdd_migrate_tests <path>'
sys.exit(1)
path = sys.argv[1]
for file_path in glob.iglob(os.path.join(os.path.abspath(path), '**', '*.py')):
for file_path in glob2.iglob(os.path.join(os.path.abspath(path), '**', '*.py')):
migrate_tests_in_file(file_path)
def migrate_tests_in_file(file_path):
"""Migrate all bdd-based tests in the given test file."""
re.sub(MIGRATE_REGEX, '@scenario(2)\ndef 1():\n pass', open(file_path), flags=re.MULTILINE)
with open(file_path, 'w') as fd:
content = fd.read()
content = MIGRATE_REGEX.sub('@scenario(2)\ndef 1():\n pass', content)
fd.seek(0)
fd.write(content)

View File

@ -61,9 +61,12 @@ setup(
'pytest-bdd = pytest_bdd.plugin',
],
'console_scripts': [
'pytestbdd_migrate_tests = pytest_bdd.scripts:migrate_tests'
'pytestbdd_migrate_tests = pytest_bdd.scripts:migrate_tests [migrate]'
]
},
tests_require=['detox'],
extras_require={
'migrate': ['glob2']
},
packages=['pytest_bdd'],
)