From 49fe5dfaa46cad7c77b71d90461ca7d00d0a7f6f Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Thu, 19 Jun 2025 13:08:30 +0300 Subject: [PATCH 1/9] Fixed Ruff errors --- examples/__init__.py | 0 examples/filesystem.py | 51 +++++++++++++++++++--------------- examples/passivedns.py | 20 +++++++------ examples/tcpconn.py | 7 +++-- flow/record/adapter/elastic.py | 6 ++-- flow/record/tools/rdump.py | 3 +- tests/standalone_test.py | 2 +- tests/test_fieldtypes.py | 6 ++-- tests/test_packer.py | 8 ++---- tests/test_rdump.py | 3 +- tests/test_record.py | 3 +- tests/test_record_adapter.py | 2 +- tests/test_splunk_adapter.py | 4 --- tests/test_xlsx_adapter.py | 3 +- 14 files changed, 57 insertions(+), 61 deletions(-) create mode 100644 examples/__init__.py diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/filesystem.py b/examples/filesystem.py index b5d8d469..57135eb0 100644 --- a/examples/filesystem.py +++ b/examples/filesystem.py @@ -1,10 +1,18 @@ +from __future__ import annotations + import os import stat - from datetime import datetime +from pathlib import Path +from typing import TYPE_CHECKING +from zoneinfo import ZoneInfo from flow.record import RecordDescriptor, RecordWriter +if TYPE_CHECKING: + from collections.abc import Iterator + + descriptor = """ filesystem/unix/entry string path; @@ -22,31 +30,29 @@ FilesystemFile = RecordDescriptor(descriptor) -def hash_file(path, t): - f = open(path, "rb") - while 1: - d = f.read(4096) - if d == "": - break - f.close() +def hash_file(path: str | Path) -> None: + with Path(path).open("rb") as f: + while 1: + d = f.read(4096) + if d == "": + break class FilesystemIterator: basepath = None - def __init__(self, basepath): + def __init__(self, basepath: str | None): self.basepath = basepath self.recordType = FilesystemFile - def classify(self, source, classification): + def classify(self, source: str, classification: str) -> None: self.recordType = FilesystemFile.base(_source=source, _classification=classification) - def iter(self, path): - path = os.path.abspath(path) - return self._iter(path) + def iter(self, path: Path) -> Iterator[FilesystemFile]: + return self._iter(path.resolve()) - def _iter(self, path): - if path.startswith("/proc"): + def _iter(self, path: Path) -> Iterator[FilesystemFile]: + if "proc" in path.parts: return st = os.lstat(path) @@ -59,7 +65,7 @@ def _iter(self, path): link = None if ifmt == stat.S_IFLNK: - link = os.readlink(path) + link = path.readlink() yield self.recordType( path=abspath, @@ -69,20 +75,19 @@ def _iter(self, path): size=st.st_size, uid=st.st_uid, gid=st.st_gid, - ctime=datetime.fromtimestamp(st.st_ctime), - mtime=datetime.fromtimestamp(st.st_mtime), - atime=datetime.fromtimestamp(st.st_atime), + ctime=datetime.fromtimestamp(st.st_ctime, tz=ZoneInfo("UTC")), + mtime=datetime.fromtimestamp(st.st_mtime, tz=ZoneInfo("UTC")), + atime=datetime.fromtimestamp(st.st_atime, tz=ZoneInfo("UTC")), link=link, ) if ifmt == stat.S_IFDIR: - for i in os.listdir(path): + for i in path.iterdir(): if i in (".", ".."): continue - fullpath = os.path.join(path, i) - for e in self.iter(fullpath): - yield e + fullpath = path.joinpath(i) + yield from self.iter(fullpath) chunk = [] diff --git a/examples/passivedns.py b/examples/passivedns.py index 28361d80..be752b03 100644 --- a/examples/passivedns.py +++ b/examples/passivedns.py @@ -1,18 +1,20 @@ #!/usr/bin/env pypy -import record -import sys +from __future__ import annotations + import datetime +import sys +from zoneinfo import ZoneInfo import net.ipv4 - +import record from fileprocessing import DirectoryProcessor -def ts(s): - return datetime.datetime.fromtimestamp(float(s)) +def ts(s: float) -> datetime.datetime: + return datetime.datetime.fromtimestamp(float(s), tz=ZoneInfo("UTC")) -def ip(s): +def ip(s: str) -> net.ipv4.Address: return net.ipv4.Address(s) @@ -21,7 +23,7 @@ class SeparatedFile: seperator = None format = None - def __init__(self, fp, seperator, format): + def __init__(self, fp: list[str], seperator: str | None, format: list[tuple]): self.fp = fp self.seperator = seperator self.format = format @@ -46,7 +48,7 @@ def __iter__(self): yield recordtype(**r) -def PassiveDnsFile(fp): +def PassiveDnsFile(fp: list[str]) -> SeparatedFile: return SeparatedFile(fp, "||", PASSIVEDNS_FORMAT) @@ -63,7 +65,7 @@ def PassiveDnsFile(fp): ] -def main(): +def main() -> None: rs = record.RecordOutput(sys.stdout) for r in DirectoryProcessor(sys.argv[1], PassiveDnsFile, r"\.log\.gz"): rs.write(r) diff --git a/examples/tcpconn.py b/examples/tcpconn.py index 0c10faa0..5870ece7 100644 --- a/examples/tcpconn.py +++ b/examples/tcpconn.py @@ -1,6 +1,7 @@ import random - from datetime import datetime +from zoneinfo import ZoneInfo + from flow import record descriptor = """ @@ -32,9 +33,9 @@ rs = record.RecordWriter() -for i in range(500): +for _ in range(500): r = conn( - ts=datetime.now(), + ts=datetime.now(tz=ZoneInfo("UTC")), src=random.choice(ip_list), srcport=random.choice(port_list), dst=random.choice(ip_list), diff --git a/flow/record/adapter/elastic.py b/flow/record/adapter/elastic.py index 6a74bf28..17a6e61b 100644 --- a/flow/record/adapter/elastic.py +++ b/flow/record/adapter/elastic.py @@ -6,6 +6,8 @@ import threading from typing import TYPE_CHECKING +import urllib3 + try: import elasticsearch import elasticsearch.helpers @@ -102,8 +104,6 @@ def __init__( if not verify_certs: # Disable InsecureRequestWarning of urllib3, caused by the verify_certs flag. - import urllib3 - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) self.metadata_fields = {} @@ -234,8 +234,6 @@ def __init__( if not verify_certs: # Disable InsecureRequestWarning of urllib3, caused by the verify_certs flag. - import urllib3 - urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def __iter__(self) -> Iterator[Record]: diff --git a/flow/record/tools/rdump.py b/flow/record/tools/rdump.py index f9759355..356c7a23 100644 --- a/flow/record/tools/rdump.py +++ b/flow/record/tools/rdump.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from __future__ import annotations +import argparse import logging import sys from importlib import import_module @@ -69,8 +70,6 @@ def list_adapters() -> None: @catch_sigpipe def main(argv: list[str] | None = None) -> int: - import argparse - parser = argparse.ArgumentParser( description="Record dumper, a tool that can read, write and filter records", formatter_class=argparse.ArgumentDefaultsHelpFormatter, diff --git a/tests/standalone_test.py b/tests/standalone_test.py index 9bd0137c..6389754e 100644 --- a/tests/standalone_test.py +++ b/tests/standalone_test.py @@ -1,5 +1,6 @@ from __future__ import annotations +import traceback from typing import Callable @@ -14,6 +15,5 @@ def main(glob: dict[str, Callable[..., None]]) -> None: print("PASSED") except Exception: print("FAILED") - import traceback traceback.print_exc() diff --git a/tests/test_fieldtypes.py b/tests/test_fieldtypes.py index e6402892..27d011a2 100644 --- a/tests/test_fieldtypes.py +++ b/tests/test_fieldtypes.py @@ -376,15 +376,15 @@ def test_uri_type() -> None: assert r.path.protocol == "http" assert r.path.hostname == "example.com" - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning): # noqa r = TestRecord(uri.from_windows(r"c:\windows\program files\Fox-IT B.V\flow.exe")) assert r.path.filename == "flow.exe" r = TestRecord() - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning): # noqa r.path = uri.normalize(r"c:\Users\Fox-IT\Downloads\autoruns.exe") assert r.path.filename == "autoruns.exe" - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning): # noqa assert r.path.dirname == uri.normalize(r"\Users\Fox-IT\Downloads") assert r.path.dirname == "/Users/Fox-IT/Downloads" diff --git a/tests/test_packer.py b/tests/test_packer.py index cff4ca35..32e82c64 100644 --- a/tests/test_packer.py +++ b/tests/test_packer.py @@ -22,7 +22,7 @@ def test_uri_packing() -> None: ], ) - # construct with an url + # Construct with an url record = TestRecord("http://www.google.com/evil.bin") data = packer.pack(record) record = packer.unpack(data) @@ -30,8 +30,7 @@ def test_uri_packing() -> None: assert record.path.filename == "evil.bin" assert record.path.dirname == "/" - # construct from uri() -> for windows=True - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning, match="Construct from uri() -> for windows=True"): path = uri.from_windows(r"c:\Program Files\Fox-IT\flow is awesome.exe") record = TestRecord(path) data = packer.pack(record) @@ -40,8 +39,7 @@ def test_uri_packing() -> None: assert record.path.filename == "flow is awesome.exe" assert record.path.dirname == "/Program Files/Fox-IT" - # construct using uri.from_windows() - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning, match="Construct using uri.from_windows()"): path = uri.from_windows(r"c:\Users\Hello World\foo.bar.exe") record = TestRecord(path) data = packer.pack(record) diff --git a/tests/test_rdump.py b/tests/test_rdump.py index 783855a2..723e2978 100644 --- a/tests/test_rdump.py +++ b/tests/test_rdump.py @@ -17,6 +17,7 @@ import flow.record.fieldtypes from flow.record import RecordDescriptor, RecordReader, RecordWriter +from flow.record.adapter.line import field_types_for_record_descriptor from flow.record.fieldtypes import flow_record_tz from flow.record.tools import rdump @@ -681,8 +682,6 @@ def test_rdump_line_verbose(tmp_path: Path, capsys: pytest.CaptureFixture, rdump writer.write(TestRecord(counter=2)) writer.write(TestRecord(counter=3)) - from flow.record.adapter.line import field_types_for_record_descriptor - field_types_for_record_descriptor.cache_clear() assert field_types_for_record_descriptor.cache_info().currsize == 0 rdump.main([str(record_path), *rdump_params]) diff --git a/tests/test_record.py b/tests/test_record.py index 88360a43..a5959a19 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -10,6 +10,7 @@ import pytest from flow.record import ( + IGNORE_FIELDS_FOR_COMPARISON, RECORD_VERSION, GroupedRecord, Record, @@ -862,8 +863,6 @@ def test_compare_environment_variable() -> None: importlib.import_module("flow.record") - from flow.record import IGNORE_FIELDS_FOR_COMPARISON, RecordDescriptor - assert {"_generated", "lastname"} == IGNORE_FIELDS_FOR_COMPARISON TestRecord = RecordDescriptor( diff --git a/tests/test_record_adapter.py b/tests/test_record_adapter.py index ed20bc96..8f821d73 100644 --- a/tests/test_record_adapter.py +++ b/tests/test_record_adapter.py @@ -242,7 +242,7 @@ def test_record_adapter_archive(tmp_path: Path) -> None: # defaults to always archive by /YEAR/MONTH/DAY/ dir structure outdir = tmp_path.joinpath(f"{dt:%Y/%m/%d}") - assert len(list(outdir.iterdir())) + assert list(outdir.iterdir()) # read the archived records and test filename and counts count2 = 0 diff --git a/tests/test_splunk_adapter.py b/tests/test_splunk_adapter.py index e827ee4a..0580ea07 100644 --- a/tests/test_splunk_adapter.py +++ b/tests/test_splunk_adapter.py @@ -339,8 +339,6 @@ def test_https_protocol_records_sourcetype(mock_httpx_package: MagicMock) -> Non if "flow.record.adapter.splunk" in sys.modules: del sys.modules["flow.record.adapter.splunk"] - from flow.record.adapter.splunk import Protocol, SourceType, SplunkWriter - with patch.object( flow.record.adapter.splunk, "HAS_HTTPX", @@ -387,8 +385,6 @@ def test_https_protocol_json_sourcetype(mock_httpx_package: MagicMock) -> None: if "flow.record.adapter.splunk" in sys.modules: del sys.modules["flow.record.adapter.splunk"] - from flow.record.adapter.splunk import SplunkWriter - with patch.object( flow.record.adapter.splunk, "HAS_HTTPX", diff --git a/tests/test_xlsx_adapter.py b/tests/test_xlsx_adapter.py index 91fa1594..558b7234 100644 --- a/tests/test_xlsx_adapter.py +++ b/tests/test_xlsx_adapter.py @@ -9,6 +9,7 @@ import pytest from flow.record import fieldtypes +from flow.record.adapter.xlsx import sanitize_fieldvalues if TYPE_CHECKING: from collections.abc import Iterator @@ -27,8 +28,6 @@ def mock_openpyxl_package(monkeypatch: pytest.MonkeyPatch) -> Iterator[MagicMock def test_sanitize_field_values(mock_openpyxl_package: MagicMock) -> None: - from flow.record.adapter.xlsx import sanitize_fieldvalues - assert list( sanitize_fieldvalues( [ From 89ff7c36e61affb2167e55f72759a50430b85dbf Mon Sep 17 00:00:00 2001 From: B0TAxy <59702228+B0TAxy@users.noreply.github.com> Date: Sun, 22 Jun 2025 12:49:34 +0300 Subject: [PATCH 2/9] Apply suggestions from code review Applied examples/filesystem.py suggestions Co-authored-by: Yun Zheng Hu --- examples/filesystem.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/filesystem.py b/examples/filesystem.py index 57135eb0..7964775d 100644 --- a/examples/filesystem.py +++ b/examples/filesystem.py @@ -32,9 +32,9 @@ def hash_file(path: str | Path) -> None: with Path(path).open("rb") as f: - while 1: + while True: d = f.read(4096) - if d == "": + if not d: break @@ -48,14 +48,14 @@ def __init__(self, basepath: str | None): def classify(self, source: str, classification: str) -> None: self.recordType = FilesystemFile.base(_source=source, _classification=classification) - def iter(self, path: Path) -> Iterator[FilesystemFile]: - return self._iter(path.resolve()) + def iter(self, path: str | Path) -> Iterator[FilesystemFile]: + return self._iter(Path(path).resolve()) def _iter(self, path: Path) -> Iterator[FilesystemFile]: - if "proc" in path.parts: + if path.is_relative_to("/proc"): return - st = os.lstat(path) + st = path.lstat() abspath = path if self.basepath and abspath.startswith(self.basepath): @@ -75,9 +75,9 @@ def _iter(self, path: Path) -> Iterator[FilesystemFile]: size=st.st_size, uid=st.st_uid, gid=st.st_gid, - ctime=datetime.fromtimestamp(st.st_ctime, tz=ZoneInfo("UTC")), - mtime=datetime.fromtimestamp(st.st_mtime, tz=ZoneInfo("UTC")), - atime=datetime.fromtimestamp(st.st_atime, tz=ZoneInfo("UTC")), + ctime=st.st_ctime, + mtime=st.st_mtime, + atime=st.st_atime, link=link, ) From 35fd3946307b2c4df3021272a31a9082a2ade470 Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 12:51:53 +0300 Subject: [PATCH 3/9] finished examples/filesystem.py --- examples/filesystem.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/filesystem.py b/examples/filesystem.py index 7964775d..eb35bff9 100644 --- a/examples/filesystem.py +++ b/examples/filesystem.py @@ -1,11 +1,8 @@ from __future__ import annotations -import os import stat -from datetime import datetime from pathlib import Path from typing import TYPE_CHECKING -from zoneinfo import ZoneInfo from flow.record import RecordDescriptor, RecordWriter @@ -83,9 +80,6 @@ def _iter(self, path: Path) -> Iterator[FilesystemFile]: if ifmt == stat.S_IFDIR: for i in path.iterdir(): - if i in (".", ".."): - continue - fullpath = path.joinpath(i) yield from self.iter(fullpath) From acb29efb1cc0033cf6f2f3fc71192fa5d168c015 Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 12:54:18 +0300 Subject: [PATCH 4/9] finished examples/passivedns.py --- examples/passivedns.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/passivedns.py b/examples/passivedns.py index be752b03..5bc14af1 100644 --- a/examples/passivedns.py +++ b/examples/passivedns.py @@ -1,17 +1,16 @@ #!/usr/bin/env pypy from __future__ import annotations -import datetime import sys -from zoneinfo import ZoneInfo +from datetime import datetime, timezone import net.ipv4 import record from fileprocessing import DirectoryProcessor -def ts(s: float) -> datetime.datetime: - return datetime.datetime.fromtimestamp(float(s), tz=ZoneInfo("UTC")) +def ts(s: float) -> datetime: + return datetime.fromtimestamp(float(s), tz=timezone.utc) def ip(s: str) -> net.ipv4.Address: From cd17e99c01ef9a39a1ee3697733bd8abed351fdc Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 12:55:44 +0300 Subject: [PATCH 5/9] Missed comment in examples/passivedns.py --- examples/passivedns.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/passivedns.py b/examples/passivedns.py index 5bc14af1..663d6498 100644 --- a/examples/passivedns.py +++ b/examples/passivedns.py @@ -9,8 +9,11 @@ from fileprocessing import DirectoryProcessor +UTC_TIMEZONE = timezone.utc + + def ts(s: float) -> datetime: - return datetime.fromtimestamp(float(s), tz=timezone.utc) + return datetime.fromtimestamp(float(s), tz=UTC_TIMEZONE) def ip(s: str) -> net.ipv4.Address: From 221435a499de97c2835b160347f23e6d580b4504 Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 13:59:11 +0300 Subject: [PATCH 6/9] Fixed PR comments --- examples/passivedns.py | 1 - examples/tcpconn.py | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/passivedns.py b/examples/passivedns.py index 663d6498..57e3a6b5 100644 --- a/examples/passivedns.py +++ b/examples/passivedns.py @@ -8,7 +8,6 @@ import record from fileprocessing import DirectoryProcessor - UTC_TIMEZONE = timezone.utc diff --git a/examples/tcpconn.py b/examples/tcpconn.py index 5870ece7..078d6d3e 100644 --- a/examples/tcpconn.py +++ b/examples/tcpconn.py @@ -1,9 +1,10 @@ import random -from datetime import datetime -from zoneinfo import ZoneInfo +from datetime import datetime, timezone from flow import record +UTC_TIMEZONE = timezone.utc + descriptor = """ network/traffic/tcp/connection datetime ts; @@ -35,7 +36,7 @@ for _ in range(500): r = conn( - ts=datetime.now(tz=ZoneInfo("UTC")), + ts=datetime.now(tz=UTC_TIMEZONE), src=random.choice(ip_list), srcport=random.choice(port_list), dst=random.choice(ip_list), From dec22d4efd1cff7b48c354666eae25eaab19a6b1 Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 14:22:17 +0300 Subject: [PATCH 7/9] Added dependency --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 9776758a..8892b42a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,10 +56,14 @@ duckdb = [ splunk = [ "httpx", ] +xlsx = [ + "openpyxl", +] test = [ "flow.record[compression]", "flow.record[avro]", "flow.record[elastic]", + "flow.record[xlsx]", "duckdb; platform_python_implementation != 'PyPy' and python_version < '3.12'", # duckdb "pytz; platform_python_implementation != 'PyPy' and python_version < '3.12'", # duckdb "tqdm", From 14dfa7762d9d1feddc8d9f6f7423344a7ec057ea Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 15:45:51 +0300 Subject: [PATCH 8/9] Fixed tests --- flow/record/base.py | 2 ++ tests/test_fieldtypes.py | 12 +++++++++--- tests/test_packer.py | 8 ++++++-- tests/test_record.py | 4 +++- tests/test_splunk_adapter.py | 4 ++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/flow/record/base.py b/flow/record/base.py index 7584f34c..23e5dd99 100644 --- a/flow/record/base.py +++ b/flow/record/base.py @@ -117,6 +117,7 @@ def _unpack(__cls, {args}): def set_ignored_fields_for_comparison(ignored_fields: Iterator[str]) -> None: """Can be used to update the IGNORE_FIELDS_FOR_COMPARISON from outside the flow.record package scope""" global IGNORE_FIELDS_FOR_COMPARISON + print(f"{ignored_fields=}") IGNORE_FIELDS_FOR_COMPARISON = set(ignored_fields) @@ -186,6 +187,7 @@ def _asdict(self, fields: list[str] | None = None, exclude: list[str] | None = N return OrderedDict((k, getattr(self, k)) for k in self.__slots__ if k not in exclude) if TYPE_CHECKING: + def __getattr__(self, name: str) -> Any: ... def __setattr__(self, k: str, v: Any) -> None: diff --git a/tests/test_fieldtypes.py b/tests/test_fieldtypes.py index 27d011a2..87411125 100644 --- a/tests/test_fieldtypes.py +++ b/tests/test_fieldtypes.py @@ -376,15 +376,21 @@ def test_uri_type() -> None: assert r.path.protocol == "http" assert r.path.hostname == "example.com" - with pytest.warns(DeprecationWarning): # noqa + with pytest.warns( + DeprecationWarning, match=r"Do not use class uri\(...\) for filesystem paths, use class path\(...\)" + ): r = TestRecord(uri.from_windows(r"c:\windows\program files\Fox-IT B.V\flow.exe")) assert r.path.filename == "flow.exe" r = TestRecord() - with pytest.warns(DeprecationWarning): # noqa + with pytest.warns( + DeprecationWarning, match=r"Do not use class uri\(...\) for filesystem paths, use class path\(...\)" + ): r.path = uri.normalize(r"c:\Users\Fox-IT\Downloads\autoruns.exe") assert r.path.filename == "autoruns.exe" - with pytest.warns(DeprecationWarning): # noqa + with pytest.warns( + DeprecationWarning, match=r"Do not use class uri\(...\) for filesystem paths, use class path\(...\)" + ): assert r.path.dirname == uri.normalize(r"\Users\Fox-IT\Downloads") assert r.path.dirname == "/Users/Fox-IT/Downloads" diff --git a/tests/test_packer.py b/tests/test_packer.py index 32e82c64..17eadc64 100644 --- a/tests/test_packer.py +++ b/tests/test_packer.py @@ -30,7 +30,9 @@ def test_uri_packing() -> None: assert record.path.filename == "evil.bin" assert record.path.dirname == "/" - with pytest.warns(DeprecationWarning, match="Construct from uri() -> for windows=True"): + with pytest.warns( + DeprecationWarning, match=r"Do not use class uri\(...\) for filesystem paths, use class path\(...\)" + ): path = uri.from_windows(r"c:\Program Files\Fox-IT\flow is awesome.exe") record = TestRecord(path) data = packer.pack(record) @@ -39,7 +41,9 @@ def test_uri_packing() -> None: assert record.path.filename == "flow is awesome.exe" assert record.path.dirname == "/Program Files/Fox-IT" - with pytest.warns(DeprecationWarning, match="Construct using uri.from_windows()"): + with pytest.warns( + DeprecationWarning, match=r"Do not use class uri\(...\) for filesystem paths, use class path\(...\)" + ): path = uri.from_windows(r"c:\Users\Hello World\foo.bar.exe") record = TestRecord(path) data = packer.pack(record) diff --git a/tests/test_record.py b/tests/test_record.py index 772a7e6c..92f7e33a 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -10,7 +10,6 @@ import pytest from flow.record import ( - IGNORE_FIELDS_FOR_COMPARISON, RECORD_VERSION, GroupedRecord, Record, @@ -878,6 +877,9 @@ def test_compare_environment_variable() -> None: importlib.import_module("flow.record") + from flow.record import IGNORE_FIELDS_FOR_COMPARISON, RecordDescriptor + + print(f"{IGNORE_FIELDS_FOR_COMPARISON=}") assert {"_generated", "lastname"} == IGNORE_FIELDS_FOR_COMPARISON TestRecord = RecordDescriptor( diff --git a/tests/test_splunk_adapter.py b/tests/test_splunk_adapter.py index 0580ea07..e827ee4a 100644 --- a/tests/test_splunk_adapter.py +++ b/tests/test_splunk_adapter.py @@ -339,6 +339,8 @@ def test_https_protocol_records_sourcetype(mock_httpx_package: MagicMock) -> Non if "flow.record.adapter.splunk" in sys.modules: del sys.modules["flow.record.adapter.splunk"] + from flow.record.adapter.splunk import Protocol, SourceType, SplunkWriter + with patch.object( flow.record.adapter.splunk, "HAS_HTTPX", @@ -385,6 +387,8 @@ def test_https_protocol_json_sourcetype(mock_httpx_package: MagicMock) -> None: if "flow.record.adapter.splunk" in sys.modules: del sys.modules["flow.record.adapter.splunk"] + from flow.record.adapter.splunk import SplunkWriter + with patch.object( flow.record.adapter.splunk, "HAS_HTTPX", From fe15422f18185c2652431756a777bab9673aa58e Mon Sep 17 00:00:00 2001 From: B0TAxy Date: Sun, 22 Jun 2025 16:07:59 +0300 Subject: [PATCH 9/9] Removed prints --- flow/record/base.py | 1 - tests/test_record.py | 1 - 2 files changed, 2 deletions(-) diff --git a/flow/record/base.py b/flow/record/base.py index 23e5dd99..32649807 100644 --- a/flow/record/base.py +++ b/flow/record/base.py @@ -117,7 +117,6 @@ def _unpack(__cls, {args}): def set_ignored_fields_for_comparison(ignored_fields: Iterator[str]) -> None: """Can be used to update the IGNORE_FIELDS_FOR_COMPARISON from outside the flow.record package scope""" global IGNORE_FIELDS_FOR_COMPARISON - print(f"{ignored_fields=}") IGNORE_FIELDS_FOR_COMPARISON = set(ignored_fields) diff --git a/tests/test_record.py b/tests/test_record.py index 92f7e33a..00c471fb 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -879,7 +879,6 @@ def test_compare_environment_variable() -> None: from flow.record import IGNORE_FIELDS_FOR_COMPARISON, RecordDescriptor - print(f"{IGNORE_FIELDS_FOR_COMPARISON=}") assert {"_generated", "lastname"} == IGNORE_FIELDS_FOR_COMPARISON TestRecord = RecordDescriptor(