Skip to content

Commit f152635

Browse files
authored
GH-113528: Split up pathlib tests for invalid basenames. (#113776)
Split test cases for invalid names into dedicated test methods. This will make it easier to refactor tests for invalid name handling in ABCs later. No change of coverage, just a change of test suite organisation.
1 parent d429a5a commit f152635

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ def test_eq_common(self):
215215
self.assertNotEqual(P(), {})
216216
self.assertNotEqual(P(), int)
217217

218-
def test_match_common(self):
218+
def test_match_empty(self):
219219
P = self.cls
220220
self.assertRaises(ValueError, P('a').match, '')
221221
self.assertRaises(ValueError, P('a').match, '.')
222+
223+
def test_match_common(self):
224+
P = self.cls
222225
# Simple relative pattern.
223226
self.assertTrue(P('b.py').match('b.py'))
224227
self.assertTrue(P('a/b.py').match('b.py'))
@@ -398,14 +401,17 @@ def test_anchor_common(self):
398401
self.assertEqual(P('/').anchor, sep)
399402
self.assertEqual(P('/a/b').anchor, sep)
400403

401-
def test_name_common(self):
404+
def test_name_empty(self):
402405
P = self.cls
403406
self.assertEqual(P('').name, '')
404407
self.assertEqual(P('.').name, '')
408+
self.assertEqual(P('/a/b/.').name, 'b')
409+
410+
def test_name_common(self):
411+
P = self.cls
405412
self.assertEqual(P('/').name, '')
406413
self.assertEqual(P('a/b').name, 'b')
407414
self.assertEqual(P('/a/b').name, 'b')
408-
self.assertEqual(P('/a/b/.').name, 'b')
409415
self.assertEqual(P('a/b.py').name, 'b.py')
410416
self.assertEqual(P('/a/b.py').name, 'b.py')
411417

@@ -448,10 +454,13 @@ def test_suffixes_common(self):
448454
self.assertEqual(P('a/Some name. Ending with a dot.').suffixes, [])
449455
self.assertEqual(P('/a/Some name. Ending with a dot.').suffixes, [])
450456

451-
def test_stem_common(self):
457+
def test_stem_empty(self):
452458
P = self.cls
453459
self.assertEqual(P('').stem, '')
454460
self.assertEqual(P('.').stem, '')
461+
462+
def test_stem_common(self):
463+
P = self.cls
455464
self.assertEqual(P('..').stem, '..')
456465
self.assertEqual(P('/').stem, '')
457466
self.assertEqual(P('a/b').stem, 'b')
@@ -470,11 +479,17 @@ def test_with_name_common(self):
470479
self.assertEqual(P('/a/b.py').with_name('d.xml'), P('/a/d.xml'))
471480
self.assertEqual(P('a/Dot ending.').with_name('d.xml'), P('a/d.xml'))
472481
self.assertEqual(P('/a/Dot ending.').with_name('d.xml'), P('/a/d.xml'))
482+
483+
def test_with_name_empty(self):
484+
P = self.cls
473485
self.assertRaises(ValueError, P('').with_name, 'd.xml')
474486
self.assertRaises(ValueError, P('.').with_name, 'd.xml')
475487
self.assertRaises(ValueError, P('/').with_name, 'd.xml')
476488
self.assertRaises(ValueError, P('a/b').with_name, '')
477489
self.assertRaises(ValueError, P('a/b').with_name, '.')
490+
491+
def test_with_name_seps(self):
492+
P = self.cls
478493
self.assertRaises(ValueError, P('a/b').with_name, '/c')
479494
self.assertRaises(ValueError, P('a/b').with_name, 'c/')
480495
self.assertRaises(ValueError, P('a/b').with_name, 'c/d')
@@ -488,11 +503,17 @@ def test_with_stem_common(self):
488503
self.assertEqual(P('/a/b.tar.gz').with_stem('d'), P('/a/d.gz'))
489504
self.assertEqual(P('a/Dot ending.').with_stem('d'), P('a/d'))
490505
self.assertEqual(P('/a/Dot ending.').with_stem('d'), P('/a/d'))
506+
507+
def test_with_stem_empty(self):
508+
P = self.cls
491509
self.assertRaises(ValueError, P('').with_stem, 'd')
492510
self.assertRaises(ValueError, P('.').with_stem, 'd')
493511
self.assertRaises(ValueError, P('/').with_stem, 'd')
494512
self.assertRaises(ValueError, P('a/b').with_stem, '')
495513
self.assertRaises(ValueError, P('a/b').with_stem, '.')
514+
515+
def test_with_stem_seps(self):
516+
P = self.cls
496517
self.assertRaises(ValueError, P('a/b').with_stem, '/c')
497518
self.assertRaises(ValueError, P('a/b').with_stem, 'c/')
498519
self.assertRaises(ValueError, P('a/b').with_stem, 'c/d')
@@ -506,10 +527,16 @@ def test_with_suffix_common(self):
506527
# Stripping suffix.
507528
self.assertEqual(P('a/b.py').with_suffix(''), P('a/b'))
508529
self.assertEqual(P('/a/b').with_suffix(''), P('/a/b'))
530+
531+
def test_with_suffix_empty(self):
532+
P = self.cls
509533
# Path doesn't have a "filename" component.
510534
self.assertRaises(ValueError, P('').with_suffix, '.gz')
511535
self.assertRaises(ValueError, P('.').with_suffix, '.gz')
512536
self.assertRaises(ValueError, P('/').with_suffix, '.gz')
537+
538+
def test_with_suffix_seps(self):
539+
P = self.cls
513540
# Invalid suffix.
514541
self.assertRaises(ValueError, P('a/b').with_suffix, 'gz')
515542
self.assertRaises(ValueError, P('a/b').with_suffix, '/')

0 commit comments

Comments
 (0)