1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add raw option to xml parser for _ attribute prefix

This commit is contained in:
Kelly Brazil
2022-11-01 18:09:05 -07:00
parent de7a010f62
commit 186ad73651
6 changed files with 94 additions and 13 deletions

View File

@ -15,6 +15,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-foodmenu.xml'), 'r', encoding='utf-8') as f:
generic_xml_foodmenu = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-nmap.xml'), 'r', encoding='utf-8') as f:
generic_xml_nmap = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-cd_catalog.json'), 'r', encoding='utf-8') as f:
generic_xml_cd_catalog_json = json.loads(f.read())
@ -22,6 +25,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-foodmenu.json'), 'r', encoding='utf-8') as f:
generic_xml_foodmenu_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-nmap.json'), 'r', encoding='utf-8') as f:
generic_xml_nmap_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-nmap-raw.json'), 'r', encoding='utf-8') as f:
generic_xml_nmap_r_json = json.loads(f.read())
def test_xml_nodata(self):
"""
@ -29,6 +38,12 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.xml.parse('', quiet=True), [])
def test_xml_nodata_r(self):
"""
Test xml parser with no data and raw output
"""
self.assertEqual(jc.parsers.xml.parse('', raw=True, quiet=True), [])
def test_xml_cd_catalog(self):
"""
Test the cd catalog xml file
@ -41,6 +56,18 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.xml.parse(self.generic_xml_foodmenu, quiet=True), self.generic_xml_foodmenu_json)
def test_xml_nmap(self):
"""
Test nmap xml output
"""
self.assertEqual(jc.parsers.xml.parse(self.generic_xml_nmap, quiet=True), self.generic_xml_nmap_json)
def test_xml_nmap_r(self):
"""
Test nmap xml raw output
"""
self.assertEqual(jc.parsers.xml.parse(self.generic_xml_nmap, raw=True, quiet=True), self.generic_xml_nmap_r_json)
if __name__ == '__main__':
unittest.main()