|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from usethis._test import CliRunner, change_cwd |
| 4 | +from usethis._ui.app import app |
| 5 | + |
| 6 | + |
| 7 | +class TestArch: |
| 8 | + def test_how_option(self, tmp_path: Path): |
| 9 | + # Act |
| 10 | + runner = CliRunner() |
| 11 | + with change_cwd(tmp_path): |
| 12 | + result = runner.invoke_safe(app, ["arch", "--how"]) |
| 13 | + |
| 14 | + # Assert |
| 15 | + assert result.exit_code == 0, result.output |
| 16 | + assert "lint-imports" in result.output |
| 17 | + |
| 18 | + def test_none_backend_pyproject_toml(self, tmp_path: Path): |
| 19 | + # Arrange |
| 20 | + (tmp_path / "pyproject.toml").write_text( |
| 21 | + '[project]\nname = "myproject"\n\n[tool.usethis]\n' |
| 22 | + ) |
| 23 | + (tmp_path / "src" / "myproject").mkdir(parents=True) |
| 24 | + (tmp_path / "src" / "myproject" / "__init__.py").touch() |
| 25 | + (tmp_path / "src" / "myproject" / "a.py").touch() |
| 26 | + (tmp_path / "src" / "myproject" / "b.py").touch() |
| 27 | + (tmp_path / "src" / "myproject" / "c.py").touch() |
| 28 | + |
| 29 | + # Act |
| 30 | + runner = CliRunner() |
| 31 | + with change_cwd(tmp_path): |
| 32 | + result = runner.invoke_safe(app, ["arch", "--backend", "none"]) |
| 33 | + |
| 34 | + # Assert |
| 35 | + assert result.exit_code == 0, result.output |
| 36 | + assert "☐ Add the dev dependency 'import-linter'." in result.output |
| 37 | + assert "Adding Import Linter config to 'pyproject.toml'." in result.output |
| 38 | + assert "lint-imports" in result.output |
| 39 | + |
| 40 | + def test_add_then_remove(self, tmp_path: Path): |
| 41 | + # Arrange |
| 42 | + (tmp_path / "pyproject.toml").write_text( |
| 43 | + '[project]\nname = "myproject"\n\n[tool.usethis]\n' |
| 44 | + ) |
| 45 | + (tmp_path / "src" / "myproject").mkdir(parents=True) |
| 46 | + (tmp_path / "src" / "myproject" / "__init__.py").touch() |
| 47 | + (tmp_path / "src" / "myproject" / "a.py").touch() |
| 48 | + (tmp_path / "src" / "myproject" / "b.py").touch() |
| 49 | + (tmp_path / "src" / "myproject" / "c.py").touch() |
| 50 | + |
| 51 | + runner = CliRunner() |
| 52 | + |
| 53 | + with change_cwd(tmp_path): |
| 54 | + # Act: Add arch |
| 55 | + result = runner.invoke_safe(app, ["arch", "--backend", "none"]) |
| 56 | + assert result.exit_code == 0, result.output |
| 57 | + |
| 58 | + # Act: Remove arch |
| 59 | + result = runner.invoke_safe(app, ["arch", "--remove", "--backend", "none"]) |
| 60 | + |
| 61 | + # Assert |
| 62 | + assert result.exit_code == 0, result.output |
| 63 | + assert "Removing" in result.output |
0 commit comments