From 9ad064297690596745a60b4c0ce386d9c64f298a Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Sat, 7 Dec 2024 08:03:34 -0700 Subject: [PATCH] Fix ruff F findings --- bindings/python/broker/__init__.py | 10 ---------- ruff.toml | 2 +- tests/btest/scripts/wire_format.py | 1 + tests/python/communication.py | 6 ++---- tests/python/data.py | 3 +-- tests/python/forwarding.py | 3 --- tests/python/ssl-tests.py | 3 --- tests/python/store.py | 14 +++++++------- tests/python/zeek-unsafe-types.py | 6 ++++-- tests/python/zeek.py | 2 +- 10 files changed, 17 insertions(+), 33 deletions(-) diff --git a/bindings/python/broker/__init__.py b/bindings/python/broker/__init__.py index b9ea1f1e..c90cc24f 100644 --- a/bindings/python/broker/__init__.py +++ b/bindings/python/broker/__init__.py @@ -6,8 +6,6 @@ import collections import datetime import ipaddress -import sys -import time import types try: @@ -308,14 +306,6 @@ def __exit__(self, type, value, traceback): self._parent = None self._store = None - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - self._store.reset() - self._parent = None - self._store = None - def name(self): return self._store.name() diff --git a/ruff.toml b/ruff.toml index b7cb6e5e..ce24954b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -11,4 +11,4 @@ exclude = ["auxil", "tests/btest//store"] [lint] -select = ["C4", "I", "ISC", "UP"] \ No newline at end of file +select = ["C4", "F", "I", "ISC", "UP"] \ No newline at end of file diff --git a/tests/btest/scripts/wire_format.py b/tests/btest/scripts/wire_format.py index 711de711..4085458b 100644 --- a/tests/btest/scripts/wire_format.py +++ b/tests/btest/scripts/wire_format.py @@ -2,6 +2,7 @@ import struct import sys import time +import traceback import uuid from collections import namedtuple from enum import IntEnum diff --git a/tests/python/communication.py b/tests/python/communication.py index 9b6decce..1c7d861a 100644 --- a/tests/python/communication.py +++ b/tests/python/communication.py @@ -1,6 +1,4 @@ import ipaddress -import multiprocessing -import sys import time import unittest @@ -184,8 +182,8 @@ def test_status_subscriber_error(self): def test_idle_endpoint(self): with ( broker.Endpoint() as ep1, - ep1.make_status_subscriber() as es1, - ep1.make_subscriber("/test") as s1, + ep1.make_status_subscriber() as es1, # noqa: F841 + ep1.make_subscriber("/test") as s1, # noqa: F841 ): pass diff --git a/tests/python/data.py b/tests/python/data.py index 51930e61..5225abab 100644 --- a/tests/python/data.py +++ b/tests/python/data.py @@ -7,7 +7,6 @@ import datetime import ipaddress import math -import sys import time import types import unittest @@ -117,7 +116,7 @@ def test_count(self): ) def test_count_overflow(self): - with self.assertRaises(Exception) as context: + with self.assertRaises(Exception) as context: # noqa: F841 # I've seen this raise either OverflowError or SystemError # depending on Python version is seems. self.check_to_broker(broker.Count(-1), "-1", broker.Data.Type.Count) diff --git a/tests/python/forwarding.py b/tests/python/forwarding.py index 6aa660b2..98ebc0a9 100644 --- a/tests/python/forwarding.py +++ b/tests/python/forwarding.py @@ -1,6 +1,3 @@ -import multiprocessing -import sys -import time import unittest import broker diff --git a/tests/python/ssl-tests.py b/tests/python/ssl-tests.py index eab8496f..96ccb687 100644 --- a/tests/python/ssl-tests.py +++ b/tests/python/ssl-tests.py @@ -1,7 +1,4 @@ -import multiprocessing import os.path -import sys -import time import unittest import broker diff --git a/tests/python/store.py b/tests/python/store.py index 80b0ae6e..98dddcaf 100644 --- a/tests/python/store.py +++ b/tests/python/store.py @@ -1,7 +1,5 @@ -import sys import time import unittest -from inspect import currentframe, getframeinfo import broker @@ -12,11 +10,11 @@ def create_stores(self): ep2 = broker.Endpoint() with ( - ep0.make_subscriber("/test") as s0, + ep0.make_subscriber("/test") as s0, # noqa: F841 ep1.make_subscriber("/test") as s1, - ep1.make_status_subscriber() as es1, + ep1.make_status_subscriber() as es1, # noqa: F841 ep2.make_subscriber("/test") as s2, - ep2.make_status_subscriber() as es2, + ep2.make_status_subscriber() as es2, # noqa: F841 ): p = ep0.listen("127.0.0.1", 0) ep1.peer("127.0.0.1", p) @@ -192,8 +190,10 @@ def test_from_one_clone(self): v1 = "A" v2 = {"A", "B", "C"} - v3 = {1: "A", 2: "B", 3: "C"} - v4 = ("A", "B", "C") + + # TODO: These are untested, should they be? + # v3 = {1: "A", 2: "B", 3: "C"} + # v4 = ("A", "B", "C") c1.put("a", v1) c1.put("b", v2) diff --git a/tests/python/zeek-unsafe-types.py b/tests/python/zeek-unsafe-types.py index 9dca6951..551d6c5b 100644 --- a/tests/python/zeek-unsafe-types.py +++ b/tests/python/zeek-unsafe-types.py @@ -2,7 +2,7 @@ import unittest import broker -from zeek_common import run_zeek, run_zeek_path +from zeek_common import run_zeek ZeekHello = """ redef Broker::default_connect_retry=1secs; @@ -79,7 +79,9 @@ def test_safe(self): # broker.zeek.SafeEvent uses broker.ImmutableData, so can access # the arguments safely: ev = broker.zeek.SafeEvent(msg) - args = ev.args() + + # TODO: should this test inspect the args somehow? + args = ev.args() # noqa: F841 if __name__ == "__main__": diff --git a/tests/python/zeek.py b/tests/python/zeek.py index 642da465..5480235e 100644 --- a/tests/python/zeek.py +++ b/tests/python/zeek.py @@ -3,7 +3,7 @@ from datetime import datetime import broker -from zeek_common import run_zeek, run_zeek_path +from zeek_common import run_zeek ZeekPing = """ redef Broker::default_connect_retry=1secs;