11"""test docker run."""
22
3- import time
43from unittest .mock import Mock , patch
54
65import pytest
76
87from nhp .docker .__main__ import main , parse_args
98
109
11- def test_exit_container (mocker ):
12- m = mocker .patch ("os._exit" )
13- import nhp .docker .__main__ as r
14-
15- r ._exit_container ()
16-
17- m .assert_called_once_with (2 )
18-
19-
2010@pytest .mark .parametrize (
2111 "args, expected_file, expected_local_storage, expected_save_full_model_results" ,
2212 [
@@ -95,7 +85,6 @@ def test_main_azure(mocker):
9585 config = Mock ()
9686 config .APP_VERSION = "dev"
9787 config .DATA_VERSION = "dev"
98- config .CONTAINER_TIMEOUT_SECONDS = 3600
9988 config .STORAGE_ACCOUNT = "sa"
10089
10190 params = {
@@ -127,7 +116,6 @@ def test_main_azure(mocker):
127116def test_init (mocker ):
128117 """It should run the main method if __name__ is __main__."""
129118 config = mocker .patch ("nhp.docker.__main__.Config" )
130- config ().CONTAINER_TIMEOUT_SECONDS = 3600
131119
132120 import nhp .docker .__main__ as r
133121
@@ -141,36 +129,6 @@ def test_init(mocker):
141129 main_mock .assert_called_once_with (config ())
142130
143131
144- def test_init_timeout_call_exit (mocker ):
145- config = mocker .patch ("nhp.docker.__main__.Config" )
146- config ().CONTAINER_TIMEOUT_SECONDS = 0.1
147-
148- import nhp .docker .__main__ as r
149-
150- main_mock = mocker .patch ("nhp.docker.__main__.main" )
151- exit_container_mock = mocker .patch ("nhp.docker.__main__._exit_container" )
152- main_mock .side_effect = lambda * args , ** kwargs : time .sleep (0.2 )
153- with patch .object (r , "__name__" , "__main__" ):
154- r .init ()
155-
156- exit_container_mock .assert_called_once ()
157-
158-
159- def test_init_timeout_dont_call_exit (mocker ):
160- import nhp .docker .__main__ as r
161-
162- config = mocker .patch ("nhp.docker.__main__.Config" )
163- config ().CONTAINER_TIMEOUT_SECONDS = 0.1
164-
165- main_mock = mocker .patch ("nhp.docker.__main__.main" )
166- exit_container_mock = mocker .patch ("nhp.docker.__main__._exit_container" )
167- main_mock .side_effect = lambda * args , ** kwargs : time .sleep (0.02 )
168- with patch .object (r , "__name__" , "__main__" ):
169- r .init ()
170-
171- exit_container_mock .assert_not_called ()
172-
173-
174132def test_init_catches_exception (mocker ):
175133 # arrange
176134 mocker .patch ("nhp.docker.__main__.main" , side_effect = Exception ("Test error" ))
0 commit comments