From 470a83982b313942c8726bc317899737d506b23e Mon Sep 17 00:00:00 2001 From: a Date: Wed, 30 Aug 2023 08:29:20 -0400 Subject: [PATCH] Fix ruff findings. --- src/coverage_g3test.py | 2 -- src/coverage_test.py | 2 -- src/fuzzed_data_provider_test.py | 12 ++++++------ src/instrument_bytecode.py | 10 ---------- src/version_dependent.py | 4 ++-- 5 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/coverage_g3test.py b/src/coverage_g3test.py index d4d1aa43..50d6af1d 100644 --- a/src/coverage_g3test.py +++ b/src/coverage_g3test.py @@ -303,12 +303,10 @@ def testConstCompare(self, trace_branch_mock, trace_cmp_mock, self.assertTrue(cmp_const_less(2)) self.assertTraceCmpWas(trace_cmp_mock.call_args[0], 1, 2, "<", True) - first_cmp_idx = trace_cmp_mock.call_args[0][3] trace_cmp_mock.reset_mock() self.assertFalse(cmp_const_less_inverted(3)) self.assertTraceCmpWas(trace_cmp_mock.call_args[0], 1, 3, ">", True) - first_cmp_idx = trace_cmp_mock.call_args[0][3] trace_cmp_mock.reset_mock() def testInstrumentationAppliedOnce(self, trace_branch_mock, trace_cmp_mock, diff --git a/src/coverage_test.py b/src/coverage_test.py index d150d8cd..5dc983a6 100644 --- a/src/coverage_test.py +++ b/src/coverage_test.py @@ -211,12 +211,10 @@ def testConstCompare(self, trace_branch_mock, trace_cmp_mock, self.assertTrue(coverage_test_helper.cmp_const_less(2)) self.assertTraceCmpWas(trace_cmp_mock.call_args[0], 1, 2, "<", True) - first_cmp_idx = trace_cmp_mock.call_args[0][3] trace_cmp_mock.reset_mock() self.assertFalse(coverage_test_helper.cmp_const_less_inverted(3)) self.assertTraceCmpWas(trace_cmp_mock.call_args[0], 1, 3, ">", True) - first_cmp_idx = trace_cmp_mock.call_args[0][3] trace_cmp_mock.reset_mock() def testInstrumentationAppliedOnce(self, trace_branch_mock, trace_cmp_mock, diff --git a/src/fuzzed_data_provider_test.py b/src/fuzzed_data_provider_test.py index f37cef3f..b01409cc 100644 --- a/src/fuzzed_data_provider_test.py +++ b/src/fuzzed_data_provider_test.py @@ -29,7 +29,7 @@ def to_bytes(n, length): else: # functionality from python3's chr() function is called unichr() in python2 - codepoint = unichr + codepoint = unichr # noqa: F821 # functionality from python3's int.to_bytes() def to_bytes(n, length): @@ -250,7 +250,7 @@ def testIntList1(self): arr += to_bytes(random.randint(0, 255), 1) fdp = atheris.FuzzedDataProvider(arr) - l = fdp.ConsumeIntList(4321, 1) + l = fdp.ConsumeIntList(4321, 1) # noqa: E741 self.assertEqual(len(l), 4321) for i in range(0, 1000): if arr[i] < 0: @@ -271,7 +271,7 @@ def testIntList9(self): arr += to_bytes(random.randint(0, 2**72 - 1), 9) fdp = atheris.FuzzedDataProvider(arr) - l = fdp.ConsumeIntList(4321, 9) + l = fdp.ConsumeIntList(4321, 9) # noqa: E741 self.assertEqual(len(l), 4321) for i in range(0, 1000): @@ -355,7 +355,7 @@ def testFloatList(self): self.assertLess(val, 1.79769313e+308) def testPickValueInList1(self): - l = [3, 3] + l = [3, 3] # noqa: E741 arr = to_bytes(random.getrandbits(1024), int(1024 / 8)) arr = to_bytes(1234, 8) + arr @@ -368,7 +368,7 @@ def testPickValueInList1(self): self.assertEqual(fdp.PickValueInList(l), 3) def testPickValueInList7(self): - l = [4, 17, 52, 12, 8, 71, 2] + l = [4, 17, 52, 12, 8, 71, 2] # noqa: E741 s = set() arr = to_bytes(random.getrandbits(1024 * 1024), int(1024 * 1024 / 8)) @@ -381,7 +381,7 @@ def testPickValueInList7(self): self.assertEqual(fdp.PickValueInList(l), 4) def testPickValueInListShort(self): - l = [] + l = [] # noqa: E741 for i in range(1, 10001): l.append(i * 13) diff --git a/src/instrument_bytecode.py b/src/instrument_bytecode.py index 4ccefe67..b252588a 100644 --- a/src/instrument_bytecode.py +++ b/src/instrument_bytecode.py @@ -49,15 +49,6 @@ from .version_dependent import rel_reference_scale from .version_dependent import REVERSE_CMP_OP from .version_dependent import rot_n -from .version_dependent import call -from .version_dependent import cache_count -from .version_dependent import caches -from .version_dependent import get_instructions -from .version_dependent import generate_exceptiontable -from .version_dependent import parse_exceptiontable -from .version_dependent import ExceptionTableEntry -from .version_dependent import args_terminator -from .version_dependent import CALLABLE_STACK_ENTRIES from .version_dependent import UNCONDITIONAL_JUMPS _TARGET_MODULE = "atheris" @@ -786,7 +777,6 @@ def trace_control_flow(self) -> None: # Insert at the first point after a RESUME instruction first_real_instr = None first_real_instr_slot = None - previous_instructions = [] for i in range(len(self._cfg[0].instructions)): bb_instr = self._cfg[0].instructions[i] if bb_instr.mnemonic not in ("RESUME", "GEN_START"): diff --git a/src/version_dependent.py b/src/version_dependent.py index dae2cb5c..627c6e66 100644 --- a/src/version_dependent.py +++ b/src/version_dependent.py @@ -394,10 +394,10 @@ def parse_exceptiontable(code): if (3, 11) <= PYTHON_VERSION <= (3, 11): from .native import _generate_exceptiontable - def generate_exceptiontable(original_code, exception_table_entries): + def generate_exceptiontable(original_code, exception_table_entries): # noqa: F811 return _generate_exceptiontable(original_code, exception_table_entries) - def parse_exceptiontable(co_exceptiontable): + def parse_exceptiontable(co_exceptiontable): # noqa: F811 if isinstance(co_exceptiontable, types.CodeType): return parse_exceptiontable(co_exceptiontable.co_exceptiontable)