19
19
import shutil
20
20
from glob import iglob
21
21
from pathlib import Path
22
+ from subprocess import Popen
22
23
from typing import (
23
24
Any ,
24
25
Callable ,
@@ -274,7 +275,8 @@ def test_init_clean__rm_dirs(
274
275
init_clean (id_ , opts = opts )
275
276
mock_clean .assert_called_with (id_ , run_dir , expected_clean )
276
277
mock_remote_clean .assert_called_with (
277
- id_ , platforms , expected_remote_clean , opts .remote_timeout )
278
+ id_ , platforms , opts .remote_timeout , expected_remote_clean
279
+ )
278
280
279
281
280
282
@pytest .mark .parametrize (
@@ -920,7 +922,7 @@ def test_remote_clean(
920
922
# Remove randomness:
921
923
monkeymock ('cylc.flow.clean.shuffle' )
922
924
923
- def mocked_remote_clean_cmd_side_effect (id_ , platform , rm_dirs , timeout ):
925
+ def mocked_remote_clean_cmd_side_effect (id_ , platform , timeout , rm_dirs ):
924
926
proc_ret_code = 0
925
927
if failed_platforms and platform ['name' ] in failed_platforms :
926
928
proc_ret_code = failed_platforms [platform ['name' ]]
@@ -942,11 +944,13 @@ def mocked_remote_clean_cmd_side_effect(id_, platform, rm_dirs, timeout):
942
944
if exc_expected :
943
945
with pytest .raises (CylcError ) as exc :
944
946
cylc_clean .remote_clean (
945
- id_ , platform_names , rm_dirs , timeout = 'irrelevant' )
947
+ id_ , platform_names , timeout = 'irrelevant' , rm_dirs = rm_dirs
948
+ )
946
949
assert "Remote clean failed" in str (exc .value )
947
950
else :
948
951
cylc_clean .remote_clean (
949
- id_ , platform_names , rm_dirs , timeout = 'irrelevant' )
952
+ id_ , platform_names , timeout = 'irrelevant' , rm_dirs = rm_dirs
953
+ )
950
954
for msg in expected_err_msgs :
951
955
assert log_filter (caplog , level = logging .ERROR , contains = msg )
952
956
if expected_platforms :
@@ -960,6 +964,33 @@ def mocked_remote_clean_cmd_side_effect(id_, platform, rm_dirs, timeout):
960
964
assert f"{ p_name } - { PlatformError .MSG_TIDY } " in caplog .text
961
965
962
966
967
+ @pytest .mark .parametrize (
968
+ 'timeout, expected' ,
969
+ [('100' , '100' ),
970
+ ('PT1M2S' , '62.0' )]
971
+ )
972
+ def test_remote_clean__timeout (
973
+ monkeymock : MonkeyMock , monkeypatch : pytest .MonkeyPatch ,
974
+ timeout : str , expected : str ,
975
+ ):
976
+ """Test that remote_clean() accepts a timeout in ISO 8601 format or
977
+ number of seconds."""
978
+ mock_remote_clean_cmd = monkeymock (
979
+ 'cylc.flow.clean._remote_clean_cmd' ,
980
+ spec = _remote_clean_cmd ,
981
+ return_value = mock .Mock (
982
+ spec = Popen , poll = lambda : 0 , communicate = lambda : ('' , '' )
983
+ )
984
+ )
985
+ monkeypatch .setattr (
986
+ 'cylc.flow.clean.get_install_target_to_platforms_map' ,
987
+ lambda * a , ** k : {'picard' : [PLATFORMS ['stargazer' ]]}
988
+ )
989
+
990
+ cylc_clean .remote_clean ('blah' , 'blah' , timeout )
991
+ assert mock_remote_clean_cmd .call_args .kwargs ['timeout' ] == expected
992
+
993
+
963
994
@pytest .mark .parametrize (
964
995
'rm_dirs, expected_args' ,
965
996
[
0 commit comments