Skip to content

Commit

Permalink
Added marks to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-chambers committed May 30, 2024
1 parent d0bcf2b commit 7aceced
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: pytest
run: pytest -m "not oracle"
7 changes: 1 addition & 6 deletions src/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
import pytest
import config
import pathlib
import threading
from typing import Awaitable
import asyncio
from iotdevicesimulator import db
from iotdevicesimulator.queries import CosmosQuery
import oracledb

CONFIG_PATH = pathlib.Path(
pathlib.Path(__file__).parents[1], "iotdevicesimulator", "__assets__", "config.cfg"
)


config_exists = pytest.mark.skipif(
not CONFIG_PATH.exists(),
reason="Config file `config.cfg` not found in root directory.",
Expand Down Expand Up @@ -55,6 +49,7 @@ async def test_query(self):
self.assertEqual(row["SITE_ID"], site_id)

@pytest.mark.asyncio
@pytest.mark.oracle
@config_exists
async def test_bad_query_type(self):

Expand Down
42 changes: 33 additions & 9 deletions src/tests/test_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
from pathlib import Path
from config import Config

CONFIG_PATH = Path(
Path(__file__).parents[1], "iotdevicesimulator", "__assets__", "config.cfg"
)
config_exists = pytest.mark.skipif(
not CONFIG_PATH.exists(),
reason="Config file `config.cfg` not found in root directory.",
)


class TestCosmosSwarm(unittest.IsolatedAsyncioTestCase):

def setUp(self):
self.config_path = str(
Path(
Path(__file__).parents[1],
"iotdevicesimulator",
"__assets__",
"config.cfg",
)
)

self.config_path = str(CONFIG_PATH)
self.config = Config(self.config_path)["oracle"]

@parameterized.expand(
Expand All @@ -33,6 +33,8 @@ def setUp(self):
]
)
@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_instantiation(
self, site_ids, query, sleep_time, max_cycles, max_sites
):
Expand All @@ -55,16 +57,25 @@ async def test_instantiation(
self.assertEqual(swarm.sleep_time, int(sleep_time))
self.assertEqual(swarm.max_sites, max_sites)

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_config_from_dict(self):
await CosmosSwarm.create(
CosmosQuery.LEVEL_1_NMDB_1HOUR, MockMessageConnection(), self.config
)

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_config_from_path(self):
await CosmosSwarm.create(
CosmosQuery.LEVEL_1_NMDB_1HOUR, MockMessageConnection(), self.config_path
)

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_delay_set(self):
query = CosmosQuery.LEVEL_1_SOILMET_30MIN
swarm = await CosmosSwarm.create(
Expand All @@ -87,6 +98,9 @@ async def test_delay_set(self):

self.assertFalse(swarm.delay_first_cycle)

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_error_if_delay_set_not_bool(self):
query = CosmosQuery.LEVEL_1_SOILMET_30MIN

Expand All @@ -100,6 +114,8 @@ async def test_error_if_delay_set_not_bool(self):
)

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_swarm_name_given(self):
query = CosmosQuery.LEVEL_1_SOILMET_30MIN
swarm = await CosmosSwarm.create(
Expand All @@ -109,6 +125,8 @@ async def test_swarm_name_given(self):
self.assertEqual(swarm.swarm_name, "myswarm")

@pytest.mark.asyncio
@config_exists
@pytest.mark.oracle
async def test_swarm_name_not_given(self):
query = CosmosQuery.LEVEL_1_SOILMET_30MIN
swarm = await CosmosSwarm.create(query, MockMessageConnection(), self.config)
Expand All @@ -118,6 +136,7 @@ async def test_swarm_name_not_given(self):
@parameterized.expand([-1, 1, 10, 35.52])
@pytest.mark.asyncio
@pytest.mark.oracle
@config_exists
async def test_good_max_sites(self, max_sites):
sites = [f"Site {x}" for x in range(10)]

Expand All @@ -142,6 +161,7 @@ async def test_good_max_sites(self, max_sites):
@parameterized.expand(["Four", -3, 0])
@pytest.mark.asyncio
@pytest.mark.oracle
@config_exists
async def test_bad_max_sites(self, max_sites):
sites = [f"Site {x}" for x in range(10)]

Expand All @@ -156,13 +176,15 @@ async def test_bad_max_sites(self, max_sites):

@pytest.mark.asyncio
@pytest.mark.oracle
@config_exists
async def test_get_oracle(self):
oracle = await CosmosSwarm._get_oracle(self.config)

self.assertIsInstance(oracle, Oracle)

@pytest.mark.asyncio
@pytest.mark.oracle
@config_exists
async def test_site_ids_from_db(self):
sleep_time = 12
max_cycles = -1
Expand All @@ -173,6 +195,8 @@ async def test_site_ids_from_db(self):

self.assertTrue([isinstance(site, SensorSite) for site in sites])


class TestCosmosSwarmStatic(unittest.TestCase):
@parameterized.expand([-1, 1, 3, 5, 7.2])
def test_list_restriction_method(self, max_count):

Expand Down

0 comments on commit 7aceced

Please sign in to comment.