diff options
Diffstat (limited to 'Lib/test/test_genericpath.py')
| -rw-r--r-- | Lib/test/test_genericpath.py | 49 | 
1 files changed, 38 insertions, 11 deletions
| diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index 50638a1..3eadd58 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -2,11 +2,12 @@  Tests common to genericpath, macpath, ntpath and posixpath  """ -import unittest -from test import support -import os  import genericpath +import os  import sys +import unittest +import warnings +from test import support  def safe_rmdir(dirname): @@ -145,6 +146,16 @@ class GenericTest(unittest.TestCase):                  f.close()              support.unlink(support.TESTFN) +    @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") +    def test_exists_fd(self): +        r, w = os.pipe() +        try: +            self.assertTrue(self.pathmodule.exists(r)) +        finally: +            os.close(r) +            os.close(w) +        self.assertFalse(self.pathmodule.exists(r)) +      def test_isdir(self):          self.assertIs(self.pathmodule.isdir(support.TESTFN), False)          f = open(support.TESTFN, "wb") @@ -258,15 +269,21 @@ class CommonTest(GenericTest):      def test_abspath(self):          self.assertIn("foo", self.pathmodule.abspath("foo")) -        self.assertIn(b"foo", self.pathmodule.abspath(b"foo")) +        with warnings.catch_warnings(): +            warnings.simplefilter("ignore", DeprecationWarning) +            self.assertIn(b"foo", self.pathmodule.abspath(b"foo"))          # Abspath returns bytes when the arg is bytes -        for path in (b'', b'foo', b'f\xf2\xf2', b'/foo', b'C:\\'): -            self.assertIsInstance(self.pathmodule.abspath(path), bytes) +        with warnings.catch_warnings(): +            warnings.simplefilter("ignore", DeprecationWarning) +            for path in (b'', b'foo', b'f\xf2\xf2', b'/foo', b'C:\\'): +                self.assertIsInstance(self.pathmodule.abspath(path), bytes)      def test_realpath(self):          self.assertIn("foo", self.pathmodule.realpath("foo")) -        self.assertIn(b"foo", self.pathmodule.realpath(b"foo")) +        with warnings.catch_warnings(): +            warnings.simplefilter("ignore", DeprecationWarning) +            self.assertIn(b"foo", self.pathmodule.realpath(b"foo"))      def test_normpath_issue5827(self):          # Make sure normpath preserves unicode @@ -282,8 +299,7 @@ class CommonTest(GenericTest):          unicwd = '\xe7w\xf0'          try: -            fsencoding = support.TESTFN_ENCODING or "ascii" -            unicwd.encode(fsencoding) +            os.fsencode(unicwd)          except (AttributeError, UnicodeEncodeError):              # FS encoding is probably ASCII              pass @@ -295,9 +311,20 @@ class CommonTest(GenericTest):      @unittest.skipIf(sys.platform == 'darwin',          "Mac OS X denies the creation of a directory with an invalid utf8 name")      def test_nonascii_abspath(self): +        name = b'\xe7w\xf0' +        if sys.platform == 'win32': +            try: +                os.fsdecode(name) +            except UnicodeDecodeError: +                self.skipTest("the filename %a is not decodable " +                              "from the ANSI code page %s" +                              % (name, sys.getfilesystemencoding())) +          # Test non-ASCII, non-UTF8 bytes in the path. -        with support.temp_cwd(b'\xe7w\xf0'): -            self.test_abspath() +        with warnings.catch_warnings(): +            warnings.simplefilter("ignore", DeprecationWarning) +            with support.temp_cwd(name): +                self.test_abspath()  def test_main(): | 
