Skip to content

Commit 61f4c10

Browse files
committed
Make sure that the tests not only bake the plugin but also install it before testing.
1 parent 57774fb commit 61f4c10

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/test_bake_project.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def inside_dir(dirpath):
2626

2727

2828
@contextmanager
29-
def bake_in_temp_dir(cookies, *args, **kwargs):
29+
def bake_in_temp_dir_and_install(cookies, *args, **kwargs):
3030
"""
3131
Delete the temporal directory that is created when executing the tests
3232
:param cookies: pytest_cookies.Cookies,
@@ -35,9 +35,11 @@ def bake_in_temp_dir(cookies, *args, **kwargs):
3535
result = cookies.bake(*args, **kwargs)
3636

3737
try:
38+
run_inside_dir("pip install ./", str(result.project))
3839
yield result
3940
finally:
4041
if result.project is not None and os.path.exists(result.project):
42+
os.system("pip uninstall -y " + result.project.basename)
4143
rmtree(str(result.project))
4244

4345

@@ -58,7 +60,7 @@ def check_output_inside_dir(command, dirpath):
5860

5961

6062
def test_year_compute_in_license_file(cookies):
61-
with bake_in_temp_dir(cookies) as result:
63+
with bake_in_temp_dir_and_install(cookies) as result:
6264
license_file_path = result.project.join("LICENSE")
6365
now = datetime.datetime.now()
6466
assert str(now.year) in license_file_path.read()
@@ -73,7 +75,7 @@ def project_info(result):
7375

7476

7577
def test_bake_with_defaults(cookies):
76-
with bake_in_temp_dir(cookies) as result:
78+
with bake_in_temp_dir_and_install(cookies) as result:
7779
assert result.project.isdir()
7880
assert result.exit_code == 0
7981
assert result.exception is None
@@ -86,14 +88,14 @@ def test_bake_with_defaults(cookies):
8688

8789

8890
def test_bake_and_run_tests(cookies):
89-
with bake_in_temp_dir(cookies) as result:
91+
with bake_in_temp_dir_and_install(cookies) as result:
9092
assert result.project.isdir()
9193
assert run_inside_dir("pytest", str(result.project)) == 0
9294

9395

9496
def test_bake_withspecialchars_and_run_tests(cookies):
9597
"""Ensure that a `full_name` with double quotes does not break setup.py"""
96-
with bake_in_temp_dir(
98+
with bake_in_temp_dir_and_install(
9799
cookies, extra_context={"full_name": 'name "quote" name'}
98100
) as result:
99101
assert result.project.isdir()
@@ -102,7 +104,7 @@ def test_bake_withspecialchars_and_run_tests(cookies):
102104

103105
def test_bake_with_apostrophe_and_run_tests(cookies):
104106
"""Ensure that a `full_name` with apostrophes does not break setup.py"""
105-
with bake_in_temp_dir(cookies, extra_context={"full_name": "O'connor"}) as result:
107+
with bake_in_temp_dir_and_install(cookies, extra_context={"full_name": "O'connor"}) as result:
106108
assert result.project.isdir()
107109
assert run_inside_dir("pytest", str(result.project)) == 0
108110

@@ -117,15 +119,15 @@ def test_bake_selecting_license(cookies):
117119
"GNU General Public License v3": "GNU GENERAL PUBLIC LICENSE",
118120
}
119121
for license, target_string in license_strings.items():
120-
with bake_in_temp_dir(
122+
with bake_in_temp_dir_and_install(
121123
cookies, extra_context={"open_source_license": license}
122124
) as result:
123125
assert target_string in result.project.join("LICENSE").read()
124126
assert license in result.project.join("setup.py").read()
125127

126128

127129
def test_bake_not_open_source(cookies):
128-
with bake_in_temp_dir(
130+
with bake_in_temp_dir_and_install(
129131
cookies, extra_context={"open_source_license": "Not open source"}
130132
) as result:
131133
found_toplevel_files = [f.basename for f in result.project.listdir()]
@@ -135,7 +137,7 @@ def test_bake_not_open_source(cookies):
135137

136138

137139
def test_using_pytest(cookies):
138-
with bake_in_temp_dir(cookies, extra_context={"use_pytest": "y"}) as result:
140+
with bake_in_temp_dir_and_install(cookies, extra_context={"use_pytest": "y"}) as result:
139141
assert result.project.isdir()
140142
test_file_path = result.project.join("tests/test_pysteps_importer_institution_name.py")
141143
lines = test_file_path.readlines()

0 commit comments

Comments
 (0)