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 _verify_command_line_failure(output="", error="", rc=0, **kwargs): args = _generate_command(output=output, error=error, rc=rc) tt.assert_raises( AssertionError, tt.command_line, args, **kwargs )
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_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))
def test_expected_regex_success(self): def func(): raise RuntimeError("shoo-bee-doo-bah") tt.assert_raises( RuntimeError, func, expected_regex="sh.*-.ee-[do]+-.*h$")
def test_expected_exception(self): def func(): raise ValueError() tt.assert_raises(ValueError, func)
def test_expected_args_success(self): def func(): raise RuntimeError(123, 456) tt.assert_raises(RuntimeError, func, expected_args=(123,456))
def test_kwargs_expected_exception(self): def func(**kwargs): if kwargs["x"] < 10: raise EnvironmentError() tt.assert_raises(EnvironmentError, func, x=5)
def test_args_expected_exception(self): def func(x): if x < 10: raise TypeError() tt.assert_raises(TypeError, func, 5)
def test_start_raises(self): tt.assert_raises(threadpool.Error, self.pool.start)
def test_dispatch_raises(self): tt.assert_raises(threadpool.Error, self.pool.dispatch, lambda: "foo")
def test_expected_regex_success(self): def func(): raise RuntimeError("shoo-bee-doo-bah") tt.assert_raises(RuntimeError, func, expected_regex="sh.*-.ee-[do]+-.*h$")
def test_expected_args_success(self): def func(): raise RuntimeError(123, 456) tt.assert_raises(RuntimeError, func, expected_args=(123, 456))
def _verify_command_line_failure(output="", error="", rc=0, **kwargs): args = _generate_command(output=output, error=error, rc=rc) tt.assert_raises(AssertionError, tt.command_line, args, **kwargs)