From ec37a1e2e8f02e29dfbc4304b3efbc1b9a447c31 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sun, 10 Dec 2017 11:24:17 +0300 Subject: [PATCH] make test pass when working path has junctions --- Lib/test/test_pathlib.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index e56e0d20844ec5..c1adf3d3041fec 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1172,7 +1172,23 @@ def test_different_flavours_unordered(self): # # Make sure any symbolic links in the base test path are resolved -BASE = os.path.realpath(TESTFN) +def _realpath(existing_path, virtual_relpath = None): + """Expand junctions as well in NT which os.path.realpath doesn't do.""" + if os.name == 'nt': + p = os.path._getfinalpathname(existing_path) + assert p.startswith('\\\\?\\') + p = p[4:] + else: + p = os.path.realpath(existing_path) + + if virtual_relpath is not None: + p = os.path.join(p, virtual_relpath) + + return p + +BASE = _realpath('.', TESTFN) + + join = lambda *x: os.path.join(BASE, *x) rel_join = lambda *x: os.path.join(TESTFN, *x) @@ -1494,7 +1510,7 @@ def test_resolve_common(self): os.path.join(BASE, 'foo', 'in', 'spam')) p = P(BASE, '..', 'foo', 'in', 'spam') self.assertEqual(str(p.resolve(strict=False)), - os.path.abspath(os.path.join('foo', 'in', 'spam'))) + _realpath('.',(os.path.join('foo', 'in', 'spam')))) # These are all relative symlinks p = P(BASE, 'dirB', 'fileB') self._check_resolve_relative(p, p) @@ -1519,7 +1535,7 @@ def test_resolve_common(self): # resolves to 'dirB/..' first before resolving to parent of dirB. self._check_resolve_relative(p, P(BASE, 'foo', 'in', 'spam'), False) # Now create absolute symlinks - d = tempfile.mkdtemp(suffix='-dirD') + d = _realpath(tempfile.mkdtemp(suffix='-dirD')) self.addCleanup(support.rmtree, d) os.symlink(os.path.join(d), join('dirA', 'linkX')) os.symlink(join('dirB'), os.path.join(d, 'linkY'))