mirror of
https://github.com/nfstream/nfstream.git
synced 2026-10-19 09:43:52 +00:00
Define the anonymizer test plugin at module level
Windows spawns meter processes instead of forking them, so plugin instances must be pickled to reach them. The plugin was defined inside the test function, which cannot be pickled, and the Windows job failed with AttributeError: Can't pickle local object 'NFStreamTest.test_anonymize_absent_values.<locals>.MixedValues' Linux and macOS fork, so the plugin was inherited rather than pickled and the test passed there. The failure was also masked at first because the Windows jobs were failing earlier, at the Npcap download, and never reached the tests. Moving the class to module level makes it picklable, matching how the other plugins used in the suite are defined.
This commit is contained in:
parent
c776ef755f
commit
427ba6e151
1 changed files with 12 additions and 11 deletions
23
tests.py
23
tests.py
|
|
@ -21,6 +21,17 @@ from nfstream import NFPlugin, NFStreamer
|
|||
from nfstream.plugins import SPLT, DHCP, FlowSlicer, MDNS
|
||||
|
||||
|
||||
class AnonymizerMixedValues(NFPlugin):
|
||||
"""Must remain module-level because Windows spawn pickles plugins."""
|
||||
|
||||
def on_init(self, packet, flow):
|
||||
flow.udps.absent = ""
|
||||
flow.udps.populated = "value"
|
||||
flow.udps.zero = 0
|
||||
flow.udps.false = False
|
||||
flow.udps.array = np.zeros(3)
|
||||
|
||||
|
||||
def get_files_list(path):
|
||||
files = []
|
||||
for r, d, f in os.walk(path):
|
||||
|
|
@ -918,20 +929,10 @@ class NFStreamTest(object):
|
|||
"\n----------------------------------------------------------------------"
|
||||
)
|
||||
|
||||
class MixedValues(NFPlugin):
|
||||
"""Produces an absent value alongside values that only look absent."""
|
||||
|
||||
def on_init(self, packet, flow):
|
||||
flow.udps.absent = ""
|
||||
flow.udps.populated = "value"
|
||||
flow.udps.zero = 0
|
||||
flow.udps.false = False
|
||||
flow.udps.array = np.zeros(3)
|
||||
|
||||
df = NFStreamer(
|
||||
source=os.path.join("tests", "pcaps", "google_ssl.pcap"),
|
||||
n_meters=1,
|
||||
udps=MixedValues(),
|
||||
udps=AnonymizerMixedValues(),
|
||||
).to_pandas(
|
||||
columns_to_anonymize=[
|
||||
"udps.absent",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue