Issue #14637: Fix the UNC import test under Windows to actually use

the UNC path. Also clean up sys.path and invalidate finder caches.

Thanks to Vinay Sajip for spotting the use of the wrong path.
This commit is contained in:
Brett Cannon 2012-04-21 19:11:58 -04:00
parent 2f92389d5c
commit b8c0206bd4
1 changed files with 8 additions and 4 deletions

View File

@ -459,6 +459,7 @@ class PathsTests(unittest.TestCase):
def test_UNC_path(self): def test_UNC_path(self):
with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f: with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
f.write("testdata = 'test_trailing_slash'") f.write("testdata = 'test_trailing_slash'")
importlib.invalidate_caches()
# Create the UNC path, like \\myhost\c$\foo\bar. # Create the UNC path, like \\myhost\c$\foo\bar.
path = os.path.abspath(self.path) path = os.path.abspath(self.path)
import socket import socket
@ -466,10 +467,13 @@ class PathsTests(unittest.TestCase):
drive = path[0] drive = path[0]
unc = "\\\\%s\\%s$"%(hn, drive) unc = "\\\\%s\\%s$"%(hn, drive)
unc += path[2:] unc += path[2:]
sys.path.append(path) sys.path.append(unc)
try:
mod = __import__("test_trailing_slash") mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, 'test_trailing_slash') self.assertEqual(mod.testdata, 'test_trailing_slash')
unload("test_trailing_slash") unload("test_trailing_slash")
finally:
sys.path.remove(unc)
class RelativeImportTests(unittest.TestCase): class RelativeImportTests(unittest.TestCase):