summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2021-07-28 14:28:14 (GMT)
committerGitHub <noreply@github.com>2021-07-28 14:28:14 (GMT)
commit56c1f6d7edad454f382d3ecb8cdcff24ac898a50 (patch)
tree7ce6f980220018d0519934684487c737efb1306a /Lib/test/test_pathlib.py
parent531e2fbc52ce07a9cf37e0db05a5337e404dfccd (diff)
downloadcpython-56c1f6d7edad454f382d3ecb8cdcff24ac898a50.zip
cpython-56c1f6d7edad454f382d3ecb8cdcff24ac898a50.tar.gz
cpython-56c1f6d7edad454f382d3ecb8cdcff24ac898a50.tar.bz2
bpo-27827: identify a greater range of reserved filename on Windows. (GH-26698)
`pathlib.PureWindowsPath.is_reserved()` now identifies as reserved filenames with trailing spaces or colons. Co-authored-by: Barney Gale <barney.gale@foundry.com> Co-authored-by: Eryk Sun <eryksun@gmail.com>
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 54b7977..e716f4d 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1282,19 +1282,35 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self.assertIs(False, P('').is_reserved())
self.assertIs(False, P('/').is_reserved())
self.assertIs(False, P('/foo/bar').is_reserved())
+ # UNC paths are never reserved.
+ self.assertIs(False, P('//my/share/nul/con/aux').is_reserved())
+ # Case-insenstive DOS-device names are reserved.
+ self.assertIs(True, P('nul').is_reserved())
+ self.assertIs(True, P('aux').is_reserved())
+ self.assertIs(True, P('prn').is_reserved())
self.assertIs(True, P('con').is_reserved())
- self.assertIs(True, P('NUL').is_reserved())
+ self.assertIs(True, P('conin$').is_reserved())
+ self.assertIs(True, P('conout$').is_reserved())
+ # COM/LPT + 1-9 or + superscript 1-3 are reserved.
+ self.assertIs(True, P('COM1').is_reserved())
+ self.assertIs(True, P('LPT9').is_reserved())
+ self.assertIs(True, P('com\xb9').is_reserved())
+ self.assertIs(True, P('com\xb2').is_reserved())
+ self.assertIs(True, P('lpt\xb3').is_reserved())
+ # DOS-device name mataching ignores characters after a dot or
+ # a colon and also ignores trailing spaces.
self.assertIs(True, P('NUL.txt').is_reserved())
- self.assertIs(True, P('com1').is_reserved())
- self.assertIs(True, P('com9.bar').is_reserved())
+ self.assertIs(True, P('PRN ').is_reserved())
+ self.assertIs(True, P('AUX .txt').is_reserved())
+ self.assertIs(True, P('COM1:bar').is_reserved())
+ self.assertIs(True, P('LPT9 :bar').is_reserved())
+ # DOS-device names are only matched at the beginning
+ # of a path component.
self.assertIs(False, P('bar.com9').is_reserved())
- self.assertIs(True, P('lpt1').is_reserved())
- self.assertIs(True, P('lpt9.bar').is_reserved())
self.assertIs(False, P('bar.lpt9').is_reserved())
- # Only the last component matters.
+ # Only the last path component matters.
+ self.assertIs(True, P('c:/baz/con/NUL').is_reserved())
self.assertIs(False, P('c:/NUL/con/baz').is_reserved())
- # UNC paths are never reserved.
- self.assertIs(False, P('//my/share/nul/con/aux').is_reserved())
class PurePathTest(_BasePurePathTest, unittest.TestCase):
cls = pathlib.PurePath