Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
- bar
stdout:
- baz
- qux
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdin("foo\\nbar", prompt=False).stdout("baz\\nqux", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
- run: python3 foo.py
stdout: |
Hello
World!
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdout("Hello\\nWorld!\\n", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
def test_missing_exit(self):
checks = yaml.safe_load(\
"""checks:
bar:
- run: python3 foo.py
""")["checks"]
result = _simple.compile(checks)
self.assertTrue(".exit()" in result)
bar:
- run: python3 foo.py
stdin: baz
stdout: baz
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdin("baz", prompt=False).stdout("baz", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").exit(0)
@check50.check()
def baz():
\"\"\"baz\"\"\"
check50.run("python3 foo.py").exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
def test_space_in_name(self):
checks = yaml.safe_load(\
"""checks:
bar baz:
- run: python3 foo.py
""")["checks"]
result = _simple.compile(checks)
self.assertTrue("def bar_baz" in result)
self.assertTrue("\"\"\"bar baz\"\"\"" in result)
def test_dash_in_name(self):
checks = yaml.safe_load(\
"""checks:
bar-baz:
- run: python3 foo.py
""")["checks"]
result = _simple.compile(checks)
self.assertTrue("def bar_baz" in result)
self.assertTrue("\"\"\"bar-baz\"\"\"" in result)
def test_number_in_name(self):
checks = yaml.safe_load(\
"""checks:
0bar:
- run: python3 foo.py
""")["checks"]
result = _simple.compile(checks)
self.assertTrue("def _0bar" in result)
self.assertTrue("\"\"\"0bar\"\"\"" in result)
:type prompt: bool
:param out_file: file to write compiled checks
:type out_file: str
:returns: ``out_file``
:rtype: str
"""
file_path = check_dir / out_file
# Prompt to replace __init__.py (compile destination)
if prompt and file_path.exists():
if not _yes_no_prompt("check50 will compile the YAML checks to __init__.py, are you sure you want to overwrite its contents?"):
raise Error("Aborting: could not overwrite to __init__.py")
# Compile simple checks
with open(check_dir / out_file, "w") as f:
f.write(_simple.compile(checks))
return out_file