88
99import docker
1010import requests
11- from docker . client import DockerClient
11+ import storm . __main__ as storm
1212
13- from lazycluster import Runtime
13+ from lazycluster import Runtime , RuntimeGroup , RuntimeManager , RuntimeTask
1414
1515from .config import RUNTIME_DOCKER_IMAGE , RUNTIME_NAMES , WORKSPACE_PORT
1616
@@ -29,6 +29,13 @@ def setup_module(module: ModuleType) -> None:
2929 _setup_ssh_connection_to_runtime (runtime_name )
3030
3131
32+ def teardown_module (module : ModuleType ) -> None :
33+ """teardown any state that was previously setup with a setup_module
34+ method.
35+ """
36+ _remove_runtimes ()
37+
38+
3239class TestRuntime :
3340 def test_setup (self ) -> None :
3441 for runtime_name in RUNTIME_NAMES :
@@ -47,17 +54,40 @@ def test_setup(self) -> None:
4754
4855 Runtime (RUNTIME_NAMES [0 ])
4956
50- # def test_echo(self):
51- # rt = Runtime(RUNTIME_NAMES[len(RUNTIME_NAMES - 1)])
52- # msg = "Hello Runtime"
53- # assert rt.echo(msg) == msg
57+ def test_echo (self ) -> None :
58+ runtime_name = RUNTIME_NAMES [len (RUNTIME_NAMES ) - 1 ]
59+ rt = Runtime (runtime_name )
60+ msg = f"Hello Runtime { runtime_name } "
61+ assert rt .echo (msg ).rstrip ("\n " ) == msg
62+
63+ def test_working (self ) -> None :
64+ runtime_name = RUNTIME_NAMES [0 ]
65+ exp_working_dir = "/etc"
66+ rt = Runtime (runtime_name , working_dir = exp_working_dir )
67+ act_working_dir = rt .echo ("${PWD}" ).rstrip ("\n " )
68+ assert exp_working_dir == act_working_dir
69+
70+ task = RuntimeTask ("get-working-dir" ).run_command ("echo ${PWD}" )
71+ rt .execute_task (task , execute_async = False )
72+ assert exp_working_dir == rt .execution_log (task .name )[0 ].rstrip ("\n " ).rstrip (
73+ "\r "
74+ )
5475
5576
56- def teardown_module (module : ModuleType ) -> None :
57- """teardown any state that was previously setup with a setup_module
58- method.
59- """
60- _remove_runtimes ()
77+ class TestRuntimeGroup :
78+ def test_creation (self ) -> None :
79+ runtime_group = RuntimeGroup (hosts = RUNTIME_NAMES )
80+ for runtime_name in RUNTIME_NAMES :
81+ assert runtime_name in runtime_group ._runtimes
82+ assert isinstance (runtime_group ._runtimes [runtime_name ], Runtime )
83+
84+
85+ class TestRuntimeManager :
86+ def test_create_group (self ) -> None :
87+ runtime_group = RuntimeManager ().create_group ()
88+ for runtime_name in RUNTIME_NAMES :
89+ assert runtime_name in runtime_group ._runtimes
90+ assert isinstance (runtime_group ._runtimes [runtime_name ], Runtime )
6191
6292
6393# -------------------------------------------------------------------------
@@ -72,6 +102,9 @@ def _remove_runtimes() -> None:
72102 except docker .errors .NotFound :
73103 # TODO: handle create a docker container if not running as containerized test
74104 print (f"Conatiner { runtime_name } not found" )
105+ # Delete ssh config as well, because the ssh setup fails
106+ # when testing against multiple python versions
107+ storm .delete (runtime_name )
75108
76109
77110def _get_current_container_id () -> str :
@@ -84,7 +117,7 @@ def _get_current_container_id() -> str:
84117 ).stdout .rstrip ("\n " )
85118
86119
87- def _start_runtime_container (name : str , client : DockerClient ) -> None :
120+ def _start_runtime_container (name : str , client : docker . DockerClient ) -> None :
88121 try :
89122 container = client .containers .run (
90123 RUNTIME_DOCKER_IMAGE ,
0 commit comments