|
30 | 30 | import tempfile |
31 | 31 | import unittest |
32 | 32 | import xml |
| 33 | +from pathlib import Path |
33 | 34 | from xml import etree |
34 | 35 | from xml.etree import ElementTree |
35 | 36 |
|
@@ -189,6 +190,30 @@ def test_load_from_module_symlink_on_symlinked_paths_in_syspath(self) -> None: |
189 | 190 | # this should be equivalent to: import secret |
190 | 191 | self.assertEqual(modutils.modpath_from_file(symlink_secret_path), ["secret"]) |
191 | 192 |
|
| 193 | + def test_load_packages_without_init(self) -> None: |
| 194 | + """Test that we correctly find packages with an __init__.py file. |
| 195 | +
|
| 196 | + Regression test for issue reported in: |
| 197 | + https://github.com/PyCQA/astroid/issues/1327 |
| 198 | + """ |
| 199 | + tmp_dir = Path(tempfile.gettempdir()) |
| 200 | + self.addCleanup(os.chdir, os.curdir) |
| 201 | + os.chdir(tmp_dir) |
| 202 | + |
| 203 | + self.addCleanup(shutil.rmtree, tmp_dir / "src") |
| 204 | + os.mkdir(tmp_dir / "src") |
| 205 | + os.mkdir(tmp_dir / "src" / "package") |
| 206 | + with open(tmp_dir / "src" / "__init__.py", "w", encoding="utf-8"): |
| 207 | + pass |
| 208 | + with open(tmp_dir / "src" / "package" / "file.py", "w", encoding="utf-8"): |
| 209 | + pass |
| 210 | + |
| 211 | + # this should be equivalent to: import secret |
| 212 | + self.assertEqual( |
| 213 | + modutils.modpath_from_file(str(Path("src") / "package"), ["."]), |
| 214 | + ["src", "package"], |
| 215 | + ) |
| 216 | + |
192 | 217 |
|
193 | 218 | class LoadModuleFromPathTest(resources.SysPathSetup, unittest.TestCase): |
194 | 219 | def test_do_not_load_twice(self) -> None: |
|
0 commit comments