Issue #13849: Add tests for null byte checking in test_genericpath
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 23 Jul 2016 04:31:47 +0000 (07:31 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sat, 23 Jul 2016 04:31:47 +0000 (07:31 +0300)
Lib/test/test_genericpath.py

index 86fc2de75301e14d13cf45824b934eb5d4f5e08d..d7644e8ef4564a5de9b602c7bf0f52f519e93a97 100644 (file)
@@ -274,6 +274,15 @@ class TestGenericTest(GenericTest, unittest.TestCase):
     # and is only meant to be inherited by others.
     pathmodule = genericpath
 
+    def test_null_bytes(self):
+        for attr in GenericTest.common_attributes:
+            # os.path.commonprefix doesn't raise ValueError
+            if attr == 'commonprefix':
+                continue
+            with self.subTest(attr=attr):
+                with self.assertRaises(ValueError) as cm:
+                    getattr(self.pathmodule, attr)('/tmp\x00abcds')
+                self.assertEqual(str(cm.exception), 'embedded null byte')
 
 # Following TestCase is not supposed to be run from test_genericpath.
 # It is inherited by other test modules (macpath, ntpath, posixpath).