Beispiel #1
0
def test_sicp_examples():
    """
    Test all the files in the SICP code directory
    """
    test_directory = os.path.dirname(os.path.realpath(__file__))
    chapters_dir = "{}/code/sicp/chapters".format(test_directory)

    for lispy_file in os.listdir(chapters_dir):
        abs_script_path = "{}/{}".format(chapters_dir, lispy_file)
        output = lispy("{}".format(abs_script_path))
        comments = re.findall(";;.*", open(abs_script_path).read())
        expected = list(map(lambda line: line.replace(";;", ""), comments))

        for output_line, expected in zip(output.split('\n'), expected):
            yield check_expected, lispy_file, expected.strip(), output_line
Beispiel #2
0
 def test_passed_as_string(self):
     """
     Tests that code passed in as a string with the -c flag is
     being evaluated properly
     """
     self.assertEquals(lispy("-c (+ 2 2)"), "4\n")