10
10
11
11
import unittest
12
12
from datetime import datetime
13
+ from enum import Enum
13
14
from typing import Iterable , List , Mapping , Optional , TypeVar , Union
14
15
from unittest .mock import MagicMock , patch
15
16
36
37
T = TypeVar ("T" )
37
38
38
39
40
+ class EnumConfig (str , Enum ):
41
+ option1 = "option1"
42
+ option2 = "option2"
43
+
44
+
45
+ class IntEnumConfig (int , Enum ):
46
+ option1 = 1
47
+ option2 = 2
48
+
49
+
39
50
class SchedulerTest (unittest .TestCase ):
40
51
class MockScheduler (Scheduler [T ], WorkspaceMixin [None ]):
41
52
def __init__ (self , session_name : str ) -> None :
@@ -78,6 +89,21 @@ def list(self) -> List[ListAppResponse]:
78
89
def _run_opts (self ) -> runopts :
79
90
opts = runopts ()
80
91
opts .add ("foo" , type_ = str , required = True , help = "required option" )
92
+ opts .add (
93
+ "bar" ,
94
+ type_ = EnumConfig ,
95
+ required = True ,
96
+ help = f"Test Enum Config { [m .name for m in EnumConfig ]} " ,
97
+ creator = lambda x : EnumConfig (x ),
98
+ ),
99
+ opts .add (
100
+ "ienum" ,
101
+ type_ = IntEnumConfig ,
102
+ required = False ,
103
+ help = f"Test Enum Config { [m .name for m in IntEnumConfig ]} " ,
104
+ creator = lambda x : IntEnumConfig (x ),
105
+ ),
106
+
81
107
return opts
82
108
83
109
def resolve_resource (self , resource : Union [str , Resource ]) -> Resource :
@@ -92,12 +118,16 @@ def test_invalid_run_cfg(self) -> None:
92
118
scheduler_mock = SchedulerTest .MockScheduler ("test_session" )
93
119
app_mock = MagicMock ()
94
120
121
+ empty_cfg = {}
95
122
with self .assertRaises (InvalidRunConfigException ):
96
- empty_cfg = {}
97
123
scheduler_mock .submit (app_mock , empty_cfg )
98
124
125
+ bad_type_cfg = {"foo" : 100 }
126
+ with self .assertRaises (InvalidRunConfigException ):
127
+ scheduler_mock .submit (app_mock , bad_type_cfg )
128
+
129
+ bad_type_cfg = {"foo" : "here" , "bar" : "temp" }
99
130
with self .assertRaises (InvalidRunConfigException ):
100
- bad_type_cfg = {"foo" : 100 }
101
131
scheduler_mock .submit (app_mock , bad_type_cfg )
102
132
103
133
def test_submit_workspace (self ) -> None :
@@ -110,7 +140,7 @@ def test_submit_workspace(self) -> None:
110
140
111
141
scheduler_mock = SchedulerTest .MockScheduler ("test_session" )
112
142
113
- cfg = {"foo" : "asdf" }
143
+ cfg = {"foo" : "asdf" , "bar" : "option1" , "ienum" : 1 }
114
144
scheduler_mock .submit (app , cfg , workspace = "some_workspace" )
115
145
self .assertEqual (app .roles [0 ].image , "some_workspace" )
116
146
@@ -131,7 +161,7 @@ def test_role_preproc_called(self) -> None:
131
161
app_mock = MagicMock ()
132
162
app_mock .roles = [MagicMock ()]
133
163
134
- cfg = {"foo" : "bar" }
164
+ cfg = {"foo" : "bar" , "bar" : "option2" }
135
165
scheduler_mock .submit_dryrun (app_mock , cfg )
136
166
role_mock = app_mock .roles [0 ]
137
167
role_mock .pre_proc .assert_called_once ()
0 commit comments