4
4
import pytest
5
5
6
6
from arca import Arca , VenvBackend , DockerBackend , Task , CurrentEnvironmentBackend
7
- from common import BASE_DIR , RETURN_COLORAMA_VERSION_FUNCTION , SECOND_RETURN_STR_FUNCTION , \
8
- TEST_UNICODE , ARG_STR_FUNCTION , KWARG_STR_FUNCTION , WAITING_FUNCTION
9
7
from arca .exceptions import BuildTimeoutError
8
+ from common import BASE_DIR , RETURN_COLORAMA_VERSION_FUNCTION , SECOND_RETURN_STR_FUNCTION , \
9
+ TEST_UNICODE , ARG_STR_FUNCTION , KWARG_STR_FUNCTION , WAITING_FUNCTION , RETURN_STR_FUNCTION
10
10
11
11
12
12
@pytest .mark .parametrize (
17
17
))
18
18
)
19
19
def test_backends (temp_repo_func , backend , requirements_location , file_location ):
20
+ """ Tests the basic stuff around backends, if it can install requirements from more locations,
21
+ launch stuff with correct cwd, works well with multiple branches, etc
22
+ """
20
23
if os .environ .get ("TRAVIS" , False ) and backend == VenvBackend :
21
24
pytest .skip ("Venv Backend doesn't work on Travis" )
22
25
@@ -86,6 +89,41 @@ def test_backends(temp_repo_func, backend, requirements_location, file_location)
86
89
87
90
assert arca .run (temp_repo_func .url , temp_repo_func .branch , task ).output == "0.3.8"
88
91
92
+ # cleanup
93
+
94
+ if isinstance (backend , CurrentEnvironmentBackend ):
95
+ backend ._uninstall ("colorama" )
96
+
97
+ with pytest .raises (ModuleNotFoundError ):
98
+ import colorama # noqa
99
+
100
+
101
+ @pytest .mark .parametrize (
102
+ "backend" ,
103
+ [CurrentEnvironmentBackend , VenvBackend , DockerBackend ]
104
+ )
105
+ def test_advanced_backends (temp_repo_func , backend ):
106
+ """ Tests the more time-intensive stuff, like timeouts or arguments,
107
+ things multiple for runs with different arguments are not neccessary
108
+ """
109
+ if os .environ .get ("TRAVIS" , False ) and backend == VenvBackend :
110
+ pytest .skip ("Venv Backend doesn't work on Travis" )
111
+
112
+ kwargs = {}
113
+
114
+ if backend == DockerBackend :
115
+ kwargs ["disable_pull" ] = True
116
+ if backend == CurrentEnvironmentBackend :
117
+ kwargs ["current_environment_requirements" ] = None
118
+ kwargs ["requirements_strategy" ] = "install_extra"
119
+
120
+ backend = backend (verbosity = 2 , ** kwargs )
121
+
122
+ arca = Arca (backend = backend , base_dir = BASE_DIR )
123
+
124
+ filepath = temp_repo_func .file_path
125
+ requirements_path = temp_repo_func .repo_path / backend .requirements_location
126
+
89
127
filepath .write_text (ARG_STR_FUNCTION )
90
128
temp_repo_func .repo .index .add ([str (filepath )])
91
129
temp_repo_func .repo .index .commit ("Argument function" )
@@ -104,6 +142,7 @@ def test_backends(temp_repo_func, backend, requirements_location, file_location)
104
142
kwargs = {"kwarg" : TEST_UNICODE }
105
143
)).output == TEST_UNICODE [::- 1 ]
106
144
145
+ # test task timeout
107
146
filepath .write_text (WAITING_FUNCTION )
108
147
temp_repo_func .repo .index .add ([str (filepath )])
109
148
temp_repo_func .repo .index .commit ("Waiting function" )
@@ -112,12 +151,19 @@ def test_backends(temp_repo_func, backend, requirements_location, file_location)
112
151
task_3_seconds = Task ("test_file:return_str_function" , timeout = 3 )
113
152
114
153
with pytest .raises (BuildTimeoutError ):
115
- assert arca .run (temp_repo_func .url , temp_repo_func .branch , task_1_second ). output == "Some string"
154
+ arca .run (temp_repo_func .url , temp_repo_func .branch , task_1_second )
116
155
117
156
assert arca .run (temp_repo_func .url , temp_repo_func .branch , task_3_seconds ).output == "Some string"
118
157
119
- if isinstance ( backend , CurrentEnvironmentBackend ):
120
- backend . _uninstall ( "colorama " )
158
+ # test requirements timeout
159
+ requirements_path . write_text ( "scipy " )
121
160
122
- with pytest .raises (ModuleNotFoundError ):
123
- import colorama # noqa
161
+ filepath .write_text (RETURN_STR_FUNCTION )
162
+
163
+ temp_repo_func .repo .index .add ([str (filepath ), str (requirements_path )])
164
+ temp_repo_func .repo .index .commit ("Updated requirements to something that takes > 1 second to install" )
165
+
166
+ arca .backend .requirements_timeout = 1
167
+
168
+ with pytest .raises (BuildTimeoutError ):
169
+ arca .run (temp_repo_func .url , temp_repo_func .branch , Task ("test_file:return_str_function" ))
0 commit comments