From 58d0e284beed5ce2b25ecb3299cf6c4ec6db2de5 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Tue, 6 Feb 2024 08:32:00 -0300 Subject: [PATCH] remove line cont from lazy logging tests --- tests/codemods/test_lazy_logging.py | 706 ++++++++++++++-------------- 1 file changed, 353 insertions(+), 353 deletions(-) diff --git a/tests/codemods/test_lazy_logging.py b/tests/codemods/test_lazy_logging.py index 0ac78f71..b20815ca 100644 --- a/tests/codemods/test_lazy_logging.py +++ b/tests/codemods/test_lazy_logging.py @@ -17,38 +17,38 @@ def test_name(self): "input_code,expected_output", [ ( - """\ - import logging - e = "error" - logging.{}("Error occurred: %s" % e) - """, - """\ - import logging - e = "error" - logging.{}("Error occurred: %s", e) - """, + """ + import logging + e = "error" + logging.{}("Error occurred: %s" % e) + """, + """ + import logging + e = "error" + logging.{}("Error occurred: %s", e) + """, ), ( - """\ - import logging - logging.{}("Error occurred: %s" % ("one",)) - """, - """\ - import logging - logging.{}("Error occurred: %s", "one") - """, + """ + import logging + logging.{}("Error occurred: %s" % ("one",)) + """, + """ + import logging + logging.{}("Error occurred: %s", "one") + """, ), ( - """\ - import logging - log = logging.getLogger('anything') - log.{}("one: %s, two: %s" % ("one", "two")) - """, - """\ - import logging - log = logging.getLogger('anything') - log.{}("one: %s, two: %s", "one", "two") - """, + """ + import logging + log = logging.getLogger('anything') + log.{}("one: %s, two: %s" % ("one", "two")) + """, + """ + import logging + log = logging.getLogger('anything') + log.{}("one: %s, two: %s", "one", "two") + """, ), ], ) @@ -61,60 +61,60 @@ def test_import(self, tmpdir, input_code, expected_output, func): "input_code,expected_output", [ ( - """\ - import logging - e = "error" - logging.log(logging.ERROR, "Error occurred: %s" % e) - """, - """\ - import logging - e = "error" - logging.log(logging.ERROR, "Error occurred: %s", e) - """, + """ + import logging + e = "error" + logging.log(logging.ERROR, "Error occurred: %s" % e) + """, + """ + import logging + e = "error" + logging.log(logging.ERROR, "Error occurred: %s", e) + """, ), ( - """\ - import logging - logging.log(logging.ERROR, "Error occurred: %s" % ("one",)) - """, - """\ - import logging - logging.log(logging.ERROR, "Error occurred: %s", "one") - """, + """ + import logging + logging.log(logging.ERROR, "Error occurred: %s" % ("one",)) + """, + """ + import logging + logging.log(logging.ERROR, "Error occurred: %s", "one") + """, ), ( - """\ - import logging - log = logging.getLogger('anything') - log.log(logging.INFO, "one: %s, two: %s" % ("one", "two")) - """, - """\ - import logging - log = logging.getLogger('anything') - log.log(logging.INFO, "one: %s, two: %s", "one", "two") - """, + """ + import logging + log = logging.getLogger('anything') + log.log(logging.INFO, "one: %s, two: %s" % ("one", "two")) + """, + """ + import logging + log = logging.getLogger('anything') + log.log(logging.INFO, "one: %s, two: %s", "one", "two") + """, ), ( - """\ - from logging import log, INFO - e = "error" - log(INFO, "Error occurred: %s" % e) - """, - """\ - from logging import log, INFO - e = "error" - log(INFO, "Error occurred: %s", e) - """, + """ + from logging import log, INFO + e = "error" + log(INFO, "Error occurred: %s" % e) + """, + """ + from logging import log, INFO + e = "error" + log(INFO, "Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger, ERROR - getLogger('anything').log(ERROR, "one: %s, two: %s" % ("one", "two")) - """, - """\ - from logging import getLogger, ERROR - getLogger('anything').log(ERROR, "one: %s, two: %s", "one", "two") - """, + """ + from logging import getLogger, ERROR + getLogger('anything').log(ERROR, "one: %s, two: %s" % ("one", "two")) + """, + """ + from logging import getLogger, ERROR + getLogger('anything').log(ERROR, "one: %s, two: %s", "one", "two") + """, ), ], ) @@ -126,26 +126,26 @@ def test_log_func(self, tmpdir, input_code, expected_output): "input_code,expected_output", [ ( - """\ - from logging import {0} - e = "error" - {0}("Error occurred: %s" % e) - """, - """\ - from logging import {0} - e = "error" - {0}("Error occurred: %s", e) - """, + """ + from logging import {0} + e = "error" + {0}("Error occurred: %s" % e) + """, + """ + from logging import {0} + e = "error" + {0}("Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger - getLogger('anything').{}("one: %s, two: %s" % ("one", "two")) - """, - """\ - from logging import getLogger - getLogger('anything').{}("one: %s, two: %s", "one", "two") - """, + """ + from logging import getLogger + getLogger('anything').{}("one: %s, two: %s" % ("one", "two")) + """, + """ + from logging import getLogger + getLogger('anything').{}("one: %s, two: %s", "one", "two") + """, ), ], ) @@ -159,26 +159,26 @@ def test_from_import(self, tmpdir, input_code, expected_output, func): "input_code,expected_output", [ ( - """\ - from logging import {} as log_func - e = "error" - log_func("Error occurred: %s" % e) - """, - """\ - from logging import {} as log_func - e = "error" - log_func("Error occurred: %s", e) - """, + """ + from logging import {} as log_func + e = "error" + log_func("Error occurred: %s" % e) + """, + """ + from logging import {} as log_func + e = "error" + log_func("Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger as make_logger - make_logger('anything').{}("one: %s, two: %s" % ("one", "two")) - """, - """\ - from logging import getLogger as make_logger - make_logger('anything').{}("one: %s, two: %s", "one", "two") - """, + """ + from logging import getLogger as make_logger + make_logger('anything').{}("one: %s, two: %s" % ("one", "two")) + """, + """ + from logging import getLogger as make_logger + make_logger('anything').{}("one: %s, two: %s", "one", "two") + """, ), ], ) @@ -191,14 +191,14 @@ def test_import_alias(self, tmpdir, input_code, expected_output, func): "code", [ """ - import xyz - xyz.info("hi: %s" % 'hello') - """, + import xyz + xyz.info("hi: %s" % 'hello') + """, """ - import my_logging - log = my_logging.getLogger('anything') - log.info("hi: %s" % 'hello') - """, + import my_logging + log = my_logging.getLogger('anything') + log.info("hi: %s" % 'hello') + """, ], ) def test_different_log_func(self, tmpdir, code): @@ -206,14 +206,14 @@ def test_different_log_func(self, tmpdir, code): @pytest.mark.xfail(reason="Not currently supported") def test_log_as_arg(self, tmpdir): - input_code = """\ + input_code = """ import logging log = logging.getLogger('foo') def some_function(logger): logger.debug("hi: %s" % 'hello') some_function(log) """ - expected_code = """\ + expected_code = """ import logging log = logging.getLogger('foo') def some_function(logger): @@ -223,7 +223,7 @@ def some_function(logger): self.run_and_assert(tmpdir, input_code, expected_code) def test_log_format_specifiers(self, tmpdir): - input_code = """\ + input_code = """ import logging name = "Alice" age = 30 @@ -234,7 +234,7 @@ def test_log_format_specifiers(self, tmpdir): scientific_val = 1234.56789 logging.info("User Info - Name: %s, Age: %d, Height: %.2f, Balance: %.2f, ID (hex): %x, Number (octal): %o, Scientific Value: %.2e" % (name, age, height, balance, hex_id, octal_num, scientific_val)) """ - expected_code = """\ + expected_code = """ import logging name = "Alice" age = 30 @@ -248,11 +248,11 @@ def test_log_format_specifiers(self, tmpdir): self.run_and_assert(tmpdir, input_code, expected_code) def test_log_kwargs(self, tmpdir): - input_code = """\ + input_code = """ import logging logging.info("Name: %s" % "Alice", exc_info=True, extra={'custom_info': 'extra details'}, stacklevel=2) """ - expected_code = """\ + expected_code = """ import logging logging.info("Name: %s", "Alice", exc_info=True, extra={'custom_info': 'extra details'}, stacklevel=2) """ @@ -262,28 +262,28 @@ def test_log_kwargs(self, tmpdir): "input_code,expected_output", [ ( - """\ - import logging - var = b"three" - logging.info(b"one %s" % var) - """, - """\ - import logging - var = b"three" - logging.info(b"one %s", var) - """, + """ + import logging + var = b"three" + logging.info(b"one %s" % var) + """, + """ + import logging + var = b"three" + logging.info(b"one %s", var) + """, ), ( - """\ - import logging - four = r" four" - logging.info(r"two \\n%s" % four) - """, - """\ - import logging - four = r" four" - logging.info(r"two \\n%s", four) - """, + """ + import logging + four = r" four" + logging.info(r"two \\n%s" % four) + """, + """ + import logging + four = r" four" + logging.info(r"two \\n%s", four) + """, ), ], ) @@ -291,13 +291,13 @@ def test_log_prefix_types(self, tmpdir, input_code, expected_output): self.run_and_assert(tmpdir, input_code, expected_output) def test_var_assignments(self, tmpdir): - input_code = """\ + input_code = """ import logging msg = "something %s" e = "error" logging.info(msg % e) """ - expected_code = """\ + expected_code = """ import logging msg = "something %s" e = "error" @@ -308,15 +308,15 @@ def test_var_assignments(self, tmpdir): @pytest.mark.parametrize( "code", [ - """\ + """ import logging logging.info("something") """, - """\ + """ import logging logging.info("% something", "hi") """, - """\ + """ import logging logging.info("% something", "hi") """, @@ -334,42 +334,42 @@ class TestLazyLoggingPlus(BaseSemgrepCodemodTest): "input_code,expected_output", [ ( - """\ - import logging - e = "error" - logging.{}("Error occurred: " + e) - """, - """\ - import logging - e = "error" - logging.{}("Error occurred: %s", e) - """, + """ + import logging + e = "error" + logging.{}("Error occurred: " + e) + """, + """ + import logging + e = "error" + logging.{}("Error occurred: %s", e) + """, ), ( - """\ - import logging - num = 2 - logging.{}("Num:" + str(num)) - """, - """\ - import logging - num = 2 - logging.{}("Num:%s", str(num)) - """, + """ + import logging + num = 2 + logging.{}("Num:" + str(num)) + """, + """ + import logging + num = 2 + logging.{}("Num:%s", str(num)) + """, ), ( - """\ - import logging - log = logging.getLogger('anything') - one = "1" - log.{}("one " + one + " two " + "2") - """, - """\ - import logging - log = logging.getLogger('anything') - one = "1" - log.{}("one %s two 2", one) - """, + """ + import logging + log = logging.getLogger('anything') + one = "1" + log.{}("one " + one + " two " + "2") + """, + """ + import logging + log = logging.getLogger('anything') + one = "1" + log.{}("one %s two 2", one) + """, ), ], ) @@ -382,54 +382,54 @@ def test_import(self, tmpdir, input_code, expected_output, func): "input_code,expected_output", [ ( - """\ - import logging - e = "error" - logging.log(logging.ERROR, "Error occurred: " + e) - """, - """\ - import logging - e = "error" - logging.log(logging.ERROR, "Error occurred: %s", e) - """, + """ + import logging + e = "error" + logging.log(logging.ERROR, "Error occurred: " + e) + """, + """ + import logging + e = "error" + logging.log(logging.ERROR, "Error occurred: %s", e) + """, ), ( - """\ - import logging - log = logging.getLogger('anything') - one = "1" - log.log(logging.INFO, "one " + one + " two " + "2") - """, - """\ - import logging - log = logging.getLogger('anything') - one = "1" - log.log(logging.INFO, "one %s two 2", one) - """, + """ + import logging + log = logging.getLogger('anything') + one = "1" + log.log(logging.INFO, "one " + one + " two " + "2") + """, + """ + import logging + log = logging.getLogger('anything') + one = "1" + log.log(logging.INFO, "one %s two 2", one) + """, ), ( - """\ - from logging import log, INFO - e = "error" - log(INFO, "Error occurred: " + e) - """, - """\ - from logging import log, INFO - e = "error" - log(INFO, "Error occurred: %s", e) - """, + """ + from logging import log, INFO + e = "error" + log(INFO, "Error occurred: " + e) + """, + """ + from logging import log, INFO + e = "error" + log(INFO, "Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger, ERROR - one = "1" - getLogger('anything').log(ERROR, "one " + one + " two " + "2") - """, - """\ - from logging import getLogger, ERROR - one = "1" - getLogger('anything').log(ERROR, "one %s two 2", one) - """, + """ + from logging import getLogger, ERROR + one = "1" + getLogger('anything').log(ERROR, "one " + one + " two " + "2") + """, + """ + from logging import getLogger, ERROR + one = "1" + getLogger('anything').log(ERROR, "one %s two 2", one) + """, ), ], ) @@ -441,28 +441,28 @@ def test_log_func(self, tmpdir, input_code, expected_output): "input_code,expected_output", [ ( - """\ - from logging import {0} - e = "error" - {0}("Error occurred: " + e) - """, - """\ - from logging import {0} - e = "error" - {0}("Error occurred: %s", e) - """, + """ + from logging import {0} + e = "error" + {0}("Error occurred: " + e) + """, + """ + from logging import {0} + e = "error" + {0}("Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger - one = "1" - getLogger('anything').{}("one " + one + " two" + "2") - """, - """\ - from logging import getLogger - one = "1" - getLogger('anything').{}("one %s two2", one) - """, + """ + from logging import getLogger + one = "1" + getLogger('anything').{}("one " + one + " two" + "2") + """, + """ + from logging import getLogger + one = "1" + getLogger('anything').{}("one %s two2", one) + """, ), ], ) @@ -476,28 +476,28 @@ def test_from_import(self, tmpdir, input_code, expected_output, func): "input_code,expected_output", [ ( - """\ - from logging import {} as log_func - e = "error" - log_func("Error occurred: " + e) - """, - """\ - from logging import {} as log_func - e = "error" - log_func("Error occurred: %s", e) - """, + """ + from logging import {} as log_func + e = "error" + log_func("Error occurred: " + e) + """, + """ + from logging import {} as log_func + e = "error" + log_func("Error occurred: %s", e) + """, ), ( - """\ - from logging import getLogger as make_logger - one = "1" - make_logger('anything').{}("one " + one + " two " + "2") - """, - """\ - from logging import getLogger as make_logger - one = "1" - make_logger('anything').{}("one %s two 2", one) - """, + """ + from logging import getLogger as make_logger + one = "1" + make_logger('anything').{}("one " + one + " two " + "2") + """, + """ + from logging import getLogger as make_logger + one = "1" + make_logger('anything').{}("one %s two 2", one) + """, ), ], ) @@ -510,16 +510,16 @@ def test_import_alias(self, tmpdir, input_code, expected_output, func): "code", [ """ - import xyz - var = "hello" - xyz.info("hi: + var) - """, + import xyz + var = "hello" + xyz.info("hi: + var) + """, """ - import my_logging - log = my_logging.getLogger('anything') - var = "hello" - log.info("hi:" + var) - """, + import my_logging + log = my_logging.getLogger('anything') + var = "hello" + log.info("hi:" + var) + """, ], ) def test_different_log_func(self, tmpdir, code): @@ -527,14 +527,14 @@ def test_different_log_func(self, tmpdir, code): @pytest.mark.xfail(reason="Not currently supported") def test_log_as_arg(self, tmpdir): - input_code = """\ + input_code = """ import logging log = logging.getLogger('foo') def some_function(logger): logger.debug("hi: " + 'hello') some_function(log) """ - expected_code = """\ + expected_code = """ import logging log = logging.getLogger('foo') def some_function(logger): @@ -545,7 +545,7 @@ def some_function(logger): @pytest.mark.xfail(reason="Not currently supported") def test_log_format_specifiers(self, tmpdir): - input_code = """\ + input_code = """ import logging name = "Alice" age = 30 @@ -562,7 +562,7 @@ def test_log_format_specifiers(self, tmpdir): ", Number (octal): " + format(octal_num, 'o') + ", Scientific Value: " + format(scientific_val, '.2e')) """ - expected_code = """\ + expected_code = """ import logging name = "Alice" age = 30 @@ -576,12 +576,12 @@ def test_log_format_specifiers(self, tmpdir): self.run_and_assert(tmpdir, input_code, expected_code) def test_log_kwargs(self, tmpdir): - input_code = """\ + input_code = """ import logging name = "alice" logging.info("Name: " + name, exc_info=True, extra={'custom_info': 'extra details'}, stacklevel=2) """ - expected_code = """\ + expected_code = """ import logging name = "alice" logging.info("Name: %s", name, exc_info=True, extra={'custom_info': 'extra details'}, stacklevel=2) @@ -592,52 +592,52 @@ def test_log_kwargs(self, tmpdir): "input_code,expected_output", [ ( - """\ - import logging - var = b"three" - logging.info(b"one " + var) - """, - """\ - import logging - var = b"three" - logging.info(b"one %s", var) - """, + """ + import logging + var = b"three" + logging.info(b"one " + var) + """, + """ + import logging + var = b"three" + logging.info(b"one %s", var) + """, ), ( - """\ - import logging - var = "three" - logging.info("one " + "two " + var) - """, - """\ - import logging - var = "three" - logging.info("one two %s", var) - """, + """ + import logging + var = "three" + logging.info("one " + "two " + var) + """, + """ + import logging + var = "three" + logging.info("one two %s", var) + """, ), ( - """\ - import logging - four = r" four" - logging.info(r"two \\n" + four) - """, - """\ - import logging - four = r" four" - logging.info(r"two \\n%s", four) - """, + """ + import logging + four = r" four" + logging.info(r"two \\n" + four) + """, + """ + import logging + four = r" four" + logging.info(r"two \\n%s", four) + """, ), ( - """\ - import logging - var = r"three" - logging.info(r"one " + r"two " + var) - """, - """\ - import logging - var = r"three" - logging.info(r"one two %s", var) - """, + """ + import logging + var = r"three" + logging.info(r"one " + r"two " + var) + """, + """ + import logging + var = r"three" + logging.info(r"one two %s", var) + """, ), ], ) @@ -646,12 +646,12 @@ def test_log_prefix_types(self, tmpdir, input_code, expected_output): @pytest.mark.xfail(reason="Not currently supported") def test_log_mixed_prefixes(self, tmpdir): - input_code = """\ + input_code = """ import logging four = u" four" logging.info("one: " + r"two \\n" + u'three '+ four) """ - expected_code = """\ + expected_code = """ import logging four = u" four" logging.info("one: " + r"two \\n" + u'three %s' , four) @@ -661,28 +661,28 @@ def test_log_mixed_prefixes(self, tmpdir): @pytest.mark.parametrize( "code", [ - """\ + """ import logging logging.info("one" + "two") """, - """\ + """ import logging logging.info("%s" + "hi") """, - """\ + """ import logging logging.info("one" + "%s" + "three %s") """, - """\ + """ import logging logging.info(2+2) """, - """\ + """ import logging var = 2 logging.info(var + var) """, - """\ + """ import logging msg = "one" var = "two" @@ -691,14 +691,14 @@ def test_log_mixed_prefixes(self, tmpdir): """, # User intention is unclear here, did they # Want a `%s` literal or no? - """\ + """ import logging var = "something" logging.info("Something occurred: %s " + var) """, # There are more `%` operators than there are variables so # We will not attempt to change the code. - """\ + """ import logging e = "error" logging.error("Error %s occurred: %s " + e) @@ -710,12 +710,12 @@ def test_no_change(self, tmpdir, code): @pytest.mark.xfail(reason="Not currently supported") def test_modulo_and_plus(self, tmpdir): - input_code = """\ + input_code = """ import logging var = "three" logging.info("one %s" % 'two ' + var + ' four') """ - expected_code = """\ + expected_code = """ import logging var = "three" logging.info("one %s %s four", 'two', var) @@ -726,32 +726,32 @@ def test_modulo_and_plus(self, tmpdir): "input_code,expected_output", [ ( - """\ - import logging - e = "error" - msg = "something %s" - logging.info(msg + e) - """, - """\ - import logging - e = "error" - msg = "something %s" - logging.info("%s%s", msg, e) - """, + """ + import logging + e = "error" + msg = "something %s" + logging.info(msg + e) + """, + """ + import logging + e = "error" + msg = "something %s" + logging.info("%s%s", msg, e) + """, ), ( - """\ - import logging - one = "one" - two = "two" - logging.info(one + two) - """, - """\ - import logging - one = "one" - two = "two" - logging.info("%s%s", one, two) - """, + """ + import logging + one = "one" + two = "two" + logging.info(one + two) + """, + """ + import logging + one = "one" + two = "two" + logging.info("%s%s", one, two) + """, ), ], )