Coverage for tests/tests/test_devices.py: 0%

35 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2026-01-05 21:46 +0100

1#!/usr/bin/env python3 

2"""RAMSES RF - Test the payload parsers on a per-device basis.""" 

3 

4from pathlib import Path, PurePath 

5 

6import pytest 

7 

8from ramses_tx import exceptions as exc 

9from ramses_tx.message import Message 

10from ramses_tx.packet import Packet 

11 

12from .helpers import TEST_DIR 

13 

14WORK_DIR = f"{TEST_DIR}/devices" 

15 

16 

17def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: 

18 def id_fnc(param: Path) -> str: 

19 return PurePath(param).name 

20 

21 metafunc.parametrize("f_name", sorted(Path(WORK_DIR).glob("*.log")), ids=id_fnc) 

22 

23 

24def _proc_log_line(log_line: str) -> None: 

25 pkt_line, pkt_eval, *_ = list( 

26 map(str.strip, log_line.split("#", maxsplit=1) + [""]) 

27 ) 

28 

29 if not pkt_line: 

30 return 

31 

32 try: 

33 pkt = Packet.from_file(pkt_line[:26], pkt_line[27:]) 

34 except exc.PacketInvalid as err: 

35 assert False, f"{pkt_line[27:]} < {err}" 

36 

37 try: 

38 _ = Message(pkt) 

39 except exc.PacketPayloadInvalid as err: 

40 assert False, f"{pkt} < {err}" 

41 

42 # assert bool(msg._is_fragment) == pkt._is_fragment 

43 # assert bool(msg._idx): dict == pkt._idx: Optional[bool | str] # not useful 

44 

45 if not pkt_eval: 

46 return 

47 try: 

48 _ = eval(pkt_eval) 

49 except SyntaxError: 

50 if "{" in pkt_eval: 

51 raise 

52 return 

53 

54 

55def test_parsers_from_log_files(f_name: Path) -> None: 

56 with open(f_name) as f: 

57 while line := (f.readline()): 

58 _proc_log_line(line)