def test_unexpected_exception_type(self): def func(): raise IndexError() try: tt.assert_raises(ValueError, func) except AssertionError, e: expected = "func\(\) raised an unexpected exception type: expected=ValueError, actual=.*exceptions.IndexError.*" tt.assert_matches(expected, str(e))
def test_expected_args_failure_error_message(self): def func(): raise RuntimeError(123, 456) try: tt.assert_raises(RuntimeError, func, expected_args=("abc", "def")) except AssertionError, e: expected = "func\(\) raised .*exceptions.RuntimeError.* with unexpected args: expected=\('abc', 'def'\), actual=\(123, 456\)" tt.assert_matches( expected, str(e) )
def test_expected_regex_failure_error_message(self): def func(a, b): raise RuntimeError("%s - %s" %(a, b)) try: tt.assert_raises(RuntimeError, func, 1, b=2, expected_regex="xxx") except AssertionError, e: import re expected = "func\(1, b=2\) raised .*exceptions.RuntimeError.*, but the regular expression 'xxx' doesn't match '1 - 2'" tt.assert_matches(expected, str(e))
def testHTMLReporting(self): htmlcontents = self._get_file_report("html") from testoob.testing import assert_matches assert htmlcontents.find("<title>Testoob report</title>") >= 0 assert htmlcontents.find("def testError(self): raise RuntimeError") >= 0 assert htmlcontents.find("def testFailure(self): self.fail()") >= 0 assert_matches(r"testSuccess.*>Success<", htmlcontents)
def test_expected_args_failure_error_message(self): def func(): raise RuntimeError(123, 456) try: tt.assert_raises(RuntimeError, func, expected_args=("abc", "def")) except AssertionError, e: expected = "func\(\) raised .*exceptions.RuntimeError.* with unexpected args: expected=\('abc', 'def'\), actual=\(123, 456\)" tt.assert_matches(expected, str(e))
def testHTMLReporting(self): htmlcontents = self._get_file_report("html") from testoob.testing import assert_matches assert htmlcontents.find("<title>Testoob report</title>") >= 0 assert htmlcontents.find( "def testError(self): raise RuntimeError") >= 0 assert htmlcontents.find("def testFailure(self): self.fail()") >= 0 assert_matches(r"testSuccess.*>Success<", htmlcontents)
def test_unexpected_exception_type(self): def func(): raise IndexError() try: tt.assert_raises(ValueError, func) except AssertionError, e: expected = ( "func\(\) raised an unexpected exception type: expected=ValueError, actual=.*exceptions.IndexError.*" ) tt.assert_matches(expected, str(e))
def test_expected_regex_failure_error_message(self): def func(a, b): raise RuntimeError("%s - %s" % (a, b)) try: tt.assert_raises(RuntimeError, func, 1, b=2, expected_regex="xxx") except AssertionError, e: import re expected = "func\(1, b=2\) raised .*exceptions.RuntimeError.*, but the regular expression 'xxx' doesn't match '1 - 2'" tt.assert_matches(expected, str(e))