|
| 1 | +from pathlib import Path |
1 | 2 | from test.support import run_unittest |
2 | 3 | from test.support.import_helper import unload, CleanImport |
3 | 4 | from test.support.warnings_helper import check_warnings |
@@ -92,6 +93,15 @@ def test_getdata_zipfile(self): |
92 | 93 |
|
93 | 94 | del sys.modules[pkg] |
94 | 95 |
|
| 96 | + def test_iter_modules(self): |
| 97 | + #see: issue44061 |
| 98 | + actual = list(pkgutil.iter_modules([Path("/home")], 'somepackage.somesubpackage')) |
| 99 | + self.assertListEqual([], actual) |
| 100 | + |
| 101 | + expected_msg = "path must be None or list of paths to look for modules in" |
| 102 | + with self.assertRaisesRegex(ValueError, expected_msg): |
| 103 | + list(pkgutil.iter_modules("invalid_path")) |
| 104 | + |
95 | 105 | def test_unreadable_dir_on_syspath(self): |
96 | 106 | # issue7367 - walk_packages failed if unreadable dir on sys.path |
97 | 107 | package_name = "unreadable_package" |
@@ -574,6 +584,12 @@ def test_get_importer_avoids_emulation(self): |
574 | 584 | self.assertIsNone(pkgutil.get_importer("*??")) |
575 | 585 | self.assertEqual(len(w.warnings), 0) |
576 | 586 |
|
| 587 | + def test_issue44061(self): |
| 588 | + try: |
| 589 | + pkgutil.get_importer(Path("/home")) |
| 590 | + except AttributeError: |
| 591 | + self.fail("Unexpected AttributeError when calling get_importer") |
| 592 | + |
577 | 593 | def test_iter_importers_avoids_emulation(self): |
578 | 594 | with check_warnings() as w: |
579 | 595 | for importer in pkgutil.iter_importers(): pass |
|
0 commit comments