Skip to content

Commit 9bfbf47

Browse files
committed
pythonGH-113528: Split up pathlib tests for invalid basenames.
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 3375dfe commit 9bfbf47

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
@@ -212,10 +212,13 @@ def test_eq_common(self):
212212
self.assertNotEqual(P(), {})
213213
self.assertNotEqual(P(), int)
214214

215-
def test_match_common(self):
215+
def test_match_empty(self):
216216
P = self.cls
217217
self.assertRaises(ValueError, P('a').match, '')
218218
self.assertRaises(ValueError, P('a').match, '.')
219+
220+
def test_match_common(self):
221+
P = self.cls
219222
# Simple relative pattern.
220223
self.assertTrue(P('b.py').match('b.py'))
221224
self.assertTrue(P('a/b.py').match('b.py'))
@@ -395,14 +398,17 @@ def test_anchor_common(self):
395398
self.assertEqual(P('/').anchor, sep)
396399
self.assertEqual(P('/a/b').anchor, sep)
397400

398-
def test_name_common(self):
401+
def test_name_empty(self):
399402
P = self.cls
400403
self.assertEqual(P('').name, '')
401404
self.assertEqual(P('.').name, '')
405+
self.assertEqual(P('/a/b/.').name, 'b')
406+
407+
def test_name_common(self):
408+
P = self.cls
402409
self.assertEqual(P('/').name, '')
403410
self.assertEqual(P('a/b').name, 'b')
404411
self.assertEqual(P('/a/b').name, 'b')
405-
self.assertEqual(P('/a/b/.').name, 'b')
406412
self.assertEqual(P('a/b.py').name, 'b.py')
407413
self.assertEqual(P('/a/b.py').name, 'b.py')
408414

@@ -445,10 +451,13 @@ def test_suffixes_common(self):
445451
self.assertEqual(P('a/Some name. Ending with a dot.').suffixes, [])
446452
self.assertEqual(P('/a/Some name. Ending with a dot.').suffixes, [])
447453

448-
def test_stem_common(self):
454+
def test_stem_empty(self):
449455
P = self.cls
450456
self.assertEqual(P('').stem, '')
451457
self.assertEqual(P('.').stem, '')
458+
459+
def test_stem_common(self):
460+
P = self.cls
452461
self.assertEqual(P('..').stem, '..')
453462
self.assertEqual(P('/').stem, '')
454463
self.assertEqual(P('a/b').stem, 'b')
@@ -467,11 +476,17 @@ def test_with_name_common(self):
467476
self.assertEqual(P('/a/b.py').with_name('d.xml'), P('/a/d.xml'))
468477
self.assertEqual(P('a/Dot ending.').with_name('d.xml'), P('a/d.xml'))
469478
self.assertEqual(P('/a/Dot ending.').with_name('d.xml'), P('/a/d.xml'))
479+
480+
def test_with_name_empty(self):
481+
P = self.cls
470482
self.assertRaises(ValueError, P('').with_name, 'd.xml')
471483
self.assertRaises(ValueError, P('.').with_name, 'd.xml')
472484
self.assertRaises(ValueError, P('/').with_name, 'd.xml')
473485
self.assertRaises(ValueError, P('a/b').with_name, '')
474486
self.assertRaises(ValueError, P('a/b').with_name, '.')
487+
488+
def test_with_name_seps(self):
489+
P = self.cls
475490
self.assertRaises(ValueError, P('a/b').with_name, '/c')
476491
self.assertRaises(ValueError, P('a/b').with_name, 'c/')
477492
self.assertRaises(ValueError, P('a/b').with_name, 'c/d')
@@ -485,11 +500,17 @@ def test_with_stem_common(self):
485500
self.assertEqual(P('/a/b.tar.gz').with_stem('d'), P('/a/d.gz'))
486501
self.assertEqual(P('a/Dot ending.').with_stem('d'), P('a/d'))
487502
self.assertEqual(P('/a/Dot ending.').with_stem('d'), P('/a/d'))
503+
504+
def test_with_stem_empty(self):
505+
P = self.cls
488506
self.assertRaises(ValueError, P('').with_stem, 'd')
489507
self.assertRaises(ValueError, P('.').with_stem, 'd')
490508
self.assertRaises(ValueError, P('/').with_stem, 'd')
491509
self.assertRaises(ValueError, P('a/b').with_stem, '')
492510
self.assertRaises(ValueError, P('a/b').with_stem, '.')
511+
512+
def test_with_stem_seps(self):
513+
P = self.cls
493514
self.assertRaises(ValueError, P('a/b').with_stem, '/c')
494515
self.assertRaises(ValueError, P('a/b').with_stem, 'c/')
495516
self.assertRaises(ValueError, P('a/b').with_stem, 'c/d')
@@ -503,10 +524,16 @@ def test_with_suffix_common(self):
503524
# Stripping suffix.
504525
self.assertEqual(P('a/b.py').with_suffix(''), P('a/b'))
505526
self.assertEqual(P('/a/b').with_suffix(''), P('/a/b'))
527+
528+
def test_with_suffix_empty(self):
529+
P = self.cls
506530
# Path doesn't have a "filename" component.
507531
self.assertRaises(ValueError, P('').with_suffix, '.gz')
508532
self.assertRaises(ValueError, P('.').with_suffix, '.gz')
509533
self.assertRaises(ValueError, P('/').with_suffix, '.gz')
534+
535+
def test_with_suffix_seps(self):
536+
P = self.cls
510537
# Invalid suffix.
511538
self.assertRaises(ValueError, P('a/b').with_suffix, 'gz')
512539
self.assertRaises(ValueError, P('a/b').with_suffix, '/')

0 commit comments

Comments
 (0)