示例#1
0
    def test_missing_section(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst, verbosity=TextFormatter.WARNING)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        f.missing_section(Section("NOTEXISTING", []))

        f.end_session()
        exp = "NOTEXISTING: missing section\n"
        self.assertEqual(dst.getvalue(), exp)
示例#2
0
    def test_errors(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst,
                          verbosity=TextFormatter.ERROR)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res, None)
        f.end_test()
        
        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_SEGFAULT, -1, "", "")
        f.execution_result(["prog"], res, None)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_TIMEOUT, 0, "", "")
        f.execution_result(["prog"], res, None)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_ERROR, 42, "", "")
        f.execution_result(["prog"], res, None)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_NOTFILE, 1, "", "")
        f.execution_result(["prog"], res, None)
        f.end_test()
        
        f.end_session()
        exp = """PROCESS ENDED WITH A FAILURE (SEGMENTATION FAULT)
TIMEOUT EXPIRED: PROCESS TERMINATED
PROCESS ENDED WITH A FAILURE (ERROR CODE 42)
FAILED TO RUN THE FILE 'prog' (the file does not exist)
"""
        self.assertEqual(dst.getvalue(), exp)
示例#3
0
    def test_comparison1(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst, verbosity=TextFormatter.WARNING)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        f.comparison_result(Section("EXPECTED", ["1", "2"]),
                            Section("GOT", ["3", "2", "4"]), [1, 0, 1],
                            ["1", "2", None])
        f.end_session()
        exp = """EXPECTED: wrong number of lines (expected 2, got 3)
EXPECTED: line 1 is wrong  (expected '1', got '3')
EXPECTED: unexpected line '4'
"""
        self.assertEqual(dst.getvalue(), exp)
示例#4
0
    def test_comparison4(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst,
                          verbosity=TextFormatter.WARNING,
                          maxerrors=4)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        f.comparison_result(Section("EXPECTED", ["1", "2"]),
                            Section("GOT", ["2", "3"]), [0, 1, 1],
                            ["2", None, "1"])
        f.end_session()
        exp = """EXPECTED: unexpected line '3'
EXPECTED: missing line (expected '1')
"""
        self.assertEqual(dst.getvalue(), exp)
示例#5
0
    def test_comparison2(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst,
                          verbosity=TextFormatter.WARNING,
                          maxerrors=4)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        f.comparison_result(
            Section("EXPECTED", ["1", "2", "3", "4", "5", "6"]),
            Section("GOT", ["6", "1", "2", "3", "4", "5"]), [1] * 6,
            ["1", "2", "3", "4", "5", "6"])
        f.end_session()
        exp = """EXPECTED: line 1 is wrong  (expected '1', got '6')
EXPECTED: line 2 is wrong  (expected '2', got '1')
EXPECTED: line 3 is wrong  (expected '3', got '2')
(... plus other 3 errors ...)
"""
        self.assertEqual(dst.getvalue(), exp)