[Jython-checkins] jython: test_chdir tolerates absent DOS 8.3 filename. Fixes #2709

jeff.allen jython-checkins at python.org
Sat Nov 3 08:48:41 EDT 2018


https://hg.python.org/jython/rev/3dbf6da78abf
changeset:   8193:3dbf6da78abf
user:        Adam Burke <adamburkemail at gmail.com>
date:        Sat Nov 03 11:42:49 2018 +0000
summary:
  test_chdir tolerates absent DOS 8.3 filename. Fixes #2709

Some Windows filesystems may be configured not to provide a DOS
shortname (8dot3name), or it may have been removed from the directory.
This change ensures that test_chdir does not fail for this reason. See
https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#short-vs-long-names

files:
  Lib/test/shortname.bat |   4 +++
  Lib/test/test_chdir.py |  35 +++++++++++++++++++++++++++++-
  NEWS                   |   1 +
  3 files changed, 39 insertions(+), 1 deletions(-)


diff --git a/Lib/test/shortname.bat b/Lib/test/shortname.bat
new file mode 100644
--- /dev/null
+++ b/Lib/test/shortname.bat
@@ -0,0 +1,4 @@
+ at ECHO OFF
+REM Supports windows-specific shortname tests in test_chdir.py
+echo %~s1
+
diff --git a/Lib/test/test_chdir.py b/Lib/test/test_chdir.py
--- a/Lib/test/test_chdir.py
+++ b/Lib/test/test_chdir.py
@@ -185,14 +185,47 @@
 
     def setUp(self):
         super(WindowsChdirTestCase, self).setUp()
-        self.subdir = os.path.join(self.dir1, 'Program Files')
+        self.windowsTestDir = 'Program Files'
+        self.subdir = os.path.join(self.dir1, self.windowsTestDir)
         os.makedirs(self.subdir)
 
+    def shortname(self,path):
+        # From later versions of Windows (post-Vista), not all files and 
+        # directories have short names
+        # This is set at the filesystem level and seems intended to phase
+        # out short (DOS) names
+        # https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
+        # shortname.bat returns the short name if available, else the full name
+        shortnameLoc = test_support.findfile('shortname.bat')
+        output = subprocess.check_output(['cmd','/c',shortnameLoc,path])
+        return output.strip()
+
     def test_windows_chdir_dos_path(self):
+        output = self.shortname(self.subdir)
+        if output.strip().endswith(self.windowsTestDir):
+            self.skipTest('no dos path to test on this filesystem')
         dos_name = os.path.join(self.dir1, 'progra~1')
         os.chdir(dos_name)
         self.assertEqual(os.getcwd(), os.path.realpath(dos_name))
 
+    def test_windows_chdir_dos_path_program_files(self):
+        # Prove that we can navigate to a commonly existing system directory
+        # with a shortname alias. Program Files commonly has 8dot3 (short) alias
+        # for script back-compatibility. Unlike other tests in the class, don't 
+        # create a temp directory
+        pfileName = os.environ['PROGRAMFILES'] 
+        shortPfileName = self.shortname( pfileName )
+        if not os.path.exists(shortPfileName):
+            self.skipTest('Windows PROGRAMFILES short directory not found on this system')
+        if pfileName == shortPfileName:
+            self.skipTest('Windows system with PROGRAMFILES on non 8dot3 filesystem')
+        cwd = os.getcwd()
+        try:
+            os.chdir(pfileName)
+            self.assertEqual(os.getcwd(), os.path.realpath(pfileName))
+        finally:
+            os.chdir(cwd)
+
     def test_windows_getcwd_ensures_drive_letter(self):
         # subdir is in the TEMP directory, usually on C:, while the
         # current working directory could be (for the sake of comments)
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
 
 Development tip
   Bugs fixed
+    - [ 2709 ] test_chdir tolerates absent DOS 8.3 filename
     - [ 2706 ] Use python.path instead of JYTHONPATH
     - [ 2410 ] Regression in PySystemStateTest (leading slash)
     - [ 2639 ] Incorrect result when using != comparison against Java {List, Set, Map}

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list