Skip to content

Commit 0bd6708

Browse files
committed
Refactor tests.
1 parent 6e53a47 commit 0bd6708

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

repo_helper/testing/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from repo_helper.files.linting import lint_fix_list, lint_warn_list
4848
from repo_helper.templates import template_dir
4949

50-
__all__ = ["demo_environment", "original_datadir", "temp_repo", "temp_empty_repo"]
50+
__all__ = ["demo_environment", "original_datadir", "temp_repo", "temp_empty_repo", "example_config"]
5151

5252

5353
@pytest.fixture()
@@ -188,8 +188,8 @@ def temp_empty_repo(tmp_pathplus, monkeypatch) -> Repo:
188188
return repo
189189

190190

191-
@pytest.fixture
192-
def temp_repo(temp_empty_repo) -> Repo:
191+
@pytest.fixture()
192+
def temp_repo(temp_empty_repo, example_config) -> Repo:
193193
"""
194194
Pytest fixture to return a git repository in a temporary location.
195195
@@ -199,8 +199,15 @@ def temp_repo(temp_empty_repo) -> Repo:
199199
:data:`repo_helper.utils.today` is monkeypatched to return 25th July 2020.
200200
"""
201201

202-
(temp_empty_repo.path / "repo_helper.yml").write_text(
203-
(pathlib.Path(__file__).parent / "repo_helper_example.yml").read_text()
204-
)
202+
(temp_empty_repo.path / "repo_helper.yml").write_text(example_config)
205203

206204
return temp_empty_repo
205+
206+
207+
@pytest.fixture(scope="session")
208+
def example_config() -> str:
209+
"""
210+
Returns the contents of the example ``repo_helper.yml`` file.
211+
"""
212+
213+
return (pathlib.Path(__file__).parent / "repo_helper_example.yml").read_text()

tests/test_cli/test_conda_recipe.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
from repo_helper.cli.commands.conda_recipe import make_recipe
1414

1515

16-
def test_conda_recipe(tmp_pathplus, file_regression: FileRegressionFixture):
17-
(tmp_pathplus / "repo_helper.yml").write_text(
18-
(pathlib.Path(__file__).parent.parent / "repo_helper.yml_").read_text()
19-
)
16+
def test_conda_recipe(
17+
tmp_pathplus,
18+
file_regression: FileRegressionFixture,
19+
example_config,
20+
):
21+
(tmp_pathplus / "repo_helper.yml").write_text(example_config)
2022
(tmp_pathplus / "requirements.txt").write_lines([
2123
"apeye>=0.3.0",
2224
"attrs>=20.2.0",
@@ -48,10 +50,12 @@ def test_conda_recipe(tmp_pathplus, file_regression: FileRegressionFixture):
4850
check_file_output(tmp_pathplus / "conda/meta.yaml", file_regression)
4951

5052

51-
def test_conda_recipe_specifiers(tmp_pathplus, file_regression: FileRegressionFixture):
52-
(tmp_pathplus / "repo_helper.yml").write_text(
53-
(pathlib.Path(__file__).parent.parent / "repo_helper.yml_").read_text()
54-
)
53+
def test_conda_recipe_specifiers(
54+
tmp_pathplus,
55+
file_regression: FileRegressionFixture,
56+
example_config,
57+
):
58+
(tmp_pathplus / "repo_helper.yml").write_text(example_config)
5559
(tmp_pathplus / "requirements.txt").write_lines([
5660
'apeye>=0.3.0; python_version < "3.10"',
5761
"attrs[extra]>=20.2.0",

tests/test_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ def test_get_gh_actions_python_versions(data_regression: DataRegressionFixture,
6666
)
6767

6868

69-
def test_parse_yaml(tmp_pathplus, data_regression):
70-
(tmp_pathplus / "repo_helper.yml").write_text((pathlib.Path(__file__).parent / "repo_helper.yml_").read_text())
69+
def test_parse_yaml(tmp_pathplus, data_regression, example_config):
70+
(tmp_pathplus / "repo_helper.yml").write_text(example_config)
7171
data_regression.check(parse_yaml(tmp_pathplus))

tests/test_core.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525

2626

2727
@pytest.mark.skipif(condition=os.sep == '\\', reason="Different test for platforms where os.sep == \\")
28-
def test_via_run_repo_helper_forward(temp_empty_repo, capsys, file_regression: FileRegressionFixture, monkeypatch):
28+
def test_via_run_repo_helper_forward(
29+
temp_empty_repo,
30+
capsys,
31+
file_regression: FileRegressionFixture,
32+
monkeypatch,
33+
example_config,
34+
):
2935

30-
(temp_empty_repo.path / "repo_helper.yml").write_text(
31-
(pathlib.Path(__file__).parent / "repo_helper.yml_").read_text()
32-
)
36+
(temp_empty_repo.path / "repo_helper.yml").write_text(example_config)
3337

3438
run_repo_helper(temp_empty_repo.path, force=False, initialise=True, commit=True, message="Testing Testing")
3539

@@ -49,7 +53,11 @@ def test_via_run_repo_helper_forward(temp_empty_repo, capsys, file_regression: F
4953

5054
@pytest.mark.skipif(condition=os.sep == '/', reason="Different test for platforms where os.sep == /")
5155
def test_via_run_repo_helper_backward(
52-
temp_empty_repo, capsys, file_regression: FileRegressionFixture, monkeypatch
56+
temp_empty_repo,
57+
capsys,
58+
file_regression: FileRegressionFixture,
59+
monkeypatch,
60+
example_config,
5361
):
5462

5563
# Monkeypatch dulwich so it doesn't try to use the global config.
@@ -61,9 +69,7 @@ def test_via_run_repo_helper_backward(
6169

6270
monkeypatch.setattr(repo_helper.utils, "today", FAKE_DATE)
6371

64-
(temp_empty_repo.path / "repo_helper.yml").write_text(
65-
(pathlib.Path(__file__).parent / "repo_helper.yml_").read_text()
66-
)
72+
(temp_empty_repo.path / "repo_helper.yml").write_text(example_config)
6773

6874
run_repo_helper(temp_empty_repo.path, force=False, initialise=True, commit=True, message="Testing Testing")
6975

@@ -86,15 +92,14 @@ def test_via_Repo_class(
8692
capsys,
8793
file_regression: FileRegressionFixture,
8894
data_regression: DataRegressionFixture,
89-
monkeypatch
95+
monkeypatch,
96+
example_config,
9097
):
9198

9299
monkeypatch.setattr(repo_helper.utils, "today", FAKE_DATE)
93100

94101
with in_directory(temp_repo.path):
95-
(temp_repo.path / "repo_helper.yml").write_text(
96-
(pathlib.Path(__file__).parent / "repo_helper.yml_").read_text()
97-
)
102+
(temp_repo.path / "repo_helper.yml").write_text(example_config)
98103
(temp_repo.path / "requirements.txt").touch()
99104
(temp_repo.path / "README.rst").touch()
100105
(temp_repo.path / "doc-source").mkdir()

0 commit comments

Comments
 (0)