From 42cbd1777dbacc614d75f67f3f9156f72be46532 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 4 Feb 2020 13:53:45 -0800 Subject: [PATCH] add xml and yaml tests --- tests/test_xml.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_yaml.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/test_xml.py create mode 100644 tests/test_yaml.py diff --git a/tests/test_xml.py b/tests/test_xml.py new file mode 100644 index 00000000..4b5c3ce3 --- /dev/null +++ b/tests/test_xml.py @@ -0,0 +1,40 @@ +import os +import unittest +import json +import jc.parsers.xml + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-cd_catalog.xml'), 'r') as f: + self.generic_xml_cd_catalog = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-foodmenu.xml'), 'r') as f: + self.generic_xml_foodmenu = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-cd_catalog.json'), 'r') as f: + self.generic_xml_cd_catalog_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/xml-foodmenu.json'), 'r') as f: + self.generic_xml_foodmenu_json = json.loads(f.read()) + + def test_xml_cd_catalog(self): + """ + Test the cd catalog xml file + """ + self.assertEqual(jc.parsers.xml.parse(self.generic_xml_cd_catalog, quiet=True), self.generic_xml_cd_catalog_json) + + def test_xml_foodmenu(self): + """ + Test the food menu xml file + """ + self.assertEqual(jc.parsers.xml.parse(self.generic_xml_foodmenu, quiet=True), self.generic_xml_foodmenu_json) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_yaml.py b/tests/test_yaml.py new file mode 100644 index 00000000..381dd9e2 --- /dev/null +++ b/tests/test_yaml.py @@ -0,0 +1,40 @@ +import os +import unittest +import json +import jc.parsers.yaml + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sc.yaml'), 'r') as f: + self.generic_yaml_istio_sc = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sidecar.yaml'), 'r') as f: + self.generic_yaml_istio_sidecar = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sc.json'), 'r') as f: + self.generic_yaml_istio_sc_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sidecar.json'), 'r') as f: + self.generic_yaml_istio_sidecar_json = json.loads(f.read()) + + def test_yaml_istio_sc(self): + """ + Test the Istio SC yaml file + """ + self.assertEqual(jc.parsers.yaml.parse(self.generic_yaml_istio_sc, quiet=True), self.generic_yaml_istio_sc_json) + + def test_yaml_istio_sidecar(self): + """ + Test the Istio Sidecar yaml file + """ + self.assertEqual(jc.parsers.yaml.parse(self.generic_yaml_istio_sidecar, quiet=True), self.generic_yaml_istio_sidecar_json) + + +if __name__ == '__main__': + unittest.main()