migrate
This commit is contained in:
parent
c5237a217e
commit
d052bbe998
|
@ -46,3 +46,4 @@ nosetests.xml
|
||||||
/include
|
/include
|
||||||
/src
|
/src
|
||||||
/share
|
/share
|
||||||
|
/local
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
"""pytest-bdd scripts."""
|
"""pytest-bdd scripts."""
|
||||||
import glob
|
import glob2
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import sys
|
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():
|
def migrate_tests():
|
||||||
|
@ -14,10 +14,14 @@ def migrate_tests():
|
||||||
print 'Usage: pytestbdd_migrate_tests <path>'
|
print 'Usage: pytestbdd_migrate_tests <path>'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
path = sys.argv[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)
|
migrate_tests_in_file(file_path)
|
||||||
|
|
||||||
|
|
||||||
def migrate_tests_in_file(file_path):
|
def migrate_tests_in_file(file_path):
|
||||||
"""Migrate all bdd-based tests in the given test file."""
|
"""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)
|
||||||
|
|
5
setup.py
5
setup.py
|
@ -61,9 +61,12 @@ setup(
|
||||||
'pytest-bdd = pytest_bdd.plugin',
|
'pytest-bdd = pytest_bdd.plugin',
|
||||||
],
|
],
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'pytestbdd_migrate_tests = pytest_bdd.scripts:migrate_tests'
|
'pytestbdd_migrate_tests = pytest_bdd.scripts:migrate_tests [migrate]'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
tests_require=['detox'],
|
tests_require=['detox'],
|
||||||
|
extras_require={
|
||||||
|
'migrate': ['glob2']
|
||||||
|
},
|
||||||
packages=['pytest_bdd'],
|
packages=['pytest_bdd'],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue