-
-
Couldn't load subscription status.
- Fork 32
Feat/attr escape #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/attr escape #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,3 +129,5 @@ dmypy.json | |
| .pyre/ | ||
|
|
||
| .idea/ | ||
| .coverage | ||
| junit.xml | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import pytest | ||
Check noticeCode scanning / CodeQL Unused import Note test
Import of 'pytest' is not used.
|
||
| import json | ||
|
|
||
| from json2xml import dicttoxml, json2xml | ||
|
|
||
|
|
||
|
|
||
| class TestEscaping: | ||
| def test_escaping(self): | ||
| # Test cases | ||
| test_cases = [ | ||
| { | ||
| "root": { | ||
| "@attrs": { | ||
| "Text": "this & that" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "data": json.dumps({"key": "value & more"}) | ||
| }, | ||
| { | ||
| "mixed": { | ||
| "json_str": json.dumps({"a": "b & c"}), | ||
| "plain": "text & symbols" | ||
| } | ||
| } | ||
| ] | ||
| for i, data in enumerate(test_cases): | ||
| print(f"\nTest case {i + 1}:") | ||
| print("Input:", data) | ||
| xml = dicttoxml.dicttoxml(data, custom_root='all') | ||
| print("Output XML:") | ||
| print(xml.decode('utf-8')) | ||
|
Comment on lines
+29
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Avoid loops in tests. ( ExplanationAvoid complex code, like loops, in test functions.Google's software engineering guidelines says:
Some ways to fix this:
Software Engineering at Google / Don't Put Logic in Tests |
||
|
|
||
| def test_escapes_angle_brackets(self): | ||
| json_data = json.dumps({"root": {"@attrs": {"HelpText": "version <here>"}}}) | ||
| result = json2xml.Json2xml(json_data).to_xml() | ||
| assert '"HelpText": "version <here>"' in result | ||
|
|
||
| def test_escapes_quotes(self): | ||
| json_data = json.dumps({"root": {"@attrs": {"Text": "\"quoted\""}}}) | ||
| result = json2xml.Json2xml(json_data).to_xml() | ||
| assert '"Text": "\\"quoted\\""' in result | ||
|
|
||
| def test_escapes_ampersands(self): | ||
| json_data = json.dumps({"root": {"@attrs": {"Text": "this & that"}}}) | ||
| result = json2xml.Json2xml(json_data).to_xml() | ||
| assert '"Text": "this & that"' in result | ||
|
|
||
| def test_escapes_mixed_special_chars(self): | ||
| json_data = json.dumps({"root": {"@attrs": {"Text": "<tag> & \"quote\""}}}) | ||
| result = json2xml.Json2xml(json_data).to_xml() | ||
| assert '"Text": "<tag> & \\"quote\\""' in result | ||
|
|
||
|
|
||
Check notice
Code scanning / CodeQL
Unused import Note test