def test_flaky_function(self): c = Checker() c.function_returns(self, "flaky", [(2, 2), (3, 3), (4, 4)]) self.assertEqual( self.clean_results(c.results), [ {"status": "OK", "expect": "flaky(2) should return 2."}, { "status": "ERROR", "expect": "flaky(3) should return 3.", "did": "Oops", "exception": { "type": "Flake", "message": "Oops", "readable": "Flake: Oops", "traceback": [ { "file": "checker/exerciser.py", "line": 0, "function": "function_returns", "text": "actual_output = fn(*inputs)", }, { "file": "checker/tests/test_run.py", "line": 0, "function": "flaky", "text": 'raise self.Flake("Oops")', }, ], }, }, {"status": "OK", "expect": "flaky(4) should return 4."}, ], )
def test_no_such_function(self): c = Checker() with self.assertRaises(Checker.Done): c.function_returns(self, 'nothing', [(1, 2), (2, 4)]) self.assertEqual(c.results, [ { 'status': 'FAIL', 'expect': 'You should have a function named nothing.' }, ])
def test_simple(self): c = Checker() c.function_returns(self, "simple", [(1, 2), (2, 4)]) self.assertEqual( c.results, [ {"status": "OK", "expect": "simple(1) should return 2."}, {"status": "OK", "expect": "simple(2) should return 4."}, ], )
def test_not_callable(self): c = Checker() self.mylist = [] with self.assertRaises(Checker.Done): c.function_returns(self, 'mylist', [(1, 2), (2, 4)]) self.assertEqual(c.results, [ { 'status': 'FAIL', 'expect': 'You should have a function named mylist.' }, ])
def test_multiple_arguments(self): c = Checker() c.function_returns(self, "add3", [(1, 2, 3, 6), (1, 1, 1, 3), (10, 11, 12, 33)]) self.assertEqual( c.results, [ {"status": "OK", "expect": "add3(1, 2, 3) should return 6."}, {"status": "OK", "expect": "add3(1, 1, 1) should return 3."}, {"status": "OK", "expect": "add3(10, 11, 12) should return 33."}, ], )
def test_wrong_answers(self): c = Checker() c.function_returns(self, "simple", [(1, 2), (2, 17), (3, 6)]) self.assertEqual( c.results, [ {"status": "OK", "expect": "simple(1) should return 2."}, {"status": "FAIL", "expect": "simple(2) should return 17.", "did": "You returned 4."}, {"status": "OK", "expect": "simple(3) should return 6."}, ], )
def test_simple(self): c = Checker() c.function_returns(self, 'simple', [(1, 2), (2, 4)]) self.assertEqual(c.results, [ { 'status': 'OK', 'expect': 'simple(1) should return 2.' }, { 'status': 'OK', 'expect': 'simple(2) should return 4.' }, ])
def test_multiple_arguments(self): c = Checker() c.function_returns(self, 'add3', [(1, 2, 3, 6), (1, 1, 1, 3), (10, 11, 12, 33)]) self.assertEqual(c.results, [ { 'status': 'OK', 'expect': 'add3(1, 2, 3) should return 6.' }, { 'status': 'OK', 'expect': 'add3(1, 1, 1) should return 3.' }, { 'status': 'OK', 'expect': 'add3(10, 11, 12) should return 33.' }, ])
def test_wrong_answers(self): c = Checker() c.function_returns(self, 'simple', [(1, 2), (2, 17), (3, 6)]) self.assertEqual(c.results, [ { 'status': 'OK', 'expect': 'simple(1) should return 2.' }, { 'status': 'FAIL', 'expect': 'simple(2) should return 17.', 'did': 'You returned 4.' }, { 'status': 'OK', 'expect': 'simple(3) should return 6.' }, ])
def test_flaky_function(self): c = Checker() c.function_returns(self, 'flaky', [(2, 2), (3, 3), (4, 4)]) self.assertEqual(self.clean_results(c.results), [ { 'status': 'OK', 'expect': 'flaky(2) should return 2.' }, { 'status': 'ERROR', 'expect': "flaky(3) should return 3.", 'did': 'Oops', 'exception': { 'type': 'Flake', 'message': 'Oops', 'readable': 'Flake: Oops', 'traceback': [ { 'file': 'checker/exerciser.py', 'line': 0, 'function': 'function_returns', 'text': 'actual_output = fn(*inputs)' }, { 'file': 'checker/tests/test_run.py', 'line': 0, 'function': 'flaky', 'text': 'raise self.Flake("Oops")' }, ] }, }, { 'status': 'OK', 'expect': 'flaky(4) should return 4.' }, ])
def test_not_callable(self): c = Checker() self.mylist = [] with self.assertRaises(Checker.Done): c.function_returns(self, "mylist", [(1, 2), (2, 4)]) self.assertEqual(c.results, [{"status": "FAIL", "expect": "You should have a function named mylist."}])
def test_no_such_function(self): c = Checker() with self.assertRaises(Checker.Done): c.function_returns(self, "nothing", [(1, 2), (2, 4)]) self.assertEqual(c.results, [{"status": "FAIL", "expect": "You should have a function named nothing."}])