testtools: Import new upstream snapshot.
[nivanova/samba-autobuild/.git] / lib / testtools / testtools / tests / test_testtools.py
index 8e253e63117cb5684b566d02ca71c50a615f113c..2845730f9f7c179016208b95a1d6f455fc4c2fdc 100644 (file)
@@ -20,6 +20,8 @@ from testtools import (
     )
 from testtools.matchers import (
     Equals,
+    MatchesException,
+    Raises,
     )
 from testtools.tests.helpers import (
     an_exc_info,
@@ -246,10 +248,9 @@ class TestAssertions(TestCase):
 
     def test_assertRaises_fails_when_different_error_raised(self):
         # assertRaises re-raises an exception that it didn't expect.
-        self.assertRaises(
-            ZeroDivisionError,
-            self.assertRaises,
-                RuntimeError, self.raiseError, ZeroDivisionError)
+        self.assertThat(lambda: self.assertRaises(RuntimeError,
+            self.raiseError, ZeroDivisionError),
+            Raises(MatchesException(ZeroDivisionError)))
 
     def test_assertRaises_returns_the_raised_exception(self):
         # assertRaises returns the exception object that was raised. This is
@@ -606,8 +607,8 @@ class TestAddCleanup(TestCase):
         def raiseKeyboardInterrupt():
             raise KeyboardInterrupt()
         self.test.addCleanup(raiseKeyboardInterrupt)
-        self.assertRaises(
-            KeyboardInterrupt, self.test.run, self.logging_result)
+        self.assertThat(lambda:self.test.run(self.logging_result),
+            Raises(MatchesException(KeyboardInterrupt)))
 
     def test_all_errors_from_MultipleExceptions_reported(self):
         # When a MultipleExceptions exception is caught, all the errors are
@@ -935,10 +936,12 @@ class TestSkipping(TestCase):
     """Tests for skipping of tests functionality."""
 
     def test_skip_causes_skipException(self):
-        self.assertRaises(self.skipException, self.skip, "Skip this test")
+        self.assertThat(lambda:self.skip("Skip this test"),
+            Raises(MatchesException(self.skipException)))
 
     def test_can_use_skipTest(self):
-        self.assertRaises(self.skipException, self.skipTest, "Skip this test")
+        self.assertThat(lambda:self.skipTest("Skip this test"),
+            Raises(MatchesException(self.skipException)))
 
     def test_skip_without_reason_works(self):
         class Test(TestCase):
@@ -964,8 +967,7 @@ class TestSkipping(TestCase):
         test.run(result)
         case = result._events[0][1]
         self.assertEqual([('startTest', case),
-            ('addSkip', case, "Text attachment: reason\n------------\n"
-             "skipping this test\n------------\n"), ('stopTest', case)],
+            ('addSkip', case, "skipping this test"), ('stopTest', case)],
             calls)
 
     def test_skipException_in_test_method_calls_result_addSkip(self):
@@ -977,8 +979,7 @@ class TestSkipping(TestCase):
         test.run(result)
         case = result._events[0][1]
         self.assertEqual([('startTest', case),
-            ('addSkip', case, "Text attachment: reason\n------------\n"
-             "skipping this test\n------------\n"), ('stopTest', case)],
+            ('addSkip', case, "skipping this test"), ('stopTest', case)],
             result._events)
 
     def test_skip__in_setup_with_old_result_object_calls_addSuccess(self):
@@ -1060,7 +1061,8 @@ class TestOnException(TestCase):
         class Case(TestCase):
             def method(self):
                 self.addOnException(events.index)
-                self.assertRaises(ValueError, self.onException, an_exc_info)
+                self.assertThat(lambda: self.onException(an_exc_info),
+                    Raises(MatchesException(ValueError)))
         case = Case("method")
         case.run()
         self.assertThat(events, Equals([]))