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 a534257 commit 3268d1f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ repos:
- id: trailing-whitespace
exclude: |
(?x)^(
src/core_codemods/docs/.*
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)
"""

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 3268d1f

Please sign in to comment.