How to use the check50._simple.compile function in check50

To help you get started, we’ve selected a few check50 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cs50 / check50 / tests / simple_tests.py View on Github external
- 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)
github cs50 / check50 / tests / simple_tests.py View on Github external
- 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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
""")["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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / check50 / internal.py View on Github external
: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