How to use the check50._api.log 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 / flask.py View on Github external
:param code: ``code`` to assert that application returns
        :type code: int

        Example usage::

            check50.flask.app("application.py").status(200)

            status = check50.flask.app("application.py").get("/").status()
            if status != 200:
                raise check50.Failure(f"expected status code 200, but got {status}")

        """
        if code is None:
            return self.response.status_code

        log(_("checking that status code {} is returned...").format(code))
        if code != self.response.status_code:
            raise Failure(_("expected status code {}, but got {}").format(
                code, self.response.status_code))
        return self
github cs50 / check50 / check50 / flask.py View on Github external
def _search_page(self, output, str_output, content, match_fn, **kwargs):
        if output is None:
            return content

        if str_output is None:
            str_output = output

        log(_("checking that \"{}\" is in page").format(str_output))

        regex = re.compile(output)

        if not match_fn(regex, content):
            raise Failure(
                _("expected to find \"{}\" in page, but it wasn't found").format(str_output))

        return self
github cs50 / check50 / check50 / py.py View on Github external
def compile(file):
    """
    Compile a Python program into byte code

    :param file: file to be compiled
    :raises check50.Failure: if compilation fails e.g. if there is a SyntaxError
    """
    log(_("compiling {} into byte code...").format(file))

    try:
        py_compile.compile(file, doraise=True)
    except py_compile.PyCompileError as e:
        log(_("Exception raised: "))
        for line in e.msg.splitlines():
            log(line)

        raise Failure(_("{} raised while compiling {} (rerun with --log for more details)").format(e.exc_type_name, file))
github cs50 / check50 / check50 / flask.py View on Github external
def _send(self, method, route, data, params, **kwargs):
        """Send request of type `method` to `route`."""
        route = self._fmt_route(route, params)
        log(_("sending {} request to {}").format(method.upper(), route))
        try:
            self.response = getattr(self._client, method.lower())(route, data=data, **kwargs)
        except BaseException as e:  # Catch all exceptions thrown by app
            log(_("exception raised in application: {}: {}").format(type(e).__name__, e))
            raise Failure(_("application raised an exception (rerun with --log for more details)"))
        return self
github cs50 / check50 / check50 / py.py View on Github external
def compile(file):
    """
    Compile a Python program into byte code

    :param file: file to be compiled
    :raises check50.Failure: if compilation fails e.g. if there is a SyntaxError
    """
    log(_("compiling {} into byte code...").format(file))

    try:
        py_compile.compile(file, doraise=True)
    except py_compile.PyCompileError as e:
        log(_("Exception raised: "))
        for line in e.msg.splitlines():
            log(line)

        raise Failure(_("{} raised while compiling {} (rerun with --log for more details)").format(e.exc_type_name, file))
github cs50 / check50 / check50 / py.py View on Github external
def compile(file):
    """
    Compile a Python program into byte code

    :param file: file to be compiled
    :raises check50.Failure: if compilation fails e.g. if there is a SyntaxError
    """
    log(_("compiling {} into byte code...").format(file))

    try:
        py_compile.compile(file, doraise=True)
    except py_compile.PyCompileError as e:
        log(_("Exception raised: "))
        for line in e.msg.splitlines():
            log(line)

        raise Failure(_("{} raised while compiling {} (rerun with --log for more details)").format(e.exc_type_name, file))
github cs50 / check50 / check50 / py.py View on Github external
def import_(path):
    """Import a Python program given a raw file path

    :param path: path to python file to be imported
    :type path: str
    :raises check50.Failure: if ``path`` doesn't exist, or if the Python file at ``path`` throws an exception when imported.
    """
    exists(path)
    log(_("importing {}...").format(path))
    name = Path(path).stem
    try:
        return internal.import_file(name, path)
    except Exception as e:
        raise Failure(str(e))