summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2014-04-27 17:00:10 (GMT)
committerTim Golden <mail@timgolden.me.uk>2014-04-27 17:00:10 (GMT)
commit4675d798bfdef3ad916d1eef6d5a4d0529ccfda7 (patch)
tree628685ce1f8db9455bb95819f876faa7c56bf020 /Lib/test/test_os.py
parentdd41f246875494c9acc6ebd4338f8df3ec6c28f0 (diff)
downloadcpython-4675d798bfdef3ad916d1eef6d5a4d0529ccfda7.zip
cpython-4675d798bfdef3ad916d1eef6d5a4d0529ccfda7.tar.gz
cpython-4675d798bfdef3ad916d1eef6d5a4d0529ccfda7.tar.bz2
Issue #18314 os.unlink will now remove junction points on Windows. Patch by Kim Gräsman.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index e129bef..7d5ee69 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -39,6 +39,10 @@ try:
import fcntl
except ImportError:
fcntl = None
+try:
+ import _winapi
+except ImportError:
+ _winapi = None
from test.script_helper import assert_python_ok
@@ -1773,6 +1777,37 @@ class Win32SymlinkTests(unittest.TestCase):
shutil.rmtree(level1)
+@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
+class Win32JunctionTests(unittest.TestCase):
+ junction = 'junctiontest'
+ junction_target = os.path.dirname(os.path.abspath(__file__))
+
+ def setUp(self):
+ assert os.path.exists(self.junction_target)
+ assert not os.path.exists(self.junction)
+
+ def tearDown(self):
+ if os.path.exists(self.junction):
+ # os.rmdir delegates to Windows' RemoveDirectoryW,
+ # which removes junction points safely.
+ os.rmdir(self.junction)
+
+ def test_create_junction(self):
+ _winapi.CreateJunction(self.junction_target, self.junction)
+ self.assertTrue(os.path.exists(self.junction))
+ self.assertTrue(os.path.isdir(self.junction))
+
+ # Junctions are not recognized as links.
+ self.assertFalse(os.path.islink(self.junction))
+
+ def test_unlink_removes_junction(self):
+ _winapi.CreateJunction(self.junction_target, self.junction)
+ self.assertTrue(os.path.exists(self.junction))
+
+ os.unlink(self.junction)
+ self.assertFalse(os.path.exists(self.junction))
+
+
@support.skip_unless_symlink
class NonLocalSymlinkTests(unittest.TestCase):
@@ -2544,6 +2579,7 @@ def test_main():
RemoveDirsTests,
CPUCountTests,
FDInheritanceTests,
+ Win32JunctionTests,
)
if __name__ == "__main__":