Skip to content

Instantly share code, notes, and snippets.

@Flameeyes
Last active August 3, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flameeyes/ecf87cbbca3cda2f111f3d7291b1cfaa to your computer and use it in GitHub Desktop.
Save Flameeyes/ecf87cbbca3cda2f111f3d7291b1cfaa to your computer and use it in GitHub Desktop.
diff --git a/tests/test_write_support.py b/tests/test_write_support.py
index e1c66bf..03fe35b 100644
--- a/tests/test_write_support.py
+++ b/tests/test_write_support.py
@@ -6,15 +6,8 @@ import pcapng.blocks as blocks
from pcapng import FileScanner, FileWriter
from pcapng.exceptions import PcapngStrictnessError, PcapngStrictnessWarning
from pcapng.strictness import Strictness, set_strictness
-
-
-def compare_blocklists(list1, list2):
- "Compare two lists of blocks. Helper for the below tests."
-
- assert len(list1) == len(list2)
-
- for i in range(0, len(list1)):
- assert list1[i] == list2[i], "block #{} mismatch".format(i)
+from testfixtures import Comparison as C
+from testfixtures import compare
def test_write_read_all_blocks():
@@ -125,7 +118,7 @@ def test_write_read_all_blocks():
fake_file.seek(0)
in_blocks = list(FileScanner(fake_file))
- compare_blocklists(in_blocks, out_blocks)
+ compare(in_blocks, out_blocks)
def test_spb_snap_lengths():
@@ -176,14 +169,35 @@ def test_spb_snap_lengths():
fake_file.seek(0)
(i_shb, i_idb, i_blk1, i_blk2, i_blk3) = list(FileScanner(fake_file))
- assert i_blk1.captured_len == 16
- assert i_blk1.packet_len == 16
- assert i_blk1.packet_data == data[:16]
+ compare(
+ C(
+ blocks.SimplePacket,
+ captured_len=16,
+ packet_len=16,
+ packet_data=data[:16],
+ strict=False,
+ ),
+ i_blk1,
+ )
- assert i_blk2.captured_len == 32
- assert i_blk2.packet_len == 32
- assert i_blk2.packet_data == data[:32]
+ compare(
+ C(
+ blocks.SimplePacket,
+ captured_len=32,
+ packet_len=32,
+ packet_data=data[:32],
+ strict=False,
+ ),
+ i_blk2,
+ )
- assert i_blk3.captured_len == 32
- assert i_blk3.packet_len == 33
- assert i_blk3.packet_data == data[:32]
+ compare(
+ C(
+ blocks.SimplePacket,
+ captured_len=32,
+ packet_len=33,
+ packet_data=data[:32],
+ strict=False,
+ ),
+ i_blk3,
+ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment