示例#1
0
 def test_init__parameter_not_a_xml_dict_element__fails(self):
     e = ET.XML("""<array>
             <key>Name</key>   <string>Foo</string>
             <key>Artist</key> <string>Bar</string>
         </array>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#2
0
 def test_init__parameter_is_a_xml_element__has_leading_text__fails(self):
     e = ET.XML("""<dict>Text
             <key>Name</key>   <string>Foo</string>
             <key>Artist</key> <string>Bar</string>
         </dict>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#3
0
 def test_init__has_key_child_element_not_in_schema__fails(self):
     e = ET.XML("""<dict>
             <key>BadKey</key> <string>Foo</string>
             <key>Artist</key> <string>Bar</string>
         </dict>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#4
0
 def test_init__parameter_is_a_xml_element__odd_number_of_children__fails(
         self):
     e = ET.XML("""<dict>
             <key>Name</key>   <string>Foo</string>
             <key>Artist</key>
         </dict>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#5
0
 def test_init__combination_of_fields_matches_no_categories__fails(self):
     e = ET.XML("""<dict>
             <key>Name</key>     <string>Foo</string>
             <key>Artist</key>   <string>Bar</string>
             <key>Director</key> <string>Baz</string>
         </dict>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#6
0
 def test_init__has_value_child_element_tag_not_in_schema_for_associated_key_name__fails(
         self):
     e = ET.XML("""<dict>
             <key>Name</key>   <integer>0</integer>
             <key>Artist</key> <string>Bar</string>
         </dict>""")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#7
0
 def test_init__schema_allows_alternate_types_for_some_fiels(
         self, e, expected):
     e = ET.XML("""<dict>
             <key>Name</key>   <string>Foo</string>
             <key>Artist</key> <string>Bar</string>
             <key>Release Date</key> {}
         </dict>""".format(e))
     assert xml_composite.Dictionary(
         e, schema=TEST_SCHEMA)["Release Date"] == expected
示例#8
0
 def test_init__parameter_is_a_xml_element__one_child__fails(self):
     e = ET.XML("<dict><key>Name</key></dict>")
     with pytest.raises(ValueError):
         xml_composite.Dictionary(e, schema=TEST_SCHEMA)
示例#9
0
 def test_init__happy_path(self):
     e = ET.XML("""<dict>
             <key>Name</key>   <string>Foo</string>
             <key>Artist</key> <string>Bar</string>
         </dict>""")
     assert xml_composite.Dictionary(e, schema=TEST_SCHEMA).value == "Album"