How to use the check50.Failure 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 / c_tests.py View on Github external
def test_leak(self):
        with open("leak.c", "w") as f:
            src =   '#include \n'\
                    'void leak() {malloc(sizeof(int));}\n'\
                    'int main() {\n'\
                    '    leak();\n'\
                    '}'
            f.write(src)

        check50.c.compile("leak.c")
        with self.assertRaises(check50.Failure):
            with check50.internal.register:
                check50.c.valgrind("./leak").exit()
github cs50 / check50 / tests / checks / target / __init__.py View on Github external
def exists4():
    """foo.py exists"""
    raise check50.Failure()
github cs50 / check50 / tests / flask_tests.py View on Github external
def test_content(self):
        src = \
"""from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return 'foobar'"""
        with open("hello.py", "w") as f:
            f.write(src)

        app = check50.flask.app("hello.py")
        app.get("/").content("foo")

        with self.assertRaises(check50.Failure):
            app.get("/").content("foo", name="body")

        app.get("/").content("bar")
github cs50 / check50 / tests / checks / hidden / __init__.py View on Github external
def check():
    check50.log("AHHHHHHHHHHHHHHHHHHH")
    raise check50.Failure("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
github cs50 / check50 / tests / api_tests.py View on Github external
def test_file(self):
        self.write("print('bar')")
        self.runpy()
        with open(self.txt_filename, "r") as f:
            with self.assertRaises(check50.Failure):
                self.process.stdout(f, regex=False)

        self.write("print('foo')")
        self.runpy()
        with open(self.txt_filename, "r") as f:
            self.process.stdout(f, regex=False)