10
10
import awscrt .io
11
11
from parameterized import parameterized
12
12
13
+ CONFIG_PATH = Path (
14
+ Path (__file__ ).parents [1 ], "iotdevicesimulator" , "__assets__" , "config.cfg"
15
+ )
16
+ config_exists = pytest .mark .skipif (
17
+ not CONFIG_PATH .exists (),
18
+ reason = "Config file `config.cfg` not found in root directory." ,
19
+ )
20
+
13
21
14
22
class TestBaseClass (unittest .TestCase ):
15
23
@@ -35,20 +43,13 @@ def test_instantiation(self):
35
43
36
44
class TestIoTCoreMQTTConnection (unittest .TestCase ):
37
45
46
+ @config_exists
38
47
def setUp (self ) -> None :
39
- config = Config (
40
- str (
41
- Path (
42
- Path (__file__ ).parents [1 ],
43
- "iotdevicesimulator" ,
44
- "__assets__" ,
45
- "config.cfg" ,
46
- )
47
- )
48
- )
48
+ config = Config (str (CONFIG_PATH ))
49
49
50
50
self .config = config ["iot_core" ]
51
51
52
+ @config_exists
52
53
def test_instantiation (self ):
53
54
54
55
instance = IotCoreMQTTConnection (** self .config , client_id = "test_id" )
@@ -57,6 +58,7 @@ def test_instantiation(self):
57
58
58
59
self .assertIsInstance (instance .connection , awscrt .mqtt .Connection )
59
60
61
+ @config_exists
60
62
def test_non_string_arguments (self ):
61
63
62
64
with self .assertRaises (TypeError ):
@@ -104,6 +106,7 @@ def test_non_string_arguments(self):
104
106
1 ,
105
107
)
106
108
109
+ @config_exists
107
110
def test_port (self ):
108
111
109
112
# Expect one of defaults if no port given
@@ -124,6 +127,7 @@ def test_port(self):
124
127
self .assertEqual (instance .connection .port , 420 )
125
128
126
129
@parameterized .expand ([- 4 , {"f" : 4 }, "FOUR" ])
130
+ @config_exists
127
131
def test_bad_port_type (self , port ):
128
132
129
133
with self .assertRaises ((TypeError , ValueError )):
@@ -136,6 +140,7 @@ def test_bad_port_type(self, port):
136
140
port = port ,
137
141
)
138
142
143
+ @config_exists
139
144
def test_clean_session_set (self ):
140
145
expected = False
141
146
@@ -151,13 +156,15 @@ def test_clean_session_set(self):
151
156
self .assertEqual (instance .connection .clean_session , expected )
152
157
153
158
@parameterized .expand ([0 , - 1 , "true" , None ])
159
+ @config_exists
154
160
def test_bad_clean_session_type (self , clean_session ):
155
161
156
162
with self .assertRaises (TypeError ):
157
163
IotCoreMQTTConnection (
158
164
** self .config , client_id = "test_id" , clean_session = clean_session
159
165
)
160
166
167
+ @config_exists
161
168
def test_keep_alive_secs_set (self ):
162
169
# Test defualt is not none
163
170
instance = IotCoreMQTTConnection (** self .config , client_id = "test_id" )
@@ -171,6 +178,7 @@ def test_keep_alive_secs_set(self):
171
178
self .assertEqual (instance .connection .keep_alive_secs , expected )
172
179
173
180
@parameterized .expand (["FOURTY" , "True" , None ])
181
+ @config_exists
174
182
def test_bad_keep_alive_secs_type (self , secs ):
175
183
with self .assertRaises (TypeError ):
176
184
IotCoreMQTTConnection (
0 commit comments