bpo-33721: Make some os.path functions and pathlib.Path methods be t… · python/cpython@0185f34

GitHub

@@ -138,10 +138,20 @@ def test_exists(self):

138138self.assertIs(self.pathmodule.exists(filename), True)

139139self.assertIs(self.pathmodule.exists(bfilename), True)

140140141+self.assertIs(self.pathmodule.exists(filename+'\udfff'), False)

142+self.assertIs(self.pathmodule.exists(bfilename+b'\xff'), False)

143+self.assertIs(self.pathmodule.exists(filename+'\x00'), False)

144+self.assertIs(self.pathmodule.exists(bfilename+b'\x00'), False)

145+141146ifself.pathmoduleisnotgenericpath:

142147self.assertIs(self.pathmodule.lexists(filename), True)

143148self.assertIs(self.pathmodule.lexists(bfilename), True)

144149150+self.assertIs(self.pathmodule.lexists(filename+'\udfff'), False)

151+self.assertIs(self.pathmodule.lexists(bfilename+b'\xff'), False)

152+self.assertIs(self.pathmodule.lexists(filename+'\x00'), False)

153+self.assertIs(self.pathmodule.lexists(bfilename+b'\x00'), False)

[email protected](hasattr(os, "pipe"), "requires os.pipe()")

146156deftest_exists_fd(self):

147157r, w=os.pipe()

@@ -158,6 +168,11 @@ def test_isdir(self):

158168self.assertIs(self.pathmodule.isdir(filename), False)

159169self.assertIs(self.pathmodule.isdir(bfilename), False)

160170171+self.assertIs(self.pathmodule.isdir(filename+'\udfff'), False)

172+self.assertIs(self.pathmodule.isdir(bfilename+b'\xff'), False)

173+self.assertIs(self.pathmodule.isdir(filename+'\x00'), False)

174+self.assertIs(self.pathmodule.isdir(bfilename+b'\x00'), False)

175+161176try:

162177create_file(filename)

163178self.assertIs(self.pathmodule.isdir(filename), False)

@@ -178,6 +193,11 @@ def test_isfile(self):

178193self.assertIs(self.pathmodule.isfile(filename), False)

179194self.assertIs(self.pathmodule.isfile(bfilename), False)

180195196+self.assertIs(self.pathmodule.isfile(filename+'\udfff'), False)

197+self.assertIs(self.pathmodule.isfile(bfilename+b'\xff'), False)

198+self.assertIs(self.pathmodule.isfile(filename+'\x00'), False)

199+self.assertIs(self.pathmodule.isfile(bfilename+b'\x00'), False)

200+181201try:

182202create_file(filename)

183203self.assertIs(self.pathmodule.isfile(filename), True)

@@ -298,18 +318,20 @@ def test_invalid_paths(self):

298318continue

299319func=getattr(self.pathmodule, attr)

300320withself.subTest(attr=attr):

301-try:

321+ifattrin ('exists', 'isdir', 'isfile'):

302322func('/tmp\udfffabcds')

303-except (OSError, UnicodeEncodeError):

304-pass

305-try:

306323func(b'/tmp\xffabcds')

307-except (OSError, UnicodeDecodeError):

308-pass

309-withself.assertRaisesRegex(ValueError, 'embedded null'):

310324func('/tmp\x00abcds')

311-withself.assertRaisesRegex(ValueError, 'embedded null'):

312325func(b'/tmp\x00abcds')

326+else:

327+withself.assertRaises((OSError, UnicodeEncodeError)):

328+func('/tmp\udfffabcds')

329+withself.assertRaises((OSError, UnicodeDecodeError)):

330+func(b'/tmp\xffabcds')

331+withself.assertRaisesRegex(ValueError, 'embedded null'):

332+func('/tmp\x00abcds')

333+withself.assertRaisesRegex(ValueError, 'embedded null'):

334+func(b'/tmp\x00abcds')

313335314336# Following TestCase is not supposed to be run from test_genericpath.

315337# It is inherited by other test modules (macpath, ntpath, posixpath).