Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_ntpath.py @ 64495:f6dfd6c563e1
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.
| author | Brian Curtin <brian.curtin@gmail.com> |
|---|---|
| date | Mon, 06 Sep 2010 17:07:27 +0000 |
| parents | 6f5ba71316e7 |
| children | 541338795950 |
line wrap: on
line diff
--- a/Lib/test/test_ntpath.py Mon Sep 06 16:29:29 2010 +0000 +++ b/Lib/test/test_ntpath.py Mon Sep 06 17:07:27 2010 +0000 @@ -2,6 +2,7 @@ import os from test.support import TestFailed from test import support, test_genericpath +from tempfile import TemporaryFile import unittest @@ -237,6 +238,18 @@ 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
