def test_quiet_expects(self): c = Checker() with c.expect("It isn't even worth mentioning.", quiet=True): pass with c.expect("Let's talk about this."): pass self.assertEqual(c.results, [{"status": "OK", "expect": "Let's talk about this."}])
def test_quiet_expects(self): c = Checker() with c.expect("It isn't even worth mentioning.", quiet=True): pass with c.expect("Let's talk about this."): pass self.assertEqual(c.results, [ { 'status': 'OK', 'expect': "Let's talk about this." }, ])
def test_error(self): class MyException(Exception): pass c = Checker() with self.assertRaises(MyException): with c.expect("Everything will be fine"): raise MyException("It wasn't fine!") self.assertEqual(self.clean_results(c.results), [ { 'status': 'ERROR', 'expect': "Everything will be fine", 'did': "It wasn't fine!", 'exception': { 'type': "MyException", 'message': "It wasn't fine!", 'readable': "MyException: It wasn't fine!", 'traceback': [ { 'file': 'checker/tests/test_run.py', 'line': 0, 'function': 'test_error', 'text': 'raise MyException("It wasn\'t fine!")' }, ] }, }, ])
def test_error(self): class MyException(Exception): pass c = Checker() with self.assertRaises(MyException): with c.expect("Everything will be fine"): raise MyException("It wasn't fine!") self.assertEqual( self.clean_results(c.results), [ { "status": "ERROR", "expect": "Everything will be fine", "did": "It wasn't fine!", "exception": { "type": "MyException", "message": "It wasn't fine!", "readable": "MyException: It wasn't fine!", "traceback": [ { "file": "checker/tests/test_run.py", "line": 0, "function": "test_error", "text": 'raise MyException("It wasn\'t fine!")', } ], }, } ], )
def test_failure_with_continue_on_fail(self): c = Checker() try: with c.expect("This should work", continue_on_fail=True): c.fail("It failed!") self.fail("We shouldn't have run past a c.fail") # pragma: nocover with c.expect("Also this one"): pass except Checker.Done: # pragma: nocover self.fail("Shouldn't have raised Done here.") self.assertEqual( c.results, [ {"status": "FAIL", "expect": "This should work", "did": "It failed!"}, {"status": "OK", "expect": "Also this one"}, ], )
def test_success(self): c = Checker() try: with c.expect("This should work"): pass except Checker.Done: # pragma: nocover self.fail("Shouldn't have raised Done here.") self.assertEqual(c.results, [{"status": "OK", "expect": "This should work"}])
def test_failure(self): c = Checker() try: with c.expect("This should work"): c.fail("It failed!") self.fail("We shouldn't have run past a c.fail") # pragma: nocover self.fail("We shouldn't have continued after a failed c.should") # pragma: nocover except Checker.Done: pass self.assertEqual(c.results, [{"status": "FAIL", "expect": "This should work", "did": "It failed!"}])
def test_test(self): c = Checker() try: with c.expect("This should definitely work"): c.test(True, "This one was ok") c.test(False, "Oops, this was bad") raise Exception("Shouldn't have gotten to here") # pragma: nocover except Checker.Done: pass self.assertEqual( c.results, [{"status": "FAIL", "expect": "This should definitely work", "did": "Oops, this was bad"}] )
def test_failure_with_continue_on_fail(self): c = Checker() try: with c.expect("This should work", continue_on_fail=True): c.fail("It failed!") self.fail( "We shouldn't have run past a c.fail") # pragma: nocover with c.expect("Also this one"): pass except Checker.Done: # pragma: nocover self.fail("Shouldn't have raised Done here.") self.assertEqual(c.results, [ { 'status': 'FAIL', 'expect': "This should work", 'did': "It failed!" }, { 'status': 'OK', 'expect': "Also this one" }, ])
def test_success(self): c = Checker() try: with c.expect("This should work"): pass except Checker.Done: # pragma: nocover self.fail("Shouldn't have raised Done here.") self.assertEqual(c.results, [ { 'status': 'OK', 'expect': "This should work" }, ])
def test_test(self): c = Checker() try: with c.expect("This should definitely work"): c.test(True, "This one was ok") c.test(False, "Oops, this was bad") raise Exception( "Shouldn't have gotten to here") # pragma: nocover except Checker.Done: pass self.assertEqual(c.results, [ { 'status': 'FAIL', 'expect': "This should definitely work", 'did': "Oops, this was bad" }, ])
def test_failure(self): c = Checker() try: with c.expect("This should work"): c.fail("It failed!") self.fail( "We shouldn't have run past a c.fail") # pragma: nocover self.fail("We shouldn't have continued after a failed c.should" ) # pragma: nocover except Checker.Done: pass self.assertEqual(c.results, [ { 'status': 'FAIL', 'expect': "This should work", 'did': "It failed!" }, ])