MCPcopy Create free account
hub / github.com/sissaschool/xmlschema / check_encode

Method check_encode

tests/validation/test_encoding.py:39–55  ·  view source on GitHub ↗
(self, xsd_component, data, expected, **kwargs)

Source from the content-addressed store, hash-verified

37 cases_dir = pathlib.Path(__file__).parent.joinpath('../test_cases')
38
39 def check_encode(self, xsd_component, data, expected, **kwargs):
40 if isinstance(expected, type) and issubclass(expected, Exception):
41 self.assertRaises(expected, xsd_component.encode, data, **kwargs)
42 elif is_etree_element(expected):
43 elem = xsd_component.encode(data, **kwargs)
44 self.check_etree_elements(expected, elem)
45 else:
46 obj = xsd_component.encode(data, **kwargs)
47 if isinstance(obj, tuple) and len(obj) == 2 and isinstance(obj[1], list):
48 self.assertEqual(expected, obj[0])
49 self.assertTrue(isinstance(obj[0], type(expected)))
50 elif is_etree_element(obj):
51 namespaces = kwargs.pop('namespaces', self.default_namespaces)
52 self.assertEqual(expected, etree_tostring(obj, namespaces=namespaces).strip())
53 else:
54 self.assertEqual(expected, obj)
55 self.assertTrue(isinstance(obj, type(expected)))
56
57 def test_decode_encode(self):
58 """Test encode after decode, checking the re-encoded tree."""

Calls 4

is_etree_elementFunction · 0.90
etree_tostringFunction · 0.90
check_etree_elementsMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected