示例#1
0
文件: test_cases.py 项目: utdb/judged
    def suite():
        expect_file = Path('test/cases') / (path.stem + '.txt')
        kb = logic.Knowledge()
        prover = logic.Prover(kb)

        output_buffer = io.StringIO()

        with path.open() as f:
            for clause, action, location in parser.parse(f):
                try:
                    if action == 'assert':
                        kb.assert_clause(clause)
                    elif action == 'retract':
                        kb.retract_clause(clause)
                    elif action == 'query':
                        for a in prover.ask(clause):
                            print("{}.".format(a), file=output_buffer)
                except datalog.DatalogError as e:
                    raise AssertionError from e

        expected = []
        output = []

        with expect_file.open() as f: expected = sorted(list(f))
        output = sorted(output_buffer.getvalue().splitlines(keepends=True))

        if output != expected:
            d = difflib.Differ()
            result = ['--- output\n','+++ expected\n', '\n']
            result.extend(d.compare(output, expected))
            message = ''.join(result)
            assert output == expected, message
示例#2
0
文件: datalog.py 项目: utdb/judged
def handle_reader(reader, args):
    """
    Processes all statements in a single reader. Errors in the handling of an
    action will be furnished with context information based on the context
    information of the parsed action.
    """
    for clause, action, location in parser.parse(reader):
        try:
            actions[action](clause, args)
        except datalog.DatalogError as e:
            e.context = location
            raise e