diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-01-06 17:03:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 17:03:07 (GMT) |
commit | f1526356b1be31071222683c9f09fa271d0203ce (patch) | |
tree | 099d40526e50b7481a230095cd456532b4b88372 | |
parent | d429a5a8e76e3013b35d60c78fcb891556ad9a7c (diff) | |
download | cpython-f1526356b1be31071222683c9f09fa271d0203ce.zip cpython-f1526356b1be31071222683c9f09fa271d0203ce.tar.gz cpython-f1526356b1be31071222683c9f09fa271d0203ce.tar.bz2 |
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.
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib_abc.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index bfde5f3..8dcc67c 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -215,10 +215,13 @@ class DummyPurePathTest(unittest.TestCase): self.assertNotEqual(P(), {}) self.assertNotEqual(P(), int) - def test_match_common(self): + def test_match_empty(self): P = self.cls self.assertRaises(ValueError, P('a').match, '') self.assertRaises(ValueError, P('a').match, '.') + + def test_match_common(self): + P = self.cls # Simple relative pattern. self.assertTrue(P('b.py').match('b.py')) self.assertTrue(P('a/b.py').match('b.py')) @@ -398,14 +401,17 @@ class DummyPurePathTest(unittest.TestCase): self.assertEqual(P('/').anchor, sep) self.assertEqual(P('/a/b').anchor, sep) - def test_name_common(self): + def test_name_empty(self): P = self.cls self.assertEqual(P('').name, '') self.assertEqual(P('.').name, '') + self.assertEqual(P('/a/b/.').name, 'b') + + def test_name_common(self): + P = self.cls self.assertEqual(P('/').name, '') self.assertEqual(P('a/b').name, 'b') self.assertEqual(P('/a/b').name, 'b') - self.assertEqual(P('/a/b/.').name, 'b') self.assertEqual(P('a/b.py').name, 'b.py') self.assertEqual(P('/a/b.py').name, 'b.py') @@ -448,10 +454,13 @@ class DummyPurePathTest(unittest.TestCase): self.assertEqual(P('a/Some name. Ending with a dot.').suffixes, []) self.assertEqual(P('/a/Some name. Ending with a dot.').suffixes, []) - def test_stem_common(self): + def test_stem_empty(self): P = self.cls self.assertEqual(P('').stem, '') self.assertEqual(P('.').stem, '') + + def test_stem_common(self): + P = self.cls self.assertEqual(P('..').stem, '..') self.assertEqual(P('/').stem, '') self.assertEqual(P('a/b').stem, 'b') @@ -470,11 +479,17 @@ class DummyPurePathTest(unittest.TestCase): self.assertEqual(P('/a/b.py').with_name('d.xml'), P('/a/d.xml')) self.assertEqual(P('a/Dot ending.').with_name('d.xml'), P('a/d.xml')) self.assertEqual(P('/a/Dot ending.').with_name('d.xml'), P('/a/d.xml')) + + def test_with_name_empty(self): + P = self.cls self.assertRaises(ValueError, P('').with_name, 'd.xml') self.assertRaises(ValueError, P('.').with_name, 'd.xml') self.assertRaises(ValueError, P('/').with_name, 'd.xml') self.assertRaises(ValueError, P('a/b').with_name, '') self.assertRaises(ValueError, P('a/b').with_name, '.') + + def test_with_name_seps(self): + P = self.cls self.assertRaises(ValueError, P('a/b').with_name, '/c') self.assertRaises(ValueError, P('a/b').with_name, 'c/') self.assertRaises(ValueError, P('a/b').with_name, 'c/d') @@ -488,11 +503,17 @@ class DummyPurePathTest(unittest.TestCase): self.assertEqual(P('/a/b.tar.gz').with_stem('d'), P('/a/d.gz')) self.assertEqual(P('a/Dot ending.').with_stem('d'), P('a/d')) self.assertEqual(P('/a/Dot ending.').with_stem('d'), P('/a/d')) + + def test_with_stem_empty(self): + P = self.cls self.assertRaises(ValueError, P('').with_stem, 'd') self.assertRaises(ValueError, P('.').with_stem, 'd') self.assertRaises(ValueError, P('/').with_stem, 'd') self.assertRaises(ValueError, P('a/b').with_stem, '') self.assertRaises(ValueError, P('a/b').with_stem, '.') + + def test_with_stem_seps(self): + P = self.cls self.assertRaises(ValueError, P('a/b').with_stem, '/c') self.assertRaises(ValueError, P('a/b').with_stem, 'c/') self.assertRaises(ValueError, P('a/b').with_stem, 'c/d') @@ -506,10 +527,16 @@ class DummyPurePathTest(unittest.TestCase): # Stripping suffix. self.assertEqual(P('a/b.py').with_suffix(''), P('a/b')) self.assertEqual(P('/a/b').with_suffix(''), P('/a/b')) + + def test_with_suffix_empty(self): + P = self.cls # Path doesn't have a "filename" component. self.assertRaises(ValueError, P('').with_suffix, '.gz') self.assertRaises(ValueError, P('.').with_suffix, '.gz') self.assertRaises(ValueError, P('/').with_suffix, '.gz') + + def test_with_suffix_seps(self): + P = self.cls # Invalid suffix. self.assertRaises(ValueError, P('a/b').with_suffix, 'gz') self.assertRaises(ValueError, P('a/b').with_suffix, '/') |