|
1 | 1 | from pathlib import Path |
| 2 | +from typing import cast |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 |
|
@@ -174,6 +175,34 @@ def test_empty_src_directory(self, tmp_path: Path): |
174 | 175 | assert config_spec is not None |
175 | 176 | assert len(config_spec.config_items) > 0 |
176 | 177 |
|
| 178 | + def test_flat_layout_with_setup_py(self, tmp_path: Path): |
| 179 | + # Arrange: flat layout (no src/) with setup.py present |
| 180 | + (tmp_path / "pyproject.toml").write_text('[project]\nname = "myflatpkg"') |
| 181 | + (tmp_path / "setup.py").touch() |
| 182 | + (tmp_path / "myflatpkg").mkdir() |
| 183 | + (tmp_path / "myflatpkg" / "__init__.py").touch() |
| 184 | + (tmp_path / "myflatpkg" / "a.py").touch() |
| 185 | + (tmp_path / "myflatpkg" / "b.py").write_text("import myflatpkg.a\n") |
| 186 | + (tmp_path / "myflatpkg" / "c.py").write_text( |
| 187 | + "import myflatpkg.a\nimport myflatpkg.b\n" |
| 188 | + ) |
| 189 | + |
| 190 | + # Act |
| 191 | + with change_cwd(tmp_path), files_manager(): |
| 192 | + config_spec = ImportLinterTool().config_spec() |
| 193 | + |
| 194 | + # Assert: setup.py should not appear as a contract; myflatpkg should |
| 195 | + contracts_item = next( |
| 196 | + item |
| 197 | + for item in config_spec.config_items |
| 198 | + if item.description == "Listed Contracts" |
| 199 | + ) |
| 200 | + pyproject_entry = contracts_item.root[Path("pyproject.toml")] |
| 201 | + contracts = cast("list[dict[str, object]]", pyproject_entry.get_value()) |
| 202 | + contract_names = [c["name"] for c in contracts] |
| 203 | + assert "setup" not in contract_names |
| 204 | + assert "myflatpkg" in contract_names |
| 205 | + |
177 | 206 |
|
178 | 207 | class TestIsINPRule: |
179 | 208 | def test_inp_rule(self): |
|
0 commit comments