Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_content_steps(self, content):
content = dedent(content)
pf = PythonFile.parse("foo.py", content)
self.assertIsNotNone(pf)
loader.load_steps(pf)
def load_content_steps(self, content):
content = dedent(content)
pf = PythonFile.parse("foo.py", content)
self.assertIsNotNone(pf)
loader.load_steps(pf)
def test_loader_reload_registry_for_given_content_with_empty_arg(self):
content = dedent("""
@step("print hello <>")
def printf(arg1):
print(arg1)
""")
load_steps(PythonFile.parse("foo.py", content))
self.assertTrue(registry.is_implemented("print hello {}"))
def test_loader_populates_registry_from_given_file_content(self):
content = dedent("""
@step("print hello")
def printf():
print("hello")
@step("print .")
def print_word(word):
print(word)
""")
load_steps(PythonFile.parse("foo.py", content))
self.assertTrue(registry.is_implemented("print hello"))
self.assertTrue(registry.is_implemented("print {}."))
self.assertEqual(len(registry.steps()), 2)
def tearDown(self):
PythonFile.select_python_parser()
def setUp(self):
PythonFile.select_python_parser('parso')
RefactorTests.setUp(self)
def tearDown(self):
RefactorTests.tearDown(self)
PythonFile.select_python_parser()
def refactor_step(request, response):
if registry.has_multiple_impls(request.oldStepValue.stepValue):
raise Exception('Multiple Implementation found for `{}`'.format(
request.oldStepValue.parameterizedStepValue
))
info = registry.get_info_for(request.oldStepValue.stepValue)
impl_file = PythonFile.parse(info.file_name)
diffs = impl_file.refactor_step(
info.step_text,
request.newStepValue.parameterizedStepValue,
_new_parameter_positions(request),
)
content = impl_file.get_code()
if request.saveChanges:
with open(info.file_name, 'w') as f:
f.write(content)
response.success = True
response.filesChanged.append(info.file_name)
response.fileChanges.add(
fileName=info.file_name,
fileContent=content, # FIXME: Remove deprecated field
diffs=[TextDiff(span=Span(**d[0]), content=d[1]) for d in diffs],
)
def load_files(step_impl_dirs):
for step_impl_dir in step_impl_dirs:
for dirpath, _, files in os.walk(step_impl_dir):
py_files = (os.path.join(dirpath, f) for f in files if f.endswith('.py'))
for file_path in py_files:
pf = PythonFile.parse(file_path)
if pf:
load_steps(pf)
def reload_steps(file_path, content=None):
pf = PythonFile.parse(file_path, content)
if pf:
registry.remove_steps(file_path)
load_steps(pf)