Skip to content

Commit c5b73d4

Browse files
Migrate tests to use new pre-commit file manager framework
1 parent e378281 commit c5b73d4

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

tests/usethis/_integrations/pre_commit/test_language.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22

3+
from usethis._config_file import files_manager
34
from usethis._integrations.pre_commit.language import get_system_language
45
from usethis._integrations.pre_commit.schema import Language
56
from usethis._test import change_cwd
@@ -18,7 +19,7 @@ def test_returns_unsupported_when_minimum_version_is_4_4_0(self, tmp_path: Path)
1819
""")
1920

2021
# Act
21-
with change_cwd(tmp_path):
22+
with change_cwd(tmp_path), files_manager():
2223
result = get_system_language()
2324

2425
# Assert
@@ -38,7 +39,7 @@ def test_returns_unsupported_when_minimum_version_is_above_4_4_0(
3839
""")
3940

4041
# Act
41-
with change_cwd(tmp_path):
42+
with change_cwd(tmp_path), files_manager():
4243
result = get_system_language()
4344

4445
# Assert
@@ -56,15 +57,15 @@ def test_returns_system_when_minimum_version_is_below_4_4_0(self, tmp_path: Path
5657
""")
5758

5859
# Act
59-
with change_cwd(tmp_path):
60+
with change_cwd(tmp_path), files_manager():
6061
result = get_system_language()
6162

6263
# Assert
6364
assert result == Language("system")
6465

6566
def test_returns_system_when_config_doesnt_exist(self, tmp_path: Path):
6667
# Act
67-
with change_cwd(tmp_path):
68+
with change_cwd(tmp_path), files_manager():
6869
result = get_system_language()
6970

7071
# Assert
@@ -81,7 +82,7 @@ def test_returns_system_when_minimum_version_not_declared(self, tmp_path: Path):
8182
""")
8283

8384
# Act
84-
with change_cwd(tmp_path):
85+
with change_cwd(tmp_path), files_manager():
8586
result = get_system_language()
8687

8788
# Assert
@@ -99,7 +100,7 @@ def test_returns_system_when_minimum_version_is_3_x(self, tmp_path: Path):
99100
""")
100101

101102
# Act
102-
with change_cwd(tmp_path):
103+
with change_cwd(tmp_path), files_manager():
103104
result = get_system_language()
104105

105106
# Assert

tests/usethis/_integrations/pre_commit/test_yaml.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ def test_extra_config(self, tmp_path: Path):
136136

137137

138138
class TestPreCommitFancyDump:
139-
def test_placeholder(self):
140-
_pre_commit_fancy_dump(
141-
config=JsonSchemaForPreCommitConfigYaml(
142-
repos=[
143-
_get_placeholder_repo_config(),
144-
]
145-
),
146-
reference={},
147-
)
139+
def test_placeholder(self, tmp_path: Path):
140+
# Arrange - create a minimal pre-commit config for get_system_language()
141+
(tmp_path / ".pre-commit-config.yaml").write_text("repos: []\n")
142+
143+
# Act
144+
with change_cwd(tmp_path), files_manager():
145+
_pre_commit_fancy_dump(
146+
config=JsonSchemaForPreCommitConfigYaml(
147+
repos=[
148+
_get_placeholder_repo_config(),
149+
]
150+
),
151+
reference={},
152+
)
148153

149154
def test_invalid(self):
150155
with pytest.raises(TypeError):

tests/usethis/_tool/impl/test_deptry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_uses_system_language_when_no_minimum_version(self, tmp_path: Path):
282282
(tmp_path / "src" / "test_project" / "__init__.py").touch()
283283

284284
# Act
285-
with change_cwd(tmp_path), PyprojectTOMLManager():
285+
with change_cwd(tmp_path), files_manager():
286286
result = DeptryTool().get_pre_commit_config()
287287

288288
# Assert
@@ -307,7 +307,7 @@ def test_uses_system_language_when_minimum_version_below_4_4_0(
307307
(tmp_path / "src" / "test_project" / "__init__.py").touch()
308308

309309
# Act
310-
with change_cwd(tmp_path), PyprojectTOMLManager():
310+
with change_cwd(tmp_path), files_manager():
311311
result = DeptryTool().get_pre_commit_config()
312312

313313
# Assert
@@ -332,7 +332,7 @@ def test_uses_unsupported_language_when_minimum_version_is_4_4_0(
332332
(tmp_path / "src" / "test_project" / "__init__.py").touch()
333333

334334
# Act
335-
with change_cwd(tmp_path), PyprojectTOMLManager():
335+
with change_cwd(tmp_path), files_manager():
336336
result = DeptryTool().get_pre_commit_config()
337337

338338
# Assert
@@ -359,7 +359,7 @@ def test_uses_unsupported_language_when_minimum_version_above_4_4_0(
359359
(tmp_path / "src" / "test_project" / "__init__.py").touch()
360360

361361
# Act
362-
with change_cwd(tmp_path), PyprojectTOMLManager():
362+
with change_cwd(tmp_path), files_manager():
363363
result = DeptryTool().get_pre_commit_config()
364364

365365
# Assert

0 commit comments

Comments
 (0)