def test_000_010_single_pass(self):
        """Test a simple function which will pass once"""
        def func(a, b):
            return a + b

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        solver(func)
        self.assertTrue(solver.passed)
    def test_100_000_list_correct(self):
        """Received list is too short - expect a useful error."""
        def func(a):
            return list(range(1, a))

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        passed = solver(func)
        self.assertTrue(passed)
    def test_200_000_dict_correct(self):
        """Returned result is a correct dictionary"""
        def func(a):
            return {x: x for x in range(1, a)}

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        passed = solver(func)
        self.assertTrue(passed)
    def test_000_110_multiple_fail(self):
        """Multiple test failures"""
        def func(a, b):
            return a + b

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        solver(func)
        self.assertFalse(solver.passed)
        self.assertEqual(len(solver.errors), 2)
        self.assertEqual(len(solver.exceptions), 0)
    def test_000_100_single_fail(self):
        """Single test cases with a single test failure"""
        def func(a, b):
            return a + b

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        solver(func)
        self.assertFalse(solver.passed)
        self.assertEqual(len(solver.errors), 1)
        self.assertEqual(len(solver.exceptions), 0)
    def test_000_020_multiple_pass(self):
        """Ensure that the multiple correct passes are recorded"""
        def func(a, b):
            return a + b

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        solver(func)
        self.assertTrue(solver.passed)
        self.assertEqual(len(solver.errors), 0)
        self.assertEqual(len(solver.exceptions), 0)
        self.assertEqual(solver.executed, 2)
    def test_000_200_exceptions(self):
        """Function under tests raises an exception"""
        def func(a, b):
            if a == 1 or b == 1:
                raise AttributeError
            return a + b

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        passed = solver(func)
        self.assertFalse(solver.passed)
        self.assertEqual(len(solver.exceptions), 1)
        self.assertEqual(len(solver.errors), 0)
    def test_000_210_allowed_exceptions(self):
        """Function under tests raises an exception"""
        def func(a):
            if a == 1:
                raise ValueError
            return a * 3

        solver = qc.autotest(challenge_name='challenge1',
                             test_id='0',
                             defer_results=True)

        passed = solver(func)
        self.assertTrue(solver.passed)
        self.assertEqual(len(solver.exceptions), 0)
        self.assertEqual(len(solver.errors), 0)
    def test_100_020_list_too_long(self):
        """Received list is too long - expect a useful error."""
        def func(a):
            return list(range(1, a * 2))

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        passed = solver(func)
        self.assertRegex(
            solver.errors[0],
            r'Test 0 - Incorrect result : return is too long - expecting list of length 3, received list of length 5'
        )
        self.assertRegex(
            solver.errors[1],
            r'Test 1 - Incorrect result : return is too long - expecting list of length 4, received list of length 7'
        )
Exemplo n.º 10
0
    def test_200_020_dict_extra_key(self):
        """Returned result is dictionary with extra keys"""
        def func(a):
            return {x: x for x in range(1, (a * 2) + 1)}

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)
        passed = solver(func)

        self.assertFalse(passed)

        self.assertEqual(len(solver.errors), 2)
        self.assertRegex(
            solver.errors[0],
            r'Test 0 - Incorrect result : return has these extra keys : 2')
        self.assertRegex(
            solver.errors[1],
            r'Test 1 - Incorrect result : return has these extra keys : 3,4')
Exemplo n.º 11
0
    def test_100_030_list_incorrect(self):
        """Returned result is the correct length but is incorrect at a particular position"""
        def func(a):
            return list(range(1, a + 1))

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)

        passed = solver(func)

        self.assertRegex(
            solver.errors[0],
            r'Test 0 - Incorrect result : list index 2 : Expected \(4\) != Returned \(3\)'
        )
        self.assertRegex(
            solver.errors[1],
            r'Test 1 - Incorrect result : list index 0 : Expected \(2\) != Returned \(1\)'
        )
Exemplo n.º 12
0
    def test_200_010_dict_missing_key(self):
        """Returned result is dictionary with missing keys"""
        def func(a):
            return {x: x for x in range(1, int(a / 2) - 1)}

        solver = qc.autotest(challenge_name='challenge1', defer_results=True)
        passed = solver(func)

        self.assertFalse(passed)
        self.assertEqual(len(solver.errors), 2)
        self.assertRegex(
            solver.errors[0],
            r'Test 0 - Incorrect result : return is missing these expected keys : 1,2'
        )
        self.assertRegex(
            solver.errors[1],
            r'Test 1 - Incorrect result : return is missing these expected keys : 1,2,3'
        )
Exemplo n.º 13
0
    def test_000_015_single_pass_str(self):
        """Test a simple function which will pass once - compare strings"""
        def func(a, b):
            return str(a + b)

        with patch('sys.stdout', new=io.StringIO()) as out:
            solver = qc.autotest(challenge_name='challenge1')
            solver(func)
            self.assertTrue(solver.passed)

        s = out.getvalue()
        self.assertEqual(
            """1 test cases executed.
Unexpected exceptions raised:
None

Return value errors:
None
""", s)