Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Oct 3, 2023
1 parent 21a3987 commit 7c189c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
15 changes: 10 additions & 5 deletions integration_tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ def setup_class(cls):
cls.codemod_registry = registry.load_registered_codemods()

def setup_method(self):
self.codemod_wrapper = [
cmod
for cmod in self.codemod_registry._codemods
if cmod.codemod == self.codemod
][0]
try:
self.codemod_wrapper = [
cmod
for cmod in self.codemod_registry._codemods
if cmod.codemod == self.codemod
][0]
except IndexError as exc:
raise IndexError(
"You must register the codemod to a CodemodCollection."
) from exc

def _assert_run_fields(self, run, output_path):
assert run["vendor"] == "pixee"
Expand Down
16 changes: 16 additions & 0 deletions integration_tests/test_lxml_safe_parser_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from core_codemods.lxml_safe_parser_defaults import LxmlSafeParserDefaults
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestLxmlSafeParserDefaults(BaseIntegrationTest):
codemod = LxmlSafeParserDefaults
code_path = "tests/samples/lxml_parser.py"
original_code, expected_new_code = original_and_expected_from_code_path(
code_path, [(1, "parser = lxml.etree.XMLParser(resolve_entities=False)\n")]
)
expected_diff = "--- \n+++ \n@@ -1,2 +1,2 @@\n import lxml\n-parser = lxml.etree.XMLParser()\n+parser = lxml.etree.XMLParser(resolve_entities=False)\n"
expected_line_change = "2"
change_description = LxmlSafeParserDefaults.CHANGE_DESCRIPTION
2 changes: 2 additions & 0 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .https_connection import HTTPSConnection
from .jwt_decode_verify import JwtDecodeVerify
from .limit_readline import LimitReadline
from .lxml_safe_parser_defaults import LxmlSafeParserDefaults
from .order_imports import OrderImports
from .process_creation_sandbox import ProcessSandbox
from .remove_unnecessary_f_str import RemoveUnnecessaryFStr
Expand All @@ -35,6 +36,7 @@
HTTPSConnection,
JwtDecodeVerify,
LimitReadline,
LxmlSafeParserDefaults,
OrderImports,
ProcessSandbox,
RemoveUnnecessaryFStr,
Expand Down
2 changes: 2 additions & 0 deletions tests/samples/lxml_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import lxml
parser = lxml.etree.XMLParser()

0 comments on commit 7c189c9

Please sign in to comment.