diff --git a/tests/codemods/test_base_codemod.py b/tests/codemods/test_base_codemod.py index d51fa7ab..65f2b590 100644 --- a/tests/codemods/test_base_codemod.py +++ b/tests/codemods/test_base_codemod.py @@ -26,7 +26,7 @@ def transform_module_impl(self, tree: cst.Module) -> cst.Module: class TestEmptyResults: - def run_and_assert(self, input_code, expexted_output): + def run_and_assert(self, input_code, expected_output): input_tree = cst.parse_module(input_code) command_instance = DoNothingCodemod( CodemodContext(), @@ -35,7 +35,7 @@ def run_and_assert(self, input_code, expexted_output): ) output_tree = command_instance.transform_module(input_tree) - assert output_tree.code == expexted_output + assert output_tree.code == expected_output def test_empty_results(self): input_code = """print('Hello World')""" diff --git a/tests/codemods/test_jwt_decode_verify.py b/tests/codemods/test_jwt_decode_verify.py index 80c45b9f..35dc1a1a 100644 --- a/tests/codemods/test_jwt_decode_verify.py +++ b/tests/codemods/test_jwt_decode_verify.py @@ -15,13 +15,13 @@ def test_import(self, tmpdir): jwt.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=False) var = "hello" """ - expexted_output = """import jwt + expected_output = """import jwt jwt.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=True) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_from_import(self, tmpdir): input_code = """from jwt import decode @@ -29,13 +29,13 @@ def test_from_import(self, tmpdir): decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=False) var = "hello" """ - expexted_output = """from jwt import decode + expected_output = """from jwt import decode decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=True) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_import_alias(self, tmpdir): input_code = """import jwt as _jwtmod @@ -43,13 +43,13 @@ def test_import_alias(self, tmpdir): _jwtmod.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=False) var = "hello" """ - expexted_output = """import jwt as _jwtmod + expected_output = """import jwt as _jwtmod _jwtmod.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], verify=True) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize( "input_args,expected_args", @@ -90,13 +90,13 @@ def test_verify_variations(self, tmpdir, input_args, expected_args): jwt.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], {input_args}) var = "hello" """ - expexted_output = f"""import jwt + expected_output = f"""import jwt jwt.decode(encoded_jwt, SECRET_KEY, algorithms=['HS256'], {expected_args}) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_multiline_formatting_verify_flag(self, tmpdir): input_code = """import jwt @@ -106,14 +106,14 @@ def test_multiline_formatting_verify_flag(self, tmpdir): ) var = "hello" """ - expexted_output = """import jwt + expected_output = """import jwt decoded_payload = jwt.decode( encoded_jwt, SECRET_KEY, algorithms=["HS256"], verify=True) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize("quote", ["'", '"']) def test_multiline_formatting_options(self, tmpdir, quote): @@ -125,7 +125,7 @@ def test_multiline_formatting_options(self, tmpdir, quote): ) var = "hello" """ - expexted_output = f"""import jwt + expected_output = f"""import jwt decoded_payload = jwt.decode( encoded_jwt, SECRET_KEY, algorithms=["HS256"], @@ -133,4 +133,4 @@ def test_multiline_formatting_options(self, tmpdir, quote): var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) diff --git a/tests/codemods/test_secure_random.py b/tests/codemods/test_secure_random.py index bf54e2ca..fc1d3d2d 100644 --- a/tests/codemods/test_secure_random.py +++ b/tests/codemods/test_secure_random.py @@ -15,13 +15,13 @@ def test_import_random(self, tmpdir): random.random() var = "hello" """ - expexted_output = """import secrets + expected_output = """import secrets secrets.SystemRandom().random() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_from_random(self, tmpdir): input_code = """from random import random @@ -29,12 +29,12 @@ def test_from_random(self, tmpdir): random() var = "hello" """ - expexted_output = """import secrets + expected_output = """import secrets secrets.SystemRandom().random() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_random_alias(self, tmpdir): input_code = """import random as alleatory @@ -42,15 +42,15 @@ def test_random_alias(self, tmpdir): alleatory.random() var = "hello" """ - expexted_output = """import secrets + expected_output = """import secrets secrets.SystemRandom().random() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize( - "input_code,expexted_output", + "input_code,expected_output", [ ( """import random @@ -78,8 +78,8 @@ def test_random_alias(self, tmpdir): ), ], ) - def test_random_randint(self, tmpdir, input_code, expexted_output): - self.run_and_assert(tmpdir, input_code, expexted_output) + def test_random_randint(self, tmpdir, input_code, expected_output): + self.run_and_assert(tmpdir, input_code, expected_output) def test_multiple_calls(self, tmpdir): input_code = """import random @@ -88,16 +88,16 @@ def test_multiple_calls(self, tmpdir): random.randint() var = "hello" """ - expexted_output = """import secrets + expected_output = """import secrets secrets.SystemRandom().random() secrets.SystemRandom().randint() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize( - "input_code,expexted_output", + "input_code,expected_output", [ ( """import random @@ -127,15 +127,15 @@ def test_multiple_calls(self, tmpdir): ), ], ) - def test_random_other_import_untouched(self, tmpdir, input_code, expexted_output): - self.run_and_assert(tmpdir, input_code, expexted_output) + def test_random_other_import_untouched(self, tmpdir, input_code, expected_output): + self.run_and_assert(tmpdir, input_code, expected_output) def test_random_nameerror(self, tmpdir): input_code = """random.random() import random""" - expexted_output = input_code - self.run_and_assert(tmpdir, input_code, expexted_output) + expected_output = input_code + self.run_and_assert(tmpdir, input_code, expected_output) def test_random_multifunctions(self, tmpdir): # Test that `random` import isn't removed if code uses part of the random @@ -147,11 +147,11 @@ def test_random_multifunctions(self, tmpdir): random.__all__ """ - expexted_output = """import random + expected_output = """import random import secrets secrets.SystemRandom().random() random.__all__ """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) diff --git a/tests/codemods/test_tempfile_mktemp.py b/tests/codemods/test_tempfile_mktemp.py index 99493fd6..06f8ce37 100644 --- a/tests/codemods/test_tempfile_mktemp.py +++ b/tests/codemods/test_tempfile_mktemp.py @@ -15,13 +15,13 @@ def test_import(self, tmpdir): tempfile.mktemp() var = "hello" """ - expexted_output = """import tempfile + expected_output = """import tempfile tempfile.mkstemp() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_import_with_arg(self, tmpdir): input_code = """import tempfile @@ -29,13 +29,13 @@ def test_import_with_arg(self, tmpdir): tempfile.mktemp('something') var = "hello" """ - expexted_output = """import tempfile + expected_output = """import tempfile tempfile.mkstemp('something') var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_from_import(self, tmpdir): input_code = """from tempfile import mktemp @@ -43,12 +43,12 @@ def test_from_import(self, tmpdir): mktemp() var = "hello" """ - expexted_output = """import tempfile + expected_output = """import tempfile tempfile.mkstemp() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.skip() def test_import_alias(self, tmpdir): @@ -57,12 +57,12 @@ def test_import_alias(self, tmpdir): _tempfile.mktemp() var = "hello" """ - expexted_output = """import tempfile as _tempfile + expected_output = """import tempfile as _tempfile _tempfile.mkstemp() var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_random_multifunctions(self, tmpdir): input_code = """from tempfile import mktemp, TemporaryFile @@ -71,7 +71,7 @@ def test_random_multifunctions(self, tmpdir): TemporaryFile() var = "hello" """ - expexted_output = """from tempfile import TemporaryFile + expected_output = """from tempfile import TemporaryFile import tempfile tempfile.mkstemp() @@ -79,4 +79,4 @@ def test_random_multifunctions(self, tmpdir): var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) diff --git a/tests/codemods/test_upgrade_sslcontext_minimum_version.py b/tests/codemods/test_upgrade_sslcontext_minimum_version.py index 4b7c747e..cb79c644 100644 --- a/tests/codemods/test_upgrade_sslcontext_minimum_version.py +++ b/tests/codemods/test_upgrade_sslcontext_minimum_version.py @@ -23,12 +23,12 @@ def test_upgrade_minimum_version(self, tmpdir, version): context = ssl.SSLContext() context.minimum_version = ssl.TLSVersion.{version} """ - expexted_output = """import ssl + expected_output = """import ssl context = ssl.SSLContext() context.minimum_version = ssl.TLSVersion.TLSv1_2 """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_upgrade_minimum_version_add_import(self, tmpdir): input_code = """from ssl import SSLContext, TLSVersion @@ -36,13 +36,13 @@ def test_upgrade_minimum_version_add_import(self, tmpdir): context = SSLContext() context.minimum_version = TLSVersion.TLSv1 """ - expexted_output = """from ssl import SSLContext + expected_output = """from ssl import SSLContext import ssl context = SSLContext() context.minimum_version = ssl.TLSVersion.TLSv1_2 """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_bad_maximum_dont_update(self, tmpdir): """ @@ -63,13 +63,13 @@ def test_import_with_alias(self, tmpdir): context = whatever.SSLContext() context.minimum_version = whatever.TLSVersion.SSLv3 """ - expexted_output = """import ssl as whatever + expected_output = """import ssl as whatever import ssl context = whatever.SSLContext() context.minimum_version = ssl.TLSVersion.TLSv1_2 """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_with_dataflow(self, tmpdir): input_code = """import ssl @@ -78,10 +78,10 @@ def test_with_dataflow(self, tmpdir): alias = context alias.minimum_version = ssl.TLSVersion.SSLv3 """ - expexted_output = """import ssl + expected_output = """import ssl context = ssl.SSLContext() alias = context alias.minimum_version = ssl.TLSVersion.TLSv1_2 """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) diff --git a/tests/codemods/test_upgrade_sslcontext_tls.py b/tests/codemods/test_upgrade_sslcontext_tls.py index 69005784..eec1c9a5 100644 --- a/tests/codemods/test_upgrade_sslcontext_tls.py +++ b/tests/codemods/test_upgrade_sslcontext_tls.py @@ -21,13 +21,13 @@ def test_upgrade_protocol_with_kwarg(self, tmpdir, protocol): context = ssl.SSLContext(protocol=ssl.{protocol}) var = "hello" """ - expexted_output = """import ssl + expected_output = """import ssl context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize("protocol", INSECURE_PROTOCOLS) def test_upgrade_protocol_without_kwarg(self, tmpdir, protocol): @@ -36,13 +36,13 @@ def test_upgrade_protocol_without_kwarg(self, tmpdir, protocol): context = ssl.SSLContext(ssl.{protocol}) var = "hello" """ - expexted_output = """import ssl + expected_output = """import ssl context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize("protocol", INSECURE_PROTOCOLS) def test_upgrade_protocol_outside_sslcontext_dont_update(self, tmpdir, protocol): @@ -50,9 +50,9 @@ def test_upgrade_protocol_outside_sslcontext_dont_update(self, tmpdir, protocol) foo(ssl.{protocol}) """ - expexted_output = input_code + expected_output = input_code - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize("protocol", INSECURE_PROTOCOLS) def test_upgrade_protocol_outside_call_dont_update(self, tmpdir, protocol): @@ -61,9 +61,9 @@ def test_upgrade_protocol_outside_call_dont_update(self, tmpdir, protocol): if x == ssl.{protocol}: print("whatever") """ - expexted_output = input_code + expected_output = input_code - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.skip("Need to add support for adding/rewriting imports") @pytest.mark.parametrize("protocol", INSECURE_PROTOCOLS) @@ -73,13 +73,13 @@ def test_upgrade_protocol_with_kwarg_direct_import(self, tmpdir, protocol): context = ssl.SSLContext({protocol}) var = "hello" """ - expexted_output = """from ssl import PROTOCOL_TLS_CLIENT + expected_output = """from ssl import PROTOCOL_TLS_CLIENT context = ssl.SSLContext(PROTOCOL_TLS_CLIENT) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) @pytest.mark.parametrize("protocol", INSECURE_PROTOCOLS) def test_upgrade_protocol_with_kwarg_import_alias(self, tmpdir, protocol): @@ -88,12 +88,12 @@ def test_upgrade_protocol_with_kwarg_import_alias(self, tmpdir, protocol): context = whatever.SSLContext(protocol=whatever.{protocol}) var = "hello" """ - expexted_output = """import ssl as whatever + expected_output = """import ssl as whatever context = whatever.SSLContext(protocol=whatever.PROTOCOL_TLS_CLIENT) var = "hello" """ - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_upgrade_protocol_with_inner_call_do_not_modify(self, tmpdir): input_code = """import ssl @@ -101,9 +101,9 @@ def test_upgrade_protocol_with_inner_call_do_not_modify(self, tmpdir): ssl.SSLContext(foo(ssl.PROTOCOL_SSLv2)) """ - expexted_output = input_code + expected_output = input_code - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output) def test_upgrade_protocol_in_expression_do_not_modify(self, tmpdir): input_code = """import ssl @@ -111,6 +111,6 @@ def test_upgrade_protocol_in_expression_do_not_modify(self, tmpdir): ssl.SSLContext(ssl.PROTOCOL_SSLv2 if condition else ssl.PROTOCOL_TLS_CLIENT) """ - expexted_output = input_code + expected_output = input_code - self.run_and_assert(tmpdir, input_code, expexted_output) + self.run_and_assert(tmpdir, input_code, expected_output)