Skip to content

Commit 490e96c

Browse files
Skipping tests if no config file present
1 parent e37fbc3 commit 490e96c

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
oracle: {
2+
dsn: "wldbase:1521/wla"
3+
user: "lewcha"
4+
password: "Lucid+Barrel8Valley"
5+
}
6+
iot_core: {
7+
endpoint: "a10mem0twl4qxt-ats.iot.eu-west-2.amazonaws.com"
8+
port: 8883
9+
cert_path: "C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotdevicesimulator/__assets__/.certs/fdri_swarm.cert.pem"
10+
key_path: "C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotdevicesimulator/__assets__/.certs/fdri_swarm.private.key"
11+
ca_cert_path: "C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotdevicesimulator/__assets__/.certs/AmazonRootCA1.pem"
12+
}

src/tests/test_devices.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ def test_sleep_time_bad_value_gives_error(self, sleep_time):
7474
CONFIG_PATH = pathlib.Path(
7575
pathlib.Path(__file__).parents[1], "iotdevicesimulator", "__assets__", "config.cfg"
7676
)
77-
78-
7977
config_exists = pytest.mark.skipif(
8078
not CONFIG_PATH.exists(),
8179
reason="Config file `config.cfg` not found in root directory.",
@@ -85,6 +83,9 @@ def test_sleep_time_bad_value_gives_error(self, sleep_time):
8583
class TestSensorSiteOperation(unittest.IsolatedAsyncioTestCase):
8684
"""Tests the active behaviour of SensorSite objects."""
8785

86+
@pytest.mark.oracle
87+
@pytest.mark.asyncio
88+
@config_exists
8889
async def asyncSetUp(self):
8990
cred_path = str(CONFIG_PATH)
9091
creds = config.Config(cred_path)["oracle"]
@@ -97,11 +98,15 @@ async def asyncSetUp(self):
9798

9899
self.message_connection = MockMessageConnection()
99100

101+
@pytest.mark.oracle
102+
@pytest.mark.asyncio
103+
@config_exists
100104
async def asyncTearDown(self) -> None:
101105
await self.oracle.connection.close()
102106

103107
@pytest.mark.asyncio
104108
@pytest.mark.oracle
109+
@config_exists
105110
async def test_run_stops_after_max_cycles(self):
106111
"""Ensures .run() method breaks after max_cycles"""
107112

@@ -114,6 +119,7 @@ async def test_run_stops_after_max_cycles(self):
114119

115120
@pytest.mark.asyncio
116121
@pytest.mark.oracle
122+
@config_exists
117123
async def test_multi_instances_stop_at_max_cycles(self):
118124
"""Ensures .run() method breaks after max_cycles for multiple instances"""
119125

src/tests/test_messaging.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
import awscrt.io
1111
from parameterized import parameterized
1212

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+
1321

1422
class TestBaseClass(unittest.TestCase):
1523

@@ -35,20 +43,13 @@ def test_instantiation(self):
3543

3644
class TestIoTCoreMQTTConnection(unittest.TestCase):
3745

46+
@config_exists
3847
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))
4949

5050
self.config = config["iot_core"]
5151

52+
@config_exists
5253
def test_instantiation(self):
5354

5455
instance = IotCoreMQTTConnection(**self.config, client_id="test_id")
@@ -57,6 +58,7 @@ def test_instantiation(self):
5758

5859
self.assertIsInstance(instance.connection, awscrt.mqtt.Connection)
5960

61+
@config_exists
6062
def test_non_string_arguments(self):
6163

6264
with self.assertRaises(TypeError):
@@ -104,6 +106,7 @@ def test_non_string_arguments(self):
104106
1,
105107
)
106108

109+
@config_exists
107110
def test_port(self):
108111

109112
# Expect one of defaults if no port given
@@ -124,6 +127,7 @@ def test_port(self):
124127
self.assertEqual(instance.connection.port, 420)
125128

126129
@parameterized.expand([-4, {"f": 4}, "FOUR"])
130+
@config_exists
127131
def test_bad_port_type(self, port):
128132

129133
with self.assertRaises((TypeError, ValueError)):
@@ -136,6 +140,7 @@ def test_bad_port_type(self, port):
136140
port=port,
137141
)
138142

143+
@config_exists
139144
def test_clean_session_set(self):
140145
expected = False
141146

@@ -151,13 +156,15 @@ def test_clean_session_set(self):
151156
self.assertEqual(instance.connection.clean_session, expected)
152157

153158
@parameterized.expand([0, -1, "true", None])
159+
@config_exists
154160
def test_bad_clean_session_type(self, clean_session):
155161

156162
with self.assertRaises(TypeError):
157163
IotCoreMQTTConnection(
158164
**self.config, client_id="test_id", clean_session=clean_session
159165
)
160166

167+
@config_exists
161168
def test_keep_alive_secs_set(self):
162169
# Test defualt is not none
163170
instance = IotCoreMQTTConnection(**self.config, client_id="test_id")
@@ -171,6 +178,7 @@ def test_keep_alive_secs_set(self):
171178
self.assertEqual(instance.connection.keep_alive_secs, expected)
172179

173180
@parameterized.expand(["FOURTY", "True", None])
181+
@config_exists
174182
def test_bad_keep_alive_secs_type(self, secs):
175183
with self.assertRaises(TypeError):
176184
IotCoreMQTTConnection(

0 commit comments

Comments
 (0)