Skip to content

Commit 2e3cdd9

Browse files
committed
[test/versionConv] Add _parse_dict_sections test
1 parent d8b235c commit 2e3cdd9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/test_version_converter.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,44 @@ def test_convert_odml_file_value(self):
520520
self.assertEqual(len(prop), 1)
521521
self.assertEqual(len(prop.findall("name")), 1)
522522

523+
def test_parse_dict_sections(self):
524+
# Test appending tags; not appending empty subsections or properties
525+
root = ET.Element("root")
526+
sec_dict = [{'name': 'sec_one', 'sections': [], 'properties': []}]
527+
528+
self.assertEqual(len(root.getchildren()), 0)
529+
self.VC("")._parse_dict_sections(root, sec_dict)
530+
self.assertEqual(len(root.getchildren()), 1)
531+
self.assertIsNotNone(root.find("section").find("name"))
532+
533+
# Test appending multiple sections
534+
root = ET.Element("root")
535+
sec_dict = [{'name': 'sec_one'}, {'name': 'sec_two'}, {'name': 'sec_three'}]
536+
537+
self.assertEqual(len(root.getchildren()), 0)
538+
self.VC("")._parse_dict_sections(root, sec_dict)
539+
self.assertEqual(len(root.getchildren()), 3)
540+
541+
# Test appending subsections
542+
root = ET.Element("root")
543+
sec_dict = [{'name': 'sec_one', 'sections': [{'name': 'sub_one'},
544+
{'name': 'sub_two'}]}]
545+
self.assertEqual(len(root.getchildren()), 0)
546+
self.VC("")._parse_dict_sections(root, sec_dict)
547+
sec = root.find("section")
548+
self.assertEqual(len(sec.getchildren()), 3)
549+
self.assertEqual(len(sec.findall("section")), 2)
550+
551+
# Test appending properties
552+
root = ET.Element("root")
553+
sec_dict = [{'name': 'sec_one', 'properties': [{'name': 'prop_one'},
554+
{'name': 'prop_two'}]}]
555+
self.assertEqual(len(root.getchildren()), 0)
556+
self.VC("")._parse_dict_sections(root, sec_dict)
557+
sec = root.find("section")
558+
self.assertEqual(len(sec.getchildren()), 3)
559+
self.assertEqual(len(sec.findall("property")), 2)
560+
523561
def test_parse_dict_properties(self):
524562
# Test appending tags and moving values
525563
root = ET.Element("root")

0 commit comments

Comments
 (0)