How to use the check50._simple.CompileError 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 / check50 / _simple.py View on Github external
def _compile_check(name, check):
    indent = " " * 4

    # Allow check names to contain spaces/dashes, but replace them with underscores
    check_name = name.replace(' ', '_').replace('-', '_')

    # Allow check names to start with numbers by prepending an _ to them
    if check_name[0].isdigit():
        check_name = f"_{check_name}"

    if not re.match("\w+", check_name):
        raise CompileError(
                _("{} is not a valid name for a check; check names should consist only of alphanumeric characters, underscores, and spaces").format(name))

    out = ["@check50.check()",
           f"def {check_name}():",
           f'{indent}"""{name}"""']

    for run in check:
        _validate(name, run)

        # Append exit with no args if unspecified
        if "exit" not in run:
            run["exit"] = None

        line = [f"{indent}check50"]

        for command_name in COMMANDS:
github cs50 / check50 / check50 / _simple.py View on Github external
def _validate(name, run):
    if run == "run":
        raise CompileError(_("You forgot a - in front of run"))

    for key in run:
        if key not in COMMANDS:
            raise UnsupportedCommand(
                _("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))

    for required_command in ["run"]:
        if required_command not in run:
            raise MissingCommand(_("Missing {} in check {}").format(required_name, name))
github cs50 / check50 / check50 / _simple.py View on Github external
for key in run:
        if key not in COMMANDS:
            raise UnsupportedCommand(
                _("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))

    for required_command in ["run"]:
        if required_command not in run:
            raise MissingCommand(_("Missing {} in check {}").format(required_name, name))


class CompileError(Exception):
    pass


class UnsupportedCommand(CompileError):
    pass


class MissingCommand(CompileError):
    pass


class InvalidArgument(CompileError):
    pass
github cs50 / check50 / check50 / _simple.py View on Github external
_("{} is not a valid command in check {}, use only: {}").format(key, name, COMMANDS))

    for required_command in ["run"]:
        if required_command not in run:
            raise MissingCommand(_("Missing {} in check {}").format(required_name, name))


class CompileError(Exception):
    pass


class UnsupportedCommand(CompileError):
    pass


class MissingCommand(CompileError):
    pass


class InvalidArgument(CompileError):
    pass
github cs50 / check50 / check50 / _simple.py View on Github external
raise MissingCommand(_("Missing {} in check {}").format(required_name, name))


class CompileError(Exception):
    pass


class UnsupportedCommand(CompileError):
    pass


class MissingCommand(CompileError):
    pass


class InvalidArgument(CompileError):
    pass