]> granicus.if.org Git - python/commitdiff
Fix some errors that #7566 introduced on non-Windows platforms due to
authorBrian Curtin <brian.curtin@gmail.com>
Mon, 6 Sep 2010 19:46:17 +0000 (19:46 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Mon, 6 Sep 2010 19:46:17 +0000 (19:46 +0000)
an ImportError. Rearranged the import, faked out the implementation when
the import fails, and reorganized a test that depends on Win32 behavior.

Lib/ntpath.py
Lib/test/test_ntpath.py

index eae3cf3098a4eeca01311f6b779bd3c08baf246a..4a121f52223f8c331f00844c311cda36cda1e695 100644 (file)
@@ -10,7 +10,6 @@ import sys
 import stat
 import genericpath
 from genericpath import *
-from nt import _getfileinformation
 
 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
@@ -656,4 +655,10 @@ def samefile(f1, f2):
 
 def sameopenfile(f1, f2):
     """Test whether two file objects reference the same file"""
-    return _getfileinformation(f1) == _getfileinformation(f2)
+    try:
+        from nt import _getfileinformation
+        return _getfileinformation(f1) == _getfileinformation(f2)
+    except ImportError:
+        # On other operating systems, return True if the file descriptors
+        # are the same.
+        return f1 == f2
index 9f39abaec33e698374d61dec66af199d397efad5..5609aee5dbf4b560b745721eb488226aebb0df53 100644 (file)
@@ -1,5 +1,6 @@
 import ntpath
 import os
+import sys
 from test.support import TestFailed
 from test import support, test_genericpath
 from tempfile import TemporaryFile
@@ -244,11 +245,12 @@ class TestNtpath(unittest.TestCase):
             self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno()))
             # Make sure different files are really different
             self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno()))
-            # Make sure invalid values don't cause issues
-            with self.assertRaises(ValueError):
-                # Invalid file descriptors shouldn't display assert
-                # dialogs (#4804)
-                ntpath.sameopenfile(-1, -1)
+            # Make sure invalid values don't cause issues on win32
+            if sys.platform == "win32":
+                with self.assertRaises(ValueError):
+                    # Invalid file descriptors shouldn't display assert
+                    # dialogs (#4804)
+                    ntpath.sameopenfile(-1, -1)
 
 
 class NtCommonTest(test_genericpath.CommonTest):