diff options
author | Steve Dower <steve.dower@microsoft.com> | 2018-02-22 18:39:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-22 18:39:10 (GMT) |
commit | 23ad6d0d1a7a6145a01494f4f3913a63d1f0250c (patch) | |
tree | 8519ec43fb83fa69d1bb0df490260835e5eb59c2 /Lib/test | |
parent | 451d1edaf4d27c4e632d81246d308e8dd6ea945f (diff) | |
download | cpython-23ad6d0d1a7a6145a01494f4f3913a63d1f0250c.zip cpython-23ad6d0d1a7a6145a01494f4f3913a63d1f0250c.tar.gz cpython-23ad6d0d1a7a6145a01494f4f3913a63d1f0250c.tar.bz2 |
bpo-32556: nt._getfinalpathname, nt._getvolumepathname and nt._getdiskusage now correctly convert from bytes. (GH-5761)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ntpath.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 15215e4..1eec26b 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -7,6 +7,12 @@ from test.support import TestFailed from test import support, test_genericpath from tempfile import TemporaryFile +try: + import nt +except ImportError: + # Most tests can complete without the nt module, + # but for those that require it we import here. + nt = None def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") @@ -271,17 +277,9 @@ class TestNtpath(unittest.TestCase): tester('ntpath.expanduser("~/foo/bar")', 'C:\\idle\\eric/foo/bar') + @unittest.skipUnless(nt, "abspath requires 'nt' module") def test_abspath(self): - # ntpath.abspath() can only be used on a system with the "nt" module - # (reasonably), so we protect this test with "import nt". This allows - # the rest of the tests for the ntpath module to be run to completion - # on any platform, since most of the module is intended to be usable - # from any platform. - try: - import nt - tester('ntpath.abspath("C:\\")', "C:\\") - except ImportError: - self.skipTest('nt module not available') + tester('ntpath.abspath("C:\\")', "C:\\") def test_relpath(self): tester('ntpath.relpath("a")', 'a') @@ -424,6 +422,34 @@ class TestNtpath(unittest.TestCase): self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$")) self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$\\")) + @unittest.skipUnless(nt, "OS helpers require 'nt' module") + def test_nt_helpers(self): + # Trivial validation that the helpers do not break, and support both + # unicode and bytes (UTF-8) paths + + drive, path = ntpath.splitdrive(sys.executable) + drive = drive.rstrip(ntpath.sep) + ntpath.sep + self.assertEqual(drive, nt._getvolumepathname(sys.executable)) + self.assertEqual(drive.encode(), + nt._getvolumepathname(sys.executable.encode())) + + cap, free = nt._getdiskusage(sys.exec_prefix) + self.assertGreater(cap, 0) + self.assertGreater(free, 0) + b_cap, b_free = nt._getdiskusage(sys.exec_prefix.encode()) + # Free space may change, so only test the capacity is equal + self.assertEqual(b_cap, cap) + self.assertGreater(b_free, 0) + + for path in [sys.prefix, sys.executable]: + final_path = nt._getfinalpathname(path) + self.assertIsInstance(final_path, str) + self.assertGreater(len(final_path), 0) + + b_final_path = nt._getfinalpathname(path.encode()) + self.assertIsInstance(b_final_path, bytes) + self.assertGreater(len(b_final_path), 0) + class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase): pathmodule = ntpath attributes = ['relpath'] |