Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unparse_to_node_handle_text(self):
class Cls(xso.XSO):
TAG = "bar"
text = xso.Text()
obj = Cls()
obj.text = "foobar"
self._unparse_test(
obj,
etree.fromstring("foobar")
)
def test_unparse_to_node_handle_child(self):
class ClsLeaf(xso.XSO):
TAG = "baz"
text = xso.Text()
class Cls(xso.XSO):
TAG = "bar"
child = xso.Child([ClsLeaf])
obj = Cls()
obj.child = ClsLeaf()
obj.child.text = "fnord"
self._unparse_test(
obj,
etree.fromstring("fnord")
)
def test_unparse_to_node_create_node(self):
self._unparse_test(
self.obj,
etree.fromstring("")
)
super().__init__()
self.attr = a
prop = xso.ChildMap([Foo, Bar])
instance = make_instance_mock({
prop: {
Bar.TAG: [Bar()],
Foo.TAG: [Foo(a="1"), Foo(a="2")]
}
})
parent = etree.Element("root")
prop.to_node(instance, parent)
self.assertSubtreeEqual(
etree.fromstring(""),
parent)
def test_element_path(self):
el = etree.fromstring(""
""
"")
baz1 = el[0][0]
subfoo = el[1]
baz2 = el[2][0]
self.assertEqual(
"/foo",
element_path(el))
self.assertEqual(
"/foo/bar[0]/baz[0]",
element_path(baz1))
self.assertEqual(
"/foo/subfoo[0]",
element_path(subfoo))
self.assertEqual(
def test_assertSubtreeEqual_missing_child(self):
t1 = etree.fromstring("")
t2 = etree.fromstring("")
with self.assertRaises(AssertionError):
self.assertSubtreeEqual(t1, t2)
def test_enforce_attr_policy_fail(self):
instance = make_instance_mock()
prop = xso.ChildText(
"body",
attr_policy=xso.UnknownAttrPolicy.FAIL)
subtree = etree.fromstring("foo")
with self.assertRaises(ValueError):
drive_from_events(prop.from_events, instance, subtree, self.ctx)
self.assertFalse(instance._stanza_props)
def test_assertSubtreeEqual_text_no_join_text_parts(self):
t1 = etree.fromstring("t<a>ext1</a><a>")
t2 = etree.fromstring("te</a><a>xt1")
with self.assertRaises(AssertionError):
self.assertSubtreeEqual(t1, t2, join_text_parts=False)
</a>
def test_forwards_nested_elements(self):
tree = etree.fromstring("")
sd = xso.SAXDriver(self.catchall)
lxml.sax.saxify(tree, sd)
self.assertSequenceEqual(
[
("start", None, "foo", {}),
("start", None, "bar", {}),
("end",),
("end",)
],
self.l
)
sd.close()
TAG = "bar"
class Foo(xso.XSO):
TAG = "foo"
instance = make_instance_mock()
prop = xso.ChildMap(
[Foo, Bar],
key=lambda obj: obj.TAG[1]
)
drive_from_events(
prop.from_events,
instance,
etree.fromstring(""),
self.ctx
)
drive_from_events(
prop.from_events,
instance,
etree.fromstring(""),
self.ctx
)
drive_from_events(
prop.from_events,
instance,
etree.fromstring(""),
self.ctx
)
self.assertIn(prop, instance._stanza_props)