from util import log_center # these should be redundant, but they're necessary to refer to the specific log # objects. import ast_extensions import parse_file import check import infer """ This is just the core of the unit testing file. generate_tests.py must be run to fill this file with the several unit tests (each of which tests one source code file in the test_files directory). """ announce_file("unit_tests_core.py") log = check.log = parse_file.log = infer.log = Logger() class PytyTests(unittest.TestCase): def _check_expr(self, s, expr_kind, typ, expected): """Typechecks the string C{s} as an C{expr_type} expression.""" a = ast.parse(s).body[0].value f = expr_template % expr_kind if expected == "pass" or expected == "fail": t = PType.from_str(typ)
""" Uses the specification of the files in C{TEST_SPECS} to generate lots of individual python source code files which are all placed in the directory specified by C{_TEST_FILE_DIR}. Then generates a unit test for every individual python source file created. Note: In test specification documents, files will be specified as: [Name of test] - [Expected typecheck behavior] [Source code] but in the generated python source files (with file name [KindOfTest_NameOfTest]), this will be formatted as: ### [Expected typecheck behavior] [Source code] """ announce_file("generate_tests.py") def _split_last(s, sub): """Splits string `s` at the last occurrence of substring `sub` and returns a tuple of the form (left, right).""" return (sub.join(s.split(sub)[:-1]), s.split(sub)[-1]) def _split_first(s, sub): """Splits string `s` at the first occurrence of substring `sub` and returns a tuple of the form (left, right).""" return (s.split(sub)[0], sub.join(s.split(sub)[1:])) def _expr_test_function_def(test_name, expr_string, expr_kind, type, expected_result):
from logger import Logger, announce_file from util import log_center # these should be redundant, but they're necessary to refer to the specific log # objects. import ast_extensions import parse_file import check import infer """ This is just the core of the unit testing file. generate_tests.py must be run to fill this file with the several unit tests (each of which tests one source code file in the test_files directory). """ announce_file("unit_tests_core.py") log = check.log = parse_file.log = infer.log = Logger() class PytyTests(unittest.TestCase): def _check_expr(self, s, expr_kind, typ, expected): """Typechecks the string C{s} as an C{expr_type} expression.""" a = ast.parse(s).body[0].value f = expr_template % expr_kind if expected == "pass" or expected == "fail": t = PType.from_str(typ)