3
3
from light_the_torch .computation_backend import CPUBackend
4
4
5
5
6
- @pytest .mark .slow
7
- def test_help_ini (cmd ):
8
- result = cmd ("--help-ini" )
9
- result .assert_success (is_run_test_env = False )
10
- assert "disable_light_the_torch" in result .out
11
- assert "force_cpu" in result .out
6
+ @pytest .fixture
7
+ def patch_extract_dists (mocker ):
8
+ def patch_extract_dists_ (return_value = None ):
9
+ if return_value is None :
10
+ return_value = []
11
+ return mocker .patch (
12
+ "tox_ltt.plugin.ltt.extract_dists" , return_value = return_value
13
+ )
14
+ return mocker .patch ()
15
+
16
+ return patch_extract_dists_
17
+
18
+
19
+ @pytest .fixture
20
+ def patch_find_links (mocker ):
21
+ def patch_find_links_ (return_value = None ):
22
+ if return_value is None :
23
+ return_value = []
24
+ return mocker .patch (
25
+ "tox_ltt.plugin.ltt.find_links" , return_value = return_value
26
+ )
27
+ return mocker .patch ()
28
+
29
+ return patch_find_links_
30
+
31
+
32
+ @pytest .fixture
33
+ def install_mock (mocker ):
34
+ return mocker .patch ("tox.venv.VirtualEnv.run_install_command" )
12
35
13
36
14
37
def get_pyproject_toml ():
@@ -100,14 +123,16 @@ def tox_ltt_initproj_(
100
123
return tox_ltt_initproj_
101
124
102
125
103
- @pytest .fixture
104
- def install_mock (mocker ):
105
- return mocker .patch ("tox.venv.VirtualEnv.run_install_command" )
126
+ def test_help_ini (cmd ):
127
+ result = cmd ("--help-ini" )
128
+ result .assert_success (is_run_test_env = False )
129
+ assert "disable_light_the_torch" in result .out
130
+ assert "force_cpu" in result .out
106
131
107
132
108
133
@pytest .mark .slow
109
- def test_tox_ltt_disabled (mocker , tox_ltt_initproj , cmd ):
110
- mock = mocker . patch ( "tox_ltt.plugin.ltt.resolve_dists" )
134
+ def test_tox_ltt_disabled (patch_extract_dists , tox_ltt_initproj , cmd ):
135
+ mock = patch_extract_dists ( )
111
136
tox_ltt_initproj (disable_light_the_torch = True )
112
137
113
138
result = cmd ()
@@ -117,9 +142,8 @@ def test_tox_ltt_disabled(mocker, tox_ltt_initproj, cmd):
117
142
118
143
119
144
@pytest .mark .slow
120
- def test_tox_ltt_force_cpu (mocker , tox_ltt_initproj , cmd , install_mock ):
121
- mock = mocker .patch ("tox_ltt.plugin.ltt.find_links" , return_value = [])
122
-
145
+ def test_tox_ltt_force_cpu (patch_find_links , tox_ltt_initproj , cmd , install_mock ):
146
+ mock = patch_find_links ()
123
147
tox_ltt_initproj (deps = ("torch" ,), force_cpu = True )
124
148
125
149
result = cmd ()
@@ -130,9 +154,10 @@ def test_tox_ltt_force_cpu(mocker, tox_ltt_initproj, cmd, install_mock):
130
154
assert kwargs ["computation_backend" ] == CPUBackend ()
131
155
132
156
133
- def test_tox_ltt_no_requirements (mocker , tox_ltt_initproj , cmd , install_mock ):
134
- mock = mocker .patch ("tox_ltt.plugin.ltt.resolve_dists" )
135
-
157
+ def test_tox_ltt_no_requirements (
158
+ patch_extract_dists , tox_ltt_initproj , cmd , install_mock
159
+ ):
160
+ mock = patch_extract_dists ()
136
161
tox_ltt_initproj (skip_install = True )
137
162
138
163
result = cmd ()
@@ -142,8 +167,10 @@ def test_tox_ltt_no_requirements(mocker, tox_ltt_initproj, cmd, install_mock):
142
167
143
168
144
169
@pytest .mark .slow
145
- def test_tox_ltt_no_pytorch_dists (mocker , tox_ltt_initproj , cmd , install_mock ):
146
- mock = mocker .patch ("tox_ltt.plugin.ltt.find_links" )
170
+ def test_tox_ltt_no_pytorch_dists (
171
+ patch_find_links , tox_ltt_initproj , cmd , install_mock
172
+ ):
173
+ mock = patch_find_links ()
147
174
148
175
deps = ("light-the-torch" ,)
149
176
tox_ltt_initproj (deps = deps )
@@ -155,8 +182,10 @@ def test_tox_ltt_no_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_mock):
155
182
156
183
157
184
@pytest .mark .slow
158
- def test_tox_ltt_direct_pytorch_dists (mocker , tox_ltt_initproj , cmd , install_mock ):
159
- mock = mocker .patch ("tox_ltt.plugin.ltt.find_links" , return_value = [])
185
+ def test_tox_ltt_direct_pytorch_dists (
186
+ patch_find_links , tox_ltt_initproj , cmd , install_mock
187
+ ):
188
+ mock = patch_find_links ()
160
189
161
190
deps = ("torch" , "torchaudio" , "torchtext" , "torchvision" )
162
191
dists = set (deps )
@@ -171,8 +200,10 @@ def test_tox_ltt_direct_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_moc
171
200
172
201
173
202
@pytest .mark .slow
174
- def test_tox_ltt_indirect_pytorch_dists (mocker , tox_ltt_initproj , cmd , install_mock ):
175
- mock = mocker .patch ("tox_ltt.plugin.ltt.find_links" , return_value = [])
203
+ def test_tox_ltt_indirect_pytorch_dists (
204
+ patch_find_links , tox_ltt_initproj , cmd , install_mock
205
+ ):
206
+ mock = patch_find_links ()
176
207
177
208
deps = (
"git+https://github.com/pmeier/[email protected] " ,)
178
209
dists = {"torch>=1.5.0" , "torchvision>=0.6.0" }
@@ -187,9 +218,9 @@ def test_tox_ltt_indirect_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_m
187
218
188
219
189
220
def test_tox_ltt_project_pytorch_dists (
190
- subtests , mocker , tox_ltt_initproj , cmd , install_mock
221
+ subtests , patch_find_links , tox_ltt_initproj , cmd , install_mock
191
222
):
192
- mock = mocker . patch ( "tox_ltt.plugin.ltt.find_links" , return_value = [] )
223
+ mock = patch_find_links ( )
193
224
194
225
install_requires = ("torch>=1.5.0" , "torchvision>=0.6.0" )
195
226
dists = set (install_requires )
0 commit comments