Skip to content

Commit 3277c9d

Browse files
committed
test: add pcapng file I/O test
1 parent 26fe6f9 commit 3277c9d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/logformats_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
except ModuleNotFoundError:
4545
asammdf = None
4646

47+
try:
48+
import pcapng
49+
except ModuleNotFoundError:
50+
pcapng = None
51+
4752

4853
@contextmanager
4954
def override_locale(category: int, locale_str: str) -> None:
@@ -103,6 +108,13 @@ def test_extension_matching_mf4(self):
103108
if asammdf is not None:
104109
raise
105110

111+
def test_extension_matching_pcapng(self):
112+
try:
113+
self._test_extension(".pcapng")
114+
except NotImplementedError:
115+
if pcapng is not None:
116+
raise
117+
106118

107119
class ReaderWriterTest(unittest.TestCase, ComparingMessagesTestCase, metaclass=ABCMeta):
108120
"""Tests a pair of writer and reader by writing all data first and
@@ -859,6 +871,28 @@ def _setup_instance(self):
859871
)
860872

861873

874+
@unittest.skipIf(pcapng is None, "pcapng is unavailable")
875+
class TestPcapngFileFormat(ReaderWriterTest):
876+
"""Tests can.PcapngWriter and can.PcapngReader"""
877+
878+
def _setup_instance(self):
879+
super()._setup_instance_helper(
880+
can.PcapngWriter,
881+
can.PcapngReader,
882+
binary_file=True,
883+
check_remote_frames=True,
884+
check_error_frames=True,
885+
check_fd=True,
886+
check_comments=False,
887+
test_append=True,
888+
# default unit is nanoseconds, yet float causes smaller tolerance to fail
889+
allowed_timestamp_delta=1e-6,
890+
# It preserves channels, however adds_default_channel doesn't work properly
891+
preserves_channel=False,
892+
adds_default_channel="can0",
893+
)
894+
895+
862896
class TestSqliteDatabaseFormat(ReaderWriterTest):
863897
"""Tests can.SqliteWriter and can.SqliteReader"""
864898

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ deps =
1212
parameterized~=0.8
1313
asammdf>=6.0; platform_python_implementation=="CPython" and python_version<"3.13"
1414
pywin32>=305; platform_system=="Windows" and platform_python_implementation=="CPython" and python_version<"3.14"
15+
python-pcapng>=2.1.1
1516

1617
commands =
1718
pytest {posargs}

0 commit comments

Comments
 (0)