testtools: Import new upstream snapshot.
[nivanova/samba-autobuild/.git] / lib / testtools / testtools / tests / test_compat.py
index 138b286d5db71b014d04a2ed2437badcd5440901..856953896a9d6386f7f82805c45eb4e40a5a5e99 100644 (file)
@@ -17,6 +17,11 @@ from testtools.compat import (
     _u,
     unicode_output_stream,
     )
+from testtools.matchers import (
+    MatchesException,
+    Not,
+    Raises,
+    )
 
 
 class TestDetectEncoding(testtools.TestCase):
@@ -192,34 +197,34 @@ class TestUnicodeOutputStream(testtools.TestCase):
         super(TestUnicodeOutputStream, self).setUp()
         if sys.platform == "cli":
             self.skip("IronPython shouldn't wrap streams to do encoding")
-    
+
     def test_no_encoding_becomes_ascii(self):
         """A stream with no encoding attribute gets ascii/replace strings"""
         sout = _FakeOutputStream()
         unicode_output_stream(sout).write(self.uni)
         self.assertEqual([_b("pa???n")], sout.writelog)
-    
+
     def test_encoding_as_none_becomes_ascii(self):
         """A stream with encoding value of None gets ascii/replace strings"""
         sout = _FakeOutputStream()
         sout.encoding = None
         unicode_output_stream(sout).write(self.uni)
         self.assertEqual([_b("pa???n")], sout.writelog)
-    
+
     def test_bogus_encoding_becomes_ascii(self):
         """A stream with a bogus encoding gets ascii/replace strings"""
         sout = _FakeOutputStream()
         sout.encoding = "bogus"
         unicode_output_stream(sout).write(self.uni)
         self.assertEqual([_b("pa???n")], sout.writelog)
-    
+
     def test_partial_encoding_replace(self):
         """A string which can be partly encoded correctly should be"""
         sout = _FakeOutputStream()
         sout.encoding = "iso-8859-7"
         unicode_output_stream(sout).write(self.uni)
         self.assertEqual([_b("pa?\xe8?n")], sout.writelog)
-    
+
     def test_unicode_encodings_not_wrapped(self):
         """A unicode encoding is left unwrapped as needs no error handler"""
         sout = _FakeOutputStream()
@@ -228,7 +233,7 @@ class TestUnicodeOutputStream(testtools.TestCase):
         sout = _FakeOutputStream()
         sout.encoding = "utf-16-be"
         self.assertIs(unicode_output_stream(sout), sout)
-    
+
     def test_stringio(self):
         """A StringIO object should maybe get an ascii native str type"""
         try:
@@ -241,7 +246,8 @@ class TestUnicodeOutputStream(testtools.TestCase):
         soutwrapper = unicode_output_stream(sout)
         if newio:
             self.expectFailure("Python 3 StringIO expects text not bytes",
-                self.assertRaises, TypeError, soutwrapper.write, self.uni)
+                self.assertThat, lambda: soutwrapper.write(self.uni),
+                Not(Raises(MatchesException(TypeError))))
         soutwrapper.write(self.uni)
         self.assertEqual("pa???n", sout.getvalue())