summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ntpath.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-09-06 17:07:27 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-09-06 17:07:27 (GMT)
commit6285774f06f44f04353801cc79fd2a5e67f884ec (patch)
treefd38bd421fce735854ca6de4bbe0774ba0769fe8 /Lib/test/test_ntpath.py
parent5c997b8d90e8e531bf844f5618a203f0a12ac9dc (diff)
downloadcpython-6285774f06f44f04353801cc79fd2a5e67f884ec.zip
cpython-6285774f06f44f04353801cc79fd2a5e67f884ec.tar.gz
cpython-6285774f06f44f04353801cc79fd2a5e67f884ec.tar.bz2
Implement #7566 - os.path.sameopenfile for Windows.
This uses the GetFileInformationByHandle function to return a tuple of values to identify a file, then ntpath.sameopenfile compares file tuples, which is exposed as os.path.sameopenfile.
Diffstat (limited to 'Lib/test/test_ntpath.py')
-rw-r--r--Lib/test/test_ntpath.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 86e3eda..9f39aba 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -2,6 +2,7 @@ import ntpath
import os
from test.support import TestFailed
from test import support, test_genericpath
+from tempfile import TemporaryFile
import unittest
@@ -237,6 +238,18 @@ class TestNtpath(unittest.TestCase):
tester('ntpath.relpath("/a", "/a")', '.')
tester('ntpath.relpath("/a/b", "/a/b")', '.')
+ def test_sameopenfile(self):
+ with TemporaryFile() as tf1, TemporaryFile() as tf2:
+ # Make sure the same file is really the same
+ 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)
+
class NtCommonTest(test_genericpath.CommonTest):
pathmodule = ntpath