Kaydet (Commit) 13a0db5d authored tarafından Brian Curtin's avatar Brian Curtin

Fix some errors that #7566 introduced on non-Windows platforms due to

an ImportError. Rearranged the import, faked out the implementation when
the import fails, and reorganized a test that depends on Win32 behavior.
üst 4bc12ef4
...@@ -10,7 +10,6 @@ import sys ...@@ -10,7 +10,6 @@ import sys
import stat import stat
import genericpath import genericpath
from genericpath import * from genericpath import *
from nt import _getfileinformation
__all__ = ["normcase","isabs","join","splitdrive","split","splitext", __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime", "basename","dirname","commonprefix","getsize","getmtime",
...@@ -656,4 +655,10 @@ def samefile(f1, f2): ...@@ -656,4 +655,10 @@ def samefile(f1, f2):
def sameopenfile(f1, f2): def sameopenfile(f1, f2):
"""Test whether two file objects reference the same file""" """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
import ntpath import ntpath
import os import os
import sys
from test.support import TestFailed from test.support import TestFailed
from test import support, test_genericpath from test import support, test_genericpath
from tempfile import TemporaryFile from tempfile import TemporaryFile
...@@ -244,11 +245,12 @@ class TestNtpath(unittest.TestCase): ...@@ -244,11 +245,12 @@ class TestNtpath(unittest.TestCase):
self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno())) self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno()))
# Make sure different files are really different # Make sure different files are really different
self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno())) self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno()))
# Make sure invalid values don't cause issues # Make sure invalid values don't cause issues on win32
with self.assertRaises(ValueError): if sys.platform == "win32":
# Invalid file descriptors shouldn't display assert with self.assertRaises(ValueError):
# dialogs (#4804) # Invalid file descriptors shouldn't display assert
ntpath.sameopenfile(-1, -1) # dialogs (#4804)
ntpath.sameopenfile(-1, -1)
class NtCommonTest(test_genericpath.CommonTest): class NtCommonTest(test_genericpath.CommonTest):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment