Skip to content

Commit

Permalink
Add integration test for use-defusedxml
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 24, 2023
1 parent e1522c5 commit c91ab02
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
exclude: |
(?x)^(
src/core_codemods/docs/.*
integration_tests/.*
)$
- id: check-added-large-files
- repo: https://github.com/psf/black
Expand Down
42 changes: 42 additions & 0 deletions integration_tests/test_use_defusedxml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from core_codemods.use_defused_xml import UseDefusedXml
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestUseDefusedXml(BaseIntegrationTest):
codemod = UseDefusedXml
code_path = "tests/samples/use_defusedxml.py"

original_code, _ = original_and_expected_from_code_path(code_path, [])
expected_new_code = """\
from io import StringIO
from xml.etree import ElementInclude # pylint: disable=unused-import
import defusedxml.ElementTree
xml = StringIO("<root>Hello XML</root>")
et = defusedxml.ElementTree.parse(xml)
"""

num_changed_files = 2
expected_diff = """\
---
+++
@@ -1,5 +1,6 @@
from io import StringIO
-from xml.etree import ElementTree, ElementInclude # pylint: disable=unused-import
+from xml.etree import ElementInclude # pylint: disable=unused-import
+import defusedxml.ElementTree
xml = StringIO("<root>Hello XML</root>")
-et = ElementTree.parse(xml)
+et = defusedxml.ElementTree.parse(xml)
""" # noqa: W291

expected_line_change = "5"
change_description = UseDefusedXml.CHANGE_DESCRIPTION

requirements_path = "tests/samples/requirements.txt"
original_requirements = "# file used to test dependency management\nrequests==2.31.0\nblack==23.7.*\nmypy~=1.4\npylint>1\n"
expected_new_reqs = "# file used to test dependency management\nrequests==2.31.0\nblack==23.7.*\nmypy~=1.4\npylint>1\ndefusedxml~=0.7.1"
5 changes: 5 additions & 0 deletions tests/samples/use_defusedxml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from io import StringIO
from xml.etree import ElementTree, ElementInclude # pylint: disable=unused-import

xml = StringIO("<root>Hello XML</root>")
et = ElementTree.parse(xml)

0 comments on commit c91ab02

Please sign in to comment.