Skip to content

Commit cd40c47

Browse files
committed
tests skeleton
1 parent 4861d0b commit cd40c47

12 files changed

Lines changed: 422 additions & 68 deletions

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ A Web Interface is available to monitor which frames are pending for which devic
6767

6868
![monitor screenshot](images/monitor.png)
6969

70+
# Software architecture
71+
72+
![sw arch](images/arch.png)
73+
74+
75+
# Test
76+
77+
Tests should always be run inside the `tests` folder for proper initialization.
78+
7079
# Roadmap
7180

7281
- HTTP Input/Output
82+
- Do some modularization to allow interfacing multiple decoders
7383
- Tests

images/arch.png

36.7 KB
Loading

src/app/main.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_max_chunk():
6262
######## FRAME PROCESSING #########
6363

6464
# Reassemble frames
65-
def reassemble_frame(devEUI: str):
65+
def reassemble_frame(devEUI: str) -> bytes | None:
6666
global frame_buffer
6767
if devEUI in frame_buffer:
6868
reconstructed_frame = b''.join([frame["raw"] for frame in frame_buffer[devEUI]])
@@ -91,6 +91,7 @@ def process_frame(devEUI: str):
9191

9292
else:
9393
logger.debug("Tried to process a devEUI that didn't have any frame...")
94+
return -1
9495

9596
def frame_timeout_checker():
9697
while not exit_event.is_set():
@@ -228,6 +229,9 @@ def load_config() -> dict:
228229

229230
def launch():
230231
global config, js_worker_process, task_queue, result_queue
232+
233+
234+
######## CONFIG
231235
config = load_config()
232236

233237
match config["log"]["level"]:
@@ -247,9 +251,12 @@ def launch():
247251
logger.setLevel(log_level)
248252

249253

254+
########### Javascript
250255
js_worker_process, task_queue, result_queue = js_fetcher.start_js_worker()
251256

252-
# Init self broker
257+
258+
259+
########## SELF BROKER
253260
if config["local-broker"]["enable"] == True:
254261
mosquitto_process = self_broker.start_mosquitto()
255262

@@ -265,7 +272,7 @@ def launch():
265272

266273

267274

268-
# Init input
275+
########## Init input
269276
if config["input"]["mqtt"]["enable"] == True:
270277
mqtt_client = mqtt.Client(callback_api_version=CallbackAPIVersion.VERSION2)
271278
mqtt_client.on_message = on_mqtt_message
@@ -291,7 +298,7 @@ def launch():
291298
logger.info("HTTP Server started...")
292299

293300

294-
#### Init output
301+
##### Init output
295302
if config["output"]["mqtt"]["enable"] == True:
296303
try:
297304
client_output.connect(config["output"]["mqtt"]["host"], config["output"]["mqtt"]["port"])
@@ -305,14 +312,11 @@ def launch():
305312

306313

307314

308-
# Timeout checker thread
315+
######## Timeout checker thread
309316
timeout_thread = threading.Thread(target=frame_timeout_checker, daemon=True)
310317
timeout_thread.start()
311318

312319

313-
314-
315-
316320
logger.info("Application started and waiting for input...")
317321

318322
# Keep the main thread alive

tests/conftest.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33
import pytest
44

55
# Ajouter le dossier src/app au sys.path pour les imports relatifs
6-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src/app')))
6+
sys.path.insert(0, os.path.abspath(path=os.path.join(os.path.dirname(__file__), '..', 'src/app')))
77

8-
from main import frame_buffer
8+
# Put the interpreter at the right place to resolve imports
9+
os.chdir(os.path.dirname(__file__))
10+
11+
from main import frame_buffer, exit_event
12+
13+
# @pytest.fixture(autouse=True)
14+
# def clear_frame_buffer():
15+
# """
16+
# Vide le frame_buffer avant chaque test pour garantir un état propre.
17+
# """
18+
# frame_buffer.clear()
19+
# yield
920

1021
@pytest.fixture(autouse=True)
11-
def clear_frame_buffer():
22+
def exit_event_unset():
1223
"""
1324
Vide le frame_buffer avant chaque test pour garantir un état propre.
1425
"""
15-
frame_buffer.clear()
26+
exit_event.clear()
1627
yield
28+
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
markers =
3+
mock_patch_reassemble
4+
mock_config_value

0 commit comments

Comments
 (0)