]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix context manager use in posixpath.join() tests
authorHynek Schlawack <hs@ox.cx>
Tue, 17 Jul 2012 08:48:19 +0000 (10:48 +0200)
committerHynek Schlawack <hs@ox.cx>
Tue, 17 Jul 2012 08:48:19 +0000 (10:48 +0200)
The asserts were useless (and buggy).

Lib/test/test_posixpath.py

index 54de0cf51635ba0eb0a7323c9ff36f8a8ebce447..1ec4a154d997a4377eab6704588c38ac283ec731 100644 (file)
@@ -56,15 +56,18 @@ class PosixPathTest(unittest.TestCase):
         self.assertEqual(posixpath.join(b"/foo/", b"bar/", b"baz/"),
                          b"/foo/bar/baz/")
 
-        with self.assertRaises(TypeError) as e:
-            posixpath.join(b'bytes', 'str')
-            self.assertIn("Can't mix strings and bytes", e.args[0])
-        with self.assertRaises(TypeError) as e:
-            posixpath.join('str', b'bytes')
-            self.assertIn("Can't mix strings and bytes", e.args[0])
-        with self.assertRaises(TypeError) as e:
-            posixpath.join('str', bytearray(b'bytes'))
-            self.assertIn("Can't mix strings and bytes", e.args[0])
+        # Check for friendly str/bytes mixing message
+        for args in [[b'bytes', 'str'],
+                     [bytearray(b'bytes'), 'str']]:
+            for _ in range(2):
+                with self.assertRaises(TypeError) as cm:
+                    posixpath.join(*args)
+                self.assertEqual(
+                    "Can't mix strings and bytes in path components.",
+                    cm.exception.args[0]
+                )
+                args.reverse()  # check both orders
+
 
     def test_split(self):
         self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar"))