示例#1
0
    def test_single_skipped_test(self):
        with keep_score() as current_score, skip_if(True):
            @test()
            def _():
                pass

            self.assertEqual(current_score(), Score(0, 1))
示例#2
0
    def test_single_failing_test(self):
        with keep_score() as current_score:
            @test()
            def _():
                fail()

            self.assertEqual(current_score(), Score(0, 1))
示例#3
0
    def test_single_passing_test(self):
        with keep_score() as current_score:
            @test()
            def _():
                pass

            self.assertEqual(current_score(), Score(1, 1))
示例#4
0
    def test_fail_fail(self):
        with keep_score() as current_score:
            @test()
            def _():
                fail()

            @test()
            def _():
                fail()

            self.assertEqual(current_score(), Score(0, 2))
示例#5
0
    def test_pass_pass(self):
        with keep_score() as current_score:
            @test()
            def _():
                pass

            @test()
            def _():
                pass

            self.assertEqual(current_score(), Score(2, 2))
示例#6
0
    def test_all_or_nothing_pf(self):
        with keep_score() as current_score:
            with all_or_nothing():
                @test()
                def _():
                    pass

                @test()
                def _():
                    fail()

            self.assertEqual(current_score(), Score(0, 2))
示例#7
0
def _test_command(args):
    '''
    Runs when using test command
    '''

    with keep_score() as current_score, keep_counts() as current_counts:

        def report_fail(e):
            message = "\n".join([
                f'[{current_counts().test_index}] FAIL {str(e)}',
                *[
                    f'{key}: {value}'
                    for key, value in current_context().items()
                ],
                '=' * 50,
            ])
            print(message.strip())

        with reporting(on_fail=report_fail):
            for path_to_tests in find_files_recursively(
                    predicate=has_name(args.tests_file)):
                directory_containing_tests = os.path.dirname(path_to_tests)

                with inside_directory(directory_containing_tests):
                    tested_file_present = os.path.isfile(args.tested_file)
                    filename_of_tests = os.path.basename(path_to_tests)

                    if not tested_file_present:
                        print(
                            f"ERROR: Could not find {args.tested_file} in {os.path.abspath(directory_containing_tests)}"
                        )

                        if args.ignore_missing_tested_file:
                            print(
                                f"WARNING: Continuing with testing --- tests will be fully ignored, not even be counted as skipped"
                            )
                        else:
                            sys.exit(-1)
                    else:
                        with tested_file(args.tested_file), context(
                                'Tests directory', directory_containing_tests):
                            execute_code(os.path.basename(filename_of_tests))

            score = current_score()
            counts = current_counts()

    print(f'PASS {counts.npass}')
    print(f'FAIL {counts.nfail}')
    print(f'SKIP {counts.nskip}')
    print(f'Score: {score}')
    def test_passing(self):
        def refimpl(x):
            return x

        def testimpl(x):
            return x

        with keep_score() as current_score, reference_based_test(
                refimpl, testimpl) as testcase:
            testcase(0)
            testcase(1)
            testcase(2)
            testcase(3)

            self.assertEqual(current_score(), Score(4, 4))
    def test_failing_parameter_modification(self):
        def refimpl(xs):
            return xs.append(1)

        def testimpl(xs):
            return xs.append(2)

        with keep_score() as current_score, reference_based_test(
                refimpl, testimpl) as testcase:
            testcase([])
            testcase([1])
            testcase([2])
            testcase([1, 2, 3])

            self.assertEqual(current_score(), Score(0, 4))
示例#10
0
    def test_all_or_nothing_fpp(self):
        with keep_score(), keep_counts() as current_count, all_or_nothing():

            @test()
            def _():
                fail()

            @test()
            def _():
                pass

            @test()
            def _():
                pass

            self.assertEqual(current_count(), Counts(2, 1, 0))
示例#11
0
    def test_cumulative_in_all_or_nothing(self):
        with keep_score() as current_score:
            with all_or_nothing():
                with cumulative():
                    @test()
                    def _():
                        pass

                    @test()
                    def _():
                        fail()

                with cumulative():
                    @test()
                    def _():
                        pass

                    @test()
                    def _():
                        fail()

            self.assertEqual(current_score(), Score(0, 4))
示例#12
0
    def test_failing(self):
        expected = '''
        def foo(x):
            return x * 2
        '''

        actual = '''
        def foo(x):
            return x
        '''

        expected = load_code_from_string_into_module(dedent(expected),
                                                     'expected')
        actual = load_code_from_string_into_module(dedent(actual), 'actual')

        with reference_module(expected), tested_module(actual), keep_score(
        ) as current_score, reference_based_test('foo') as testcase:
            testcase(0)
            testcase(1)
            testcase(2)
            testcase(3)

            self.assertEqual(current_score(), Score(1, 4))