1
+ import shutil
2
+
1
3
import pytest
2
4
3
5
from light_the_torch .computation_backend import CPUBackend
@@ -8,10 +10,9 @@ def patch_extract_dists(mocker):
8
10
def patch_extract_dists_ (return_value = None ):
9
11
if return_value is None :
10
12
return_value = []
11
- return mocker .patch (
12
- "tox_ltt.plugin.ltt.extract_dists" , return_value = return_value
13
- )
14
- return mocker .patch ()
13
+ return mocker .patch (
14
+ "tox_ltt.plugin.ltt.extract_dists" , return_value = return_value
15
+ )
15
16
16
17
return patch_extract_dists_
17
18
@@ -21,10 +22,7 @@ def patch_find_links(mocker):
21
22
def patch_find_links_ (return_value = None ):
22
23
if return_value is None :
23
24
return_value = []
24
- return mocker .patch (
25
- "tox_ltt.plugin.ltt.find_links" , return_value = return_value
26
- )
27
- return mocker .patch ()
25
+ return mocker .patch ("tox_ltt.plugin.ltt.find_links" , return_value = return_value )
28
26
29
27
return patch_find_links_
30
28
@@ -65,6 +63,7 @@ def get_setup_cfg(name, version, install_requires=None, extra_requires=None):
65
63
66
64
67
65
def get_tox_ini (
66
+ basepython = None ,
68
67
disable_light_the_torch = None ,
69
68
force_cpu = None ,
70
69
deps = None ,
@@ -80,6 +79,8 @@ def get_tox_ini(
80
79
81
80
lines .extend (("[testenv]" , "requires = " , "\t tox-ltt" ,))
82
81
82
+ if basepython is not None :
83
+ lines .append (f"basepython = { basepython } " )
83
84
if skip_install :
84
85
lines .append ("skip_install = True" )
85
86
if extra :
@@ -100,6 +101,7 @@ def tox_ltt_initproj(initproj):
100
101
def tox_ltt_initproj_ (
101
102
name = "foo" ,
102
103
version = "1.2.3" ,
104
+ basepython = None ,
103
105
install_requires = None ,
104
106
extra_requires = None ,
105
107
disable_light_the_torch = None ,
@@ -116,6 +118,7 @@ def tox_ltt_initproj_(
116
118
extra_requires = extra_requires ,
117
119
),
118
120
"tox.ini" : get_tox_ini (
121
+ basepython = basepython ,
119
122
skip_install = skip_install ,
120
123
extra = extra_requires is not None ,
121
124
disable_light_the_torch = disable_light_the_torch ,
@@ -269,3 +272,45 @@ def test_tox_ltt_project_extra_pytorch_dists(
269
272
270
273
args , _ = mock .call_args
271
274
assert set (args [0 ]) == dists
275
+
276
+
277
+ @pytest .fixture
278
+ def other_basepythons (current_tox_py ):
279
+ current_minor = int (current_tox_py [- 1 ])
280
+ basepythons = (f"python3.{ minor } " for minor in {6 , 7 , 8 } - {current_minor })
281
+ return [
282
+ basepython for basepython in basepythons if shutil .which (basepython ) is not None
283
+ ]
284
+
285
+
286
+ @pytest .mark .slow
287
+ def test_tox_ltt_other_basepython (
288
+ subtests ,
289
+ mock_venv ,
290
+ patch_extract_dists ,
291
+ patch_find_links ,
292
+ install_mock ,
293
+ tox_ltt_initproj ,
294
+ cmd ,
295
+ other_basepythons ,
296
+ ):
297
+ def canonical_to_tox (version ):
298
+ major , minor , _ = version .split ("." )
299
+ return f"python{ major } .{ minor } "
300
+
301
+ deps = ["torch" ]
302
+ patch_extract_dists (return_value = deps )
303
+ mock = patch_find_links ()
304
+
305
+ for basepython in other_basepythons :
306
+ mock .reset ()
307
+
308
+ with subtests .test (basepython = basepython ):
309
+ tox_ltt_initproj (basepython = basepython , deps = deps )
310
+
311
+ result = cmd ()
312
+ result .assert_success ()
313
+
314
+ _ , kwargs = mock .call_args
315
+ python_version = kwargs ["python_version" ]
316
+ assert canonical_to_tox (python_version ) == basepython
0 commit comments