Skip to content

Commit 657ef26

Browse files
committed
docs(foundation): teach custom engines to keep a user's verbose callback (#1874)
- The custom-engine example in ext.rst tests `ext._vfunc_default`, not `ext._flag_v`, and says why: a `verbose=` callable must be kept. - Document `Extractor._vfunc_default` on the extraction page. - Run the verbose-callback module on every engine-tests leg, and update the tier guard test that pins the PyShark leg's TEST_PATHS line. Refs #1874
1 parent 06cafcb commit 657ef26

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎.github/workflows/unit-tests.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,11 @@ jobs:
10301030
fi
10311031
10321032
case "$ENGINE" in
1033-
Scapy) TEST_PATHS="tests/toolkit/test_scapy_unit.py tests/foundation/engines/test_scapy_engine.py tests/protocols/transport/test_sctp_unit.py" ;;
1034-
PyShark) TEST_PATHS="tests/toolkit/test_pyshark_unit.py tests/foundation/engines/test_pyshark_engine.py" ;;
1035-
PyPCAPFile) TEST_PATHS="tests/toolkit/test_pypcapfile_unit.py tests/foundation/engines/test_pypcapfile_engine.py" ;;
1036-
PyPCAP) TEST_PATHS="tests/toolkit/test_pypcap_unit.py tests/foundation/engines/test_pypcap_engine.py tests/foundation/engines/test_pcap_backend.py" ;;
1037-
PCAP_CT) TEST_PATHS="tests/toolkit/test_pcap_ct_unit.py tests/foundation/engines/test_pcap_ct_engine.py tests/foundation/engines/test_pcap_backend.py" ;;
1033+
Scapy) TEST_PATHS="tests/toolkit/test_scapy_unit.py tests/foundation/engines/test_scapy_engine.py tests/protocols/transport/test_sctp_unit.py tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;
1034+
PyShark) TEST_PATHS="tests/toolkit/test_pyshark_unit.py tests/foundation/engines/test_pyshark_engine.py tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;
1035+
PyPCAPFile) TEST_PATHS="tests/toolkit/test_pypcapfile_unit.py tests/foundation/engines/test_pypcapfile_engine.py tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;
1036+
PyPCAP) TEST_PATHS="tests/toolkit/test_pypcap_unit.py tests/foundation/engines/test_pypcap_engine.py tests/foundation/engines/test_pcap_backend.py tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;
1037+
PCAP_CT) TEST_PATHS="tests/toolkit/test_pcap_ct_unit.py tests/foundation/engines/test_pcap_ct_engine.py tests/foundation/engines/test_pcap_backend.py tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;
10381038
esac
10391039
echo "Running: $TEST_PATHS"
10401040
# shellcheck disable=SC2086

‎docs/source/ext.rst‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,13 @@ The following code snippet shows how to create a new engine class:
512512
# check if there's any extraction protocol and/or layer thresholds
513513
# set by the user (some engines may not support this feature); or
514514
# to set up the verbose handler for the underlying engine module,
515-
# as in the following code snippet.
515+
# as in the following code snippet. Install it only when the user
516+
# asked for the default output, i.e., `verbose=True`, which sets
517+
# `ext._vfunc_default`: a callable given as `verbose=` is the
518+
# user's own handler, already stored as `ext._vfunc`, so it must
519+
# be kept rather than replaced.
516520
517-
if ext._flag_v: # check if verbose mode is enabled
521+
if ext._vfunc_default: # check if the default verbose output is requested
518522
# NOTE: PyPCAPKit has its own bundled supporting functions for
519523
# third-party libraries, e.g., the `packet2chain` function is
520524
# to convert a given Packet instance of the Scapy library to a

‎docs/source/pcapkit/foundation/extraction.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ and extracts parameters from a PCAP file.
8989

9090
.. autoattribute:: _eof_mark
9191
.. autoattribute:: _vfunc
92+
.. autoattribute:: _vfunc_default
9293

9394
.. autoattribute:: _exnam
9495
.. autoattribute:: _exeng

‎tests/test_tier_guard.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,8 @@ def test_a_commented_out_test_paths_arm_does_not_silently_win(self) -> None:
24102410
24112411
"""
24122412
live = ('PyShark) TEST_PATHS="tests/toolkit/test_pyshark_unit.py '
2413-
'tests/foundation/engines/test_pyshark_engine.py" ;;')
2413+
'tests/foundation/engines/test_pyshark_engine.py '
2414+
'tests/foundation/engines/test_engine_verbose_callback_1874_unit.py" ;;')
24142415
doctored = doctored_workflow(
24152416
self,
24162417
live,
@@ -2422,7 +2423,8 @@ def test_a_commented_out_test_paths_arm_does_not_silently_win(self) -> None:
24222423
pyshark_jobs = [job for job in jobs if job.name == 'engine-tests' and 'PyShark' in job.extras]
24232424
self.assertEqual(len(pyshark_jobs), 1)
24242425
self.assertEqual(pyshark_jobs[0].paths, ('tests/toolkit/test_pyshark_unit.py',
2425-
'tests/foundation/engines/test_pyshark_engine.py'))
2426+
'tests/foundation/engines/test_pyshark_engine.py',
2427+
'tests/foundation/engines/test_engine_verbose_callback_1874_unit.py'))
24262428

24272429
def test_the_undoctored_workflow_produces_no_unexplained_gap(self) -> None:
24282430
"""The control: the tests above fail for the doctoring, not by default."""

0 commit comments

Comments
 (0)