Skip to content

Commit 4b68fa8

Browse files
Merge branch 'main' into copilot/create-benchmark-mocking-uv
2 parents 8002985 + b868419 commit 4b68fa8

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

tests/usethis/_integrations/project/test_layout.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ def test_src_file_not_dir(self, tmp_path: Path):
3737

3838
# Assert
3939
assert result == "."
40+
41+
def test_setup_py_present(self, tmp_path: Path):
42+
# Arrange
43+
(tmp_path / "setup.py").touch()
44+
45+
# Act
46+
with change_cwd(tmp_path):
47+
result = get_source_dir_str()
48+
49+
# Assert
50+
assert result == "."

tests/usethis/_tool/impl/base/test_import_linter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from typing import cast
23

34
import pytest
45

@@ -174,6 +175,34 @@ def test_empty_src_directory(self, tmp_path: Path):
174175
assert config_spec is not None
175176
assert len(config_spec.config_items) > 0
176177

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+
177206

178207
class TestIsINPRule:
179208
def test_inp_rule(self):

0 commit comments

Comments
 (0)