Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import os
import sys
sys.path.append(os.getcwd())
from check50 import File, Checks, Error, check
class MarioMore(Checks):
@check()
def exists(self):
"""mario.c exists."""
super(MarioMore, self).exists("mario.c")
self.include("0.txt", "1.txt", "2.txt", "23.txt")
@check("exists")
def compiles(self):
"""mario.c compiles."""
self.spawn("clang -o mario mario.c -lcs50").exit(0)
@check("compiles")
def test_reject_negative(self):
"""rejects a height of -1"""
self.spawn("./mario").stdin("-1").reject().kill()
def print_results(results, log=False):
for result in results:
if result["status"] == Checks.PASS:
cprint(":) {}".format(result["description"]), "green")
elif result["status"] == Checks.FAIL:
cprint(":( {}".format(result["description"]), "red")
if result["rationale"] is not None:
cprint(" {}".format(result["rationale"]), "red")
elif result["status"] == Checks.SKIP:
cprint(":| {}".format(result["description"]), "yellow")
cprint(" {}".format(result.get("rationale") or "check skipped"), "yellow")
if log:
for line in result.get("log", []):
print(" {}".format(line))
def __init__(self, method_name):
super(Checks, self).__init__(method_name)
self.result = self.FAIL
self.rationale = None
self.helpers = None
self.log = []
self.children = []
self.data = {}
import os
import re
import sys
sys.path.append(os.getcwd())
from check50 import Checks, Error, check
class Finance(Checks):
@check()
def exists(self):
"""application.c exists."""
super(Finance, self).exists("application.py")
def print_results(results, log=False):
for result in results:
if result["status"] == Checks.PASS:
cprint(":) {}".format(result["description"]), "green")
elif result["status"] == Checks.FAIL:
cprint(":( {}".format(result["description"]), "red")
if result["rationale"] is not None:
cprint(" {}".format(result["rationale"]), "red")
elif result["status"] == Checks.SKIP:
cprint(":| {}".format(result["description"]), "yellow")
cprint(" {}".format(result.get("rationale") or "check skipped"), "yellow")
if log:
for line in result.get("log", []):
print(" {}".format(line))
def print_results(results, log=False):
for result in results:
if result["status"] == Checks.PASS:
cprint(":) {}".format(result["description"]), "green")
elif result["status"] == Checks.FAIL:
cprint(":( {}".format(result["description"]), "red")
if result["rationale"] is not None:
cprint(" {}".format(result["rationale"]), "red")
elif result["status"] == Checks.SKIP:
cprint(":| {}".format(result["description"]), "yellow")
cprint(" {}".format(result.get("rationale") or "check skipped"), "yellow")
if log:
for line in result.get("log", []):
print(" {}".format(line))