diff --git a/src/benchmark/executions.py b/src/benchmark/executions.py index 681e6c78..262daba2 100644 --- a/src/benchmark/executions.py +++ b/src/benchmark/executions.py @@ -27,7 +27,7 @@ def instrument_func(x): return x - def instrument_all(): + def instrument_all() -> None: pass @contextlib.contextmanager diff --git a/src/coverage_g3test.py b/src/coverage_g3test.py index 50d6af1d..d605d937 100644 --- a/src/coverage_g3test.py +++ b/src/coverage_g3test.py @@ -132,14 +132,14 @@ class StrProperties: # Verifying that no tracing happens since startswith is a property @atheris.instrument_func -def property_starts_with(): +def property_starts_with() -> None: fake_str = StrProperties() fake_str.startswith = None # Verifying that no patching happens since endswith is a property @atheris.instrument_func -def property_ends_with(): +def property_ends_with() -> None: fake_str = StrProperties() fake_str.endswith = None diff --git a/src/coverage_test_helper.py b/src/coverage_test_helper.py index fd7b8964..174543ac 100644 --- a/src/coverage_test_helper.py +++ b/src/coverage_test_helper.py @@ -102,12 +102,12 @@ class StrProperties: # Verifying that no tracing happens since startswith is a property -def property_starts_with(): +def property_starts_with() -> None: fake_str = StrProperties() fake_str.startswith = None # Verifying that no patching happens since endswith is a property -def property_ends_with(): +def property_ends_with() -> None: fake_str = StrProperties() fake_str.endswith = None diff --git a/src/custom_crossover_fuzz_test.py b/src/custom_crossover_fuzz_test.py index 780e6611..0ed0d6ee 100644 --- a/src/custom_crossover_fuzz_test.py +++ b/src/custom_crossover_fuzz_test.py @@ -42,7 +42,7 @@ def bytes_comparison(data): class CustomCrossoverTests(unittest.TestCase): - def testBytesComparison(self): + def testBytesComparison(self) -> None: fuzz_test_lib.run_fuzztest( bytes_comparison, setup_kwargs={ @@ -51,7 +51,7 @@ def testBytesComparison(self): expected_output=b"Was a|b|c|d|e", timeout=30) - def testNoOpCrossover(self): + def testNoOpCrossover(self) -> None: fuzz_test_lib.run_fuzztest( bytes_comparison, setup_kwargs={ diff --git a/src/custom_mutator_and_crossover_fuzz_test.py b/src/custom_mutator_and_crossover_fuzz_test.py index b9f5cacc..50336a33 100644 --- a/src/custom_mutator_and_crossover_fuzz_test.py +++ b/src/custom_mutator_and_crossover_fuzz_test.py @@ -41,7 +41,7 @@ def test_one_input(data): class CustomMutatorAndCrossoverTests(unittest.TestCase): - def testMutator(self): + def testMutator(self) -> None: fuzz_test_lib.run_fuzztest( test_one_input, setup_kwargs={ @@ -50,7 +50,7 @@ def testMutator(self): }, expected_output=b"Hello from mutator") - def testCrossover(self): + def testCrossover(self) -> None: fuzz_test_lib.run_fuzztest( test_one_input, setup_kwargs={ diff --git a/src/custom_mutator_fuzz_test.py b/src/custom_mutator_fuzz_test.py index eeab9c07..8e59ea5e 100644 --- a/src/custom_mutator_fuzz_test.py +++ b/src/custom_mutator_fuzz_test.py @@ -51,7 +51,7 @@ def compressed_data(data): class CustomMutatorTests(unittest.TestCase): - def testCompressedData(self): + def testCompressedData(self) -> None: fuzz_test_lib.run_fuzztest( compressed_data, setup_kwargs={"custom_mutator": compressed_mutator}, diff --git a/src/fuzz_test.py b/src/fuzz_test.py index 85621b6b..ba9f1cb3 100644 --- a/src/fuzz_test.py +++ b/src/fuzz_test.py @@ -224,34 +224,34 @@ def runtime_instrument_code(data): class IntegrationTests(unittest.TestCase): - def testFails(self): + def testFails(self) -> None: fuzz_test_lib.run_fuzztest( fail_immediately, expected_output=b"Failed immediately") - def testManyBranches(self): + def testManyBranches(self) -> None: fuzz_test_lib.run_fuzztest( many_branches, expected_output=b"Many branches", timeout=90) - def testBytesComparison(self): + def testBytesComparison(self) -> None: fuzz_test_lib.run_fuzztest( bytes_comparison, expected_output=b"Was foobarbazbiz", timeout=30) - def testStringComparison(self): + def testStringComparison(self) -> None: fuzz_test_lib.run_fuzztest( string_comparison, expected_output=b"Was foobarbazbiz", timeout=30) - def testUtf8Comparison(self): + def testUtf8Comparison(self) -> None: fuzz_test_lib.run_fuzztest( utf8_comparison, expected_output=b"Was random unicode", timeout=60) - def testNestedUtf8Comparison(self): + def testNestedUtf8Comparison(self) -> None: fuzz_test_lib.run_fuzztest( nested_utf8_comparison, expected_output=b"Was hello", timeout=60, ) - def testTimeoutPy(self): + def testTimeoutPy(self) -> None: """This test verifies that timeout messages are recorded from -timeout.""" fuzz_test_lib.run_fuzztest( timeout_py, @@ -262,13 +262,13 @@ def testTimeoutPy(self): args=["-timeout=1"], expected_output=b"ERROR: libFuzzer: timeout after") - def testRegExMatch(self): + def testRegExMatch(self) -> None: fuzz_test_lib.run_fuzztest( regex_match, expected_output=b"Was RegEx Match", enabled_hooks=["RegEx"]) - def testStrStartswith(self): + def testStrStartswith(self) -> None: fuzz_test_lib.run_fuzztest( str_startswith, expected_output=b"Started with foobar", @@ -276,7 +276,7 @@ def testStrStartswith(self): timeout=60, ) - def testStrEndswith(self): + def testStrEndswith(self) -> None: fuzz_test_lib.run_fuzztest( str_endswith, expected_output=b"Ended with bazbiz", @@ -284,7 +284,7 @@ def testStrEndswith(self): timeout=60, ) - def testStrMethodsCombined(self): + def testStrMethodsCombined(self) -> None: fuzz_test_lib.run_fuzztest( str_methods_combined, expected_output=b"Started with foo and ended with bar", @@ -292,7 +292,7 @@ def testStrMethodsCombined(self): timeout=60, ) - def testStrStartswithTuplePrefix(self): + def testStrStartswithTuplePrefix(self) -> None: fuzz_test_lib.run_fuzztest( str_startswith_tuple_prefix, expected_output=b"Started with oneof (foobar, hellohi, supyo)", @@ -300,7 +300,7 @@ def testStrStartswithTuplePrefix(self): timeout=60, ) - def testStrEndswithTupleSuffix(self): + def testStrEndswithTupleSuffix(self) -> None: fuzz_test_lib.run_fuzztest( str_endswith_tuple_suffix, expected_output=b"Ended with oneof (bazbiz, byebye, cyalater)", @@ -308,7 +308,7 @@ def testStrEndswithTupleSuffix(self): timeout=60, ) - def testStrStartswithStartEndArgs(self): + def testStrStartswithStartEndArgs(self) -> None: fuzz_test_lib.run_fuzztest( str_startswith_with_start_and_end, expected_output=b"Started with hellohi at index 10", @@ -316,7 +316,7 @@ def testStrStartswithStartEndArgs(self): timeout=60, ) - def testStrEndswithStartEndArgs(self): + def testStrEndswithStartEndArgs(self) -> None: fuzz_test_lib.run_fuzztest( str_endswith_with_start_and_end, expected_output=b"Ended with supyo at end index 15", @@ -324,39 +324,39 @@ def testStrEndswithStartEndArgs(self): timeout=60, ) - def testExitsGracefullyOnPyFail(self): + def testExitsGracefullyOnPyFail(self) -> None: fuzz_test_lib.run_fuzztest( fail_immediately, expected_output=b"Exiting gracefully.") - def testExitsGracefullyOnRunsOut(self): + def testExitsGracefullyOnRunsOut(self) -> None: fuzz_test_lib.run_fuzztest( never_fail, args=["-atheris_runs=2"], expected_output=b"Exiting gracefully.") - def testExceptionWithSurrogates(self): + def testExceptionWithSurrogates(self) -> None: fuzz_test_lib.run_fuzztest( raise_with_surrogates, args=["-atheris_runs=1"], expected_output=b"abc \\ud927 def") - def testRunsOutCount(self): + def testRunsOutCount(self) -> None: fuzz_test_lib.run_fuzztest( never_fail, args=["-atheris_runs=3"], expected_output=b"Done 3 in ") - def testCompressedDataWithoutCustomMutator(self): + def testCompressedDataWithoutCustomMutator(self) -> None: try: fuzz_test_lib.run_fuzztest(compressed_data) except TimeoutError: # Expected to timeout without a custom mutator. pass - def testReserveCounterAfterFuzzStart(self): + def testReserveCounterAfterFuzzStart(self) -> None: fuzz_test_lib.run_fuzztest( reserve_counter_after_fuzz_start, args=["-atheris_runs=2"], expected_output=b"Exiting gracefully.") - def testInstrumentCodeWhileFuzzing(self): + def testInstrumentCodeWhileFuzzing(self) -> None: fuzz_test_lib.run_fuzztest( runtime_instrument_code, timeout=90, diff --git a/src/fuzzed_data_provider_test.py b/src/fuzzed_data_provider_test.py index 722df76b..a4f504d4 100644 --- a/src/fuzzed_data_provider_test.py +++ b/src/fuzzed_data_provider_test.py @@ -50,14 +50,14 @@ def to_bytes(n, length): class FuzzedDataProviderTest(unittest.TestCase): - def testUnicodeActuallyAscii(self): + def testUnicodeActuallyAscii(self) -> None: fdp = atheris.FuzzedDataProvider(ASCII_BYTEMARK + b"abc123\0\x7f" + BYTE_ORDER_LITTLE_ENDIAN + b"\xd1") expected = "abc123\0\x7f\x7f\x7e\x51" actual = fdp.ConsumeUnicode(atheris.ALL_REMAINING) self.assertEqual(expected, actual) - def testUnicode16(self): + def testUnicode16(self) -> None: fdp = atheris.FuzzedDataProvider(UTF16_BYTEMARK + b"abc123\0\x7f" + HIGH_SURROGATE + LOW_SURROGATE + b"\xd1") @@ -68,7 +68,7 @@ def testUnicode16(self): actual = fdp.ConsumeUnicode(atheris.ALL_REMAINING) self.assertEqual(expected, actual) - def testUnicode16NoSurrogate(self): + def testUnicode16NoSurrogate(self) -> None: fdp = atheris.FuzzedDataProvider(UTF16_BYTEMARK + b"abc123\0\x7f" + HIGH_SURROGATE + LOW_SURROGATE + b"\xd1") @@ -82,7 +82,7 @@ def testUnicode16NoSurrogate(self): actual = fdp.ConsumeUnicodeNoSurrogates(atheris.ALL_REMAINING) self.assertEqual(expected, actual) - def testUnicode32(self): + def testUnicode32(self) -> None: fdp = atheris.FuzzedDataProvider(UTF32_BYTEMARK + b"dc\x0e\0" + b"4321" + HIGH_SURROGATE + b"\0\0" + LOW_SURROGATE + b"\0\0" + b"\xd1") @@ -100,7 +100,7 @@ def testUnicode32(self): self.assertEqual(len(expected), len(actual)) self.assertEqual(expected, actual) - def testUnicode32NoSurrogate(self): + def testUnicode32NoSurrogate(self) -> None: fdp = atheris.FuzzedDataProvider(UTF32_BYTEMARK + b"dc\x0e\0" + b"4321" + HIGH_SURROGATE + b"\0\0" + LOW_SURROGATE + b"\0\0" + b"\xd1") @@ -118,13 +118,13 @@ def testUnicode32NoSurrogate(self): self.assertEqual(len(expected), len(actual)) self.assertEqual(expected, actual) - def testBytes(self): + def testBytes(self) -> None: expected = b"abc123\0\0xff\0x7f\0x80" fdp = atheris.FuzzedDataProvider(expected) self.assertEqual(expected, fdp.ConsumeBytes(atheris.ALL_REMAINING)) - def testString(self): + def testString(self) -> None: if sys.version_info[0] >= 3: fdp = atheris.FuzzedDataProvider(ASCII_BYTEMARK + b"abc" + ASCII_BYTEMARK + b"123") @@ -135,80 +135,80 @@ def testString(self): self.assertEqual("abc", fdp.ConsumeString(3)) self.assertEqual("123", fdp.ConsumeString(atheris.ALL_REMAINING)) - def testInt1(self): + def testInt1(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(1), 0x01) - def testUInt1(self): + def testUInt1(self) -> None: fdp = atheris.FuzzedDataProvider(b"\xe1\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeUInt(1), 0xe1) - def testNegInt1(self): + def testNegInt1(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x81\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(1), 0x81 - 0x100) - def testInt2(self): + def testInt2(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(2), 0x0201) - def testUInt2(self): + def testUInt2(self) -> None: fdp = atheris.FuzzedDataProvider(b"\xa1\xe2\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeUInt(2), 0xe2a1) - def testNegInt2(self): + def testNegInt2(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x10\x82\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(2), 0x8210 - 0x10000) - def testInt3(self): + def testInt3(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(3), 0x030201) - def testUInt3(self): + def testUInt3(self) -> None: fdp = atheris.FuzzedDataProvider(b"\xa1\xb2\xc3\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeUInt(3), 0xc3b2a1) - def testNegInt3(self): + def testNegInt3(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\xd3\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(3), 0xd30201 - 0x1000000) - def testInt4(self): + def testInt4(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(4), 0x4030201) - def testUInt4(self): + def testUInt4(self) -> None: fdp = atheris.FuzzedDataProvider(b"\xa1\xb2\xc3\xd4\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeUInt(4), 0xd4c3b2a1) - def testNegInt4(self): + def testNegInt4(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\xe4\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(4), 0xe4030201 - 0x100000000) - def testInt8(self): + def testInt8(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\x08") self.assertEqual(fdp.ConsumeInt(8), 0x0807060504030201) - def testNegInt8(self): + def testNegInt8(self) -> None: fdp = atheris.FuzzedDataProvider(b"\x01\x02\x03\x04\x05\x06\x07\xb8") self.assertEqual( fdp.ConsumeInt(8), 0xb807060504030201 - 0x10000000000000000) - def testInt9(self): + def testInt9(self) -> None: fdp = atheris.FuzzedDataProvider( b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a") self.assertEqual(fdp.ConsumeInt(9), 0x090807060504030201) - def testNegInt9(self): + def testNegInt9(self) -> None: fdp = atheris.FuzzedDataProvider( b"\x01\x02\x03\x04\x05\x06\x07\x08\xe9\x0a") self.assertEqual( fdp.ConsumeInt(9), 0xe90807060504030201 - 0x1000000000000000000) - def testUInt9(self): + def testUInt9(self) -> None: fdp = atheris.FuzzedDataProvider( b"\xa1\xb2\xc3\xd4\xe5\xf6\xa7\xb8\xc9\xda") self.assertEqual(fdp.ConsumeUInt(9), 0xc9b8a7f6e5d4c3b2a1) - def testInRange1(self): + def testInRange1(self) -> None: arr = b"" for _ in range(0, 1000): arr += to_bytes(random.randint(0, 255), 1) @@ -226,7 +226,7 @@ def testInRange1(self): self.assertGreaterEqual(result, two) self.assertLessEqual(result, one) - def testInRange9(self): + def testInRange9(self) -> None: arr = b"" for _ in range(0, 1000): arr += to_bytes(random.randint(0, 255), 1) @@ -244,7 +244,7 @@ def testInRange9(self): self.assertGreaterEqual(result, two) self.assertLessEqual(result, one) - def testIntList1(self): + def testIntList1(self) -> None: arr = bytearray() for _ in range(0, 1000): arr += to_bytes(random.randint(0, 255), 1) @@ -265,7 +265,7 @@ def testIntList1(self): for i in range(1000, 4321): self.assertEqual(l[i], 0) - def testIntList9(self): + def testIntList9(self) -> None: arr = b"" for _ in range(0, 1000): arr += to_bytes(random.randint(0, 2**72 - 1), 9) @@ -281,7 +281,7 @@ def testIntList9(self): for i in range(1000, 4321): self.assertEqual(l[i], 0) - def testNonInfiniteFloat(self): + def testNonInfiniteFloat(self) -> None: arr = [] arr.append(50) arr.append(152) @@ -300,7 +300,7 @@ def testNonInfiniteFloat(self): self.assertGreaterEqual(val, -1.7976931348623157e+308) self.assertLessEqual(val, 1.7976931348623157e+308) - def testFloatList(self): + def testFloatList(self) -> None: arr = b"" for i in range(0, 256): arr += to_bytes(i, 1) @@ -354,7 +354,7 @@ def testFloatList(self): self.assertGreater(val, -1.79769313e+308) self.assertLess(val, 1.79769313e+308) - def testPickValueInList1(self): + def testPickValueInList1(self) -> None: l = [3, 3] # noqa: E741 arr = to_bytes(random.getrandbits(1024), int(1024 / 8)) @@ -367,7 +367,7 @@ def testPickValueInList1(self): self.assertEqual(fdp.PickValueInList(l), 3) - def testPickValueInList7(self): + def testPickValueInList7(self) -> None: l = [4, 17, 52, 12, 8, 71, 2] # noqa: E741 s = set() @@ -380,7 +380,7 @@ def testPickValueInList7(self): self.assertEqual(s, set(l)) self.assertEqual(fdp.PickValueInList(l), 4) - def testPickValueInListShort(self): + def testPickValueInListShort(self) -> None: l = [] # noqa: E741 for i in range(1, 10001): l.append(i * 13) diff --git a/src/import_hook.py b/src/import_hook.py index 24f3a247..c7db8c64 100644 --- a/src/import_hook.py +++ b/src/import_hook.py @@ -58,7 +58,7 @@ class AtherisMetaPathFinder(abc.MetaPathFinder): """Finds and loads package metapaths with Atheris loaders.""" def __init__(self, include_packages: Set[str], exclude_modules: Set[str], - enable_loader_override: bool, trace_dataflow: bool): + enable_loader_override: bool, trace_dataflow: bool) -> None: """Finds and loads package metapaths with Atheris loaders. Args: @@ -200,7 +200,7 @@ class AtherisSourcelessFileLoader( _frozen_importlib_external.SourcelessFileLoader): """Loads a sourceless/bytecode file, patching it with Atheris instrumentation.""" - def __init__(self, name: str, path: str, trace_dataflow: bool): + def __init__(self, name: str, path: str, trace_dataflow: bool) -> None: super().__init__(name, path) self._trace_dataflow = trace_dataflow @@ -269,7 +269,7 @@ class HookManager: """A Context manager that manages hooks.""" def __init__(self, include_packages: Set[str], exclude_modules: Set[str], - enable_loader_override: bool, trace_dataflow: bool): + enable_loader_override: bool, trace_dataflow: bool) -> None: self._include_packages = include_packages self._exclude_modules = exclude_modules self._enable_loader_override = enable_loader_override diff --git a/src/instrument_bytecode.py b/src/instrument_bytecode.py index b252588a..ccfdfc50 100644 --- a/src/instrument_bytecode.py +++ b/src/instrument_bytecode.py @@ -268,7 +268,7 @@ def cache_count(self) -> int: class BasicBlock: """A block of bytecode instructions and the adresses it may jump to.""" - def __init__(self, instructions: List[Instruction], last_one: bool): + def __init__(self, instructions: List[Instruction], last_one: bool) -> None: self.instructions = instructions self.id = instructions[0].offset @@ -317,7 +317,7 @@ class Instrumentor: Note that Instrumentor only supports insertions, not deletions. """ - def __init__(self, code: types.CodeType): + def __init__(self, code: types.CodeType) -> None: self._cfg: collections.OrderedDict = collections.OrderedDict() self.consts = list(code.co_consts) self._names = list(code.co_names) diff --git a/src/pyinstaller_coverage_test.py b/src/pyinstaller_coverage_test.py index cd1a6e89..5838e6a8 100644 --- a/src/pyinstaller_coverage_test.py +++ b/src/pyinstaller_coverage_test.py @@ -22,7 +22,7 @@ class PyInstallerCoverageTest(unittest.TestCase): - def test_build_and_run(self): + def test_build_and_run(self) -> None: coverage_test = os.path.join( os.path.dirname(os.path.realpath(__file__)), "coverage_test.py") subprocess.check_call([ diff --git a/src/regex_match_generation_test.py b/src/regex_match_generation_test.py index 5ae456b6..4e09175f 100644 --- a/src/regex_match_generation_test.py +++ b/src/regex_match_generation_test.py @@ -20,44 +20,44 @@ class RegexMatchGeneration(unittest.TestCase): - def test_plain(self): + def test_plain(self) -> None: match = gen_match("abc") self.assertEqual(match, "abc") - def test_alternate1(self): + def test_alternate1(self) -> None: match = gen_match("abc|def") self.assertIn(match, ["abc", "def"]) - def test_alternate2(self): + def test_alternate2(self) -> None: pattern = r"(abc|\d+)" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_oneof(self): + def test_oneof(self) -> None: match = gen_match("[abc]abc") self.assertIn(match, ["aabc", "babc", "cabc"]) - def test_repeat_star(self): + def test_repeat_star(self) -> None: pattern = "abc*d" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_non_greedy_repeat_star(self): + def test_non_greedy_repeat_star(self) -> None: pattern = "abc*?d" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_repeat_plus(self): + def test_repeat_plus(self) -> None: pattern = "abc+d" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_non_greedy_repeat_plus(self): + def test_non_greedy_repeat_plus(self) -> None: pattern = "abc+?d" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_notoneof(self): + def test_notoneof(self) -> None: match = gen_match("[^abc]def") if len(match) != 4: raise AssertionError(f"Unexpected generated match {match}") @@ -66,116 +66,116 @@ def test_notoneof(self): if match[0] in "abc": raise AssertionError(f"Unexpected generated match {match}") - def test_noncapturing(self): + def test_noncapturing(self) -> None: pattern = r"(?:abc){3,}" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_noncapturing2(self): + def test_noncapturing2(self) -> None: pattern = r"(?:abc){,3}" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_lookahead_at_end(self): + def test_lookahead_at_end(self) -> None: pattern = r"a(?=bc)" match = gen_match(pattern) self.assertRegex(match, pattern) self.assertEqual(match, "abc") - def test_lookbehind_at_beginning(self): + def test_lookbehind_at_beginning(self) -> None: pattern = r"(?<=a)bc" match = gen_match(pattern) self.assertRegex(match, pattern) self.assertEqual(match, "abc") - def test_ignores_lookahead_in_middle(self): + def test_ignores_lookahead_in_middle(self) -> None: pattern = r"xy(?=a)z" match = gen_match(pattern) self.assertEqual(match, "xyz") - def test_ignores_lookbehind_in_middle(self): + def test_ignores_lookbehind_in_middle(self) -> None: pattern = r"xy(?<=a)z" match = gen_match(pattern) self.assertEqual(match, "xyz") - def test_ignores_negative_lookahead_in_middle(self): + def test_ignores_negative_lookahead_in_middle(self) -> None: pattern = r"xy(?!z)z" match = gen_match(pattern) self.assertEqual(match, "xyz") - def test_ignores_negative_lookbehind_in_middle(self): + def test_ignores_negative_lookbehind_in_middle(self) -> None: pattern = r"xy(? None: match = gen_match("•") self.assertEqual(match, "•") - def test_plain_bytes(self): + def test_plain_bytes(self) -> None: match = gen_match(b"abc") self.assertEqual(match, b"abc") - def test_non_ascii_non_utf8_bytes(self): + def test_non_ascii_non_utf8_bytes(self) -> None: pattern = b"ab*c\x80\x80de*f" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_utf8(self): + def test_utf8(self) -> None: match = gen_match("•".encode("utf-8")) self.assertEqual(match, b"\xe2\x80\xa2") - def test_digits(self): + def test_digits(self) -> None: pattern = r"\d" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_not_digits(self): + def test_not_digits(self) -> None: pattern = r"\D" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_word(self): + def test_word(self) -> None: pattern = r"\w" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_not_word(self): + def test_not_word(self) -> None: pattern = r"\W" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_space(self): + def test_space(self) -> None: pattern = r"\s" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_not_space(self): + def test_not_space(self) -> None: pattern = r"\S" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_wildcard(self): + def test_wildcard(self) -> None: pattern = r"a.bc" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_range_with_fixed_chars(self): + def test_range_with_fixed_chars(self) -> None: pattern = r"[a-z1]bc" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_range(self): + def test_range(self) -> None: pattern = r"[a-z]bc" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_negative_range(self): + def test_negative_range(self) -> None: pattern = r"[^a-z]bc" match = gen_match(pattern) self.assertRegex(match, pattern) - def test_negative_range_with_fixed_chars(self): + def test_negative_range_with_fixed_chars(self) -> None: pattern = r"[^a-z\\]bc" match = gen_match(pattern) self.assertRegex(match, pattern) diff --git a/src/utils.py b/src/utils.py index df185fed..17740fdf 100644 --- a/src/utils.py +++ b/src/utils.py @@ -17,7 +17,7 @@ import os -def path(): +def path() -> str: dir, _ = os.path.split(sys.modules["atheris"].__file__) dir, _ = os.path.split(dir) return dir @@ -26,7 +26,7 @@ def path(): class ProgressRenderer: """Displays an updating progress meter in the terminal.""" - def __init__(self, stream, total_count): + def __init__(self, stream, total_count: int): assert stream.isatty() self.stream = stream @@ -36,7 +36,7 @@ def __init__(self, stream, total_count): self._current_width = 0 self.render() - def render(self): + def render(self) -> None: self.erase() done_percent = int(100 * self._count / self.total_count) message = f"[{self._count}/{self.total_count}] {done_percent}%" @@ -44,22 +44,22 @@ def render(self): self.stream.flush() self._current_width = len(message) - def erase(self): + def erase(self) -> None: self.stream.write(("\b" * self._current_width) + (" " * self._current_width) + ("\b" * self._current_width)) self.stream.flush() self._current_width = 0 - def drop(self): + def drop(self) -> None: self._current_width = 0 sys.stderr.write("\n") @property - def count(self): + def count(self) -> int: return self._count @count.setter - def count(self, new_count): + def count(self, new_count: int) -> None: self._count = new_count self.render() diff --git a/src/version_dependent.py b/src/version_dependent.py index ac9ae14f..3616166f 100644 --- a/src/version_dependent.py +++ b/src/version_dependent.py @@ -149,7 +149,7 @@ # Returns -1 for instructions that have backward relative references # (e.g. JUMP_BACKWARD, an instruction that uses a positive number to # indicate a negative jump) -def rel_reference_scale(opname): +def rel_reference_scale(opname: str) -> int: assert opname in HAVE_REL_REFERENCE if opname in REL_REFERENCE_IS_INVERTED: return -1 @@ -345,12 +345,12 @@ def __init__(self, start_offset, end_offset, target, depth, lasti): self.depth = depth self.lasti = lasti - def __repr__(self): + def __repr__(self) -> str: return ( f"(start_offset={self.start_offset} end_offset={self.end_offset} target={self.target} depth={self.depth} lasti={self.lasti})" ) - def __str__(self): + def __str__(self) -> str: return self.__repr__() def __eq__(self, other): @@ -365,13 +365,13 @@ def __eq__(self, other): class ExceptionTable: - def __init__(self, entries: List[ExceptionTableEntry]): + def __init__(self, entries: List[ExceptionTableEntry]) -> None: self.entries = entries - def __repr__(self): + def __repr__(self) -> str: return "\n".join([repr(x) for x in self.entries]) - def __str__(self): + def __str__(self) -> str: return "\n".join([repr(x) for x in self.entries]) def __eq__(self, other):