def test_remove_raw_generator(self): sub_generator = Generator() generator = HTMLChildGenerator() generator.append(sub_generator) generator.append("foo") generator.remove_raw(sub_generator) assert_equal([b"foo"], list(iter(generator)))
def test_children(self): generator = HTMLChildGenerator() generator.append("Foo") generator.append("<tag>") assert_equal(["Foo", "<tag>"], generator.children) generator.children.append("Bar") assert_equal(["Foo", "<tag>"], generator.children)
def test_children_readonly(self): generator = HTMLChildGenerator() generator.append("Foo") generator.children.append("Bar") assert_equal(["Foo"], generator.children)
def test_empty(self): generator = HTMLChildGenerator() generator.append(u"c1") generator.extend([u"c2", u"c3", NullGenerator()]) generator.empty() assert_equal([], list(iter(generator)))
def test_len(self): generator = HTMLChildGenerator() generator.append(u"c1") generator.extend([u"c2", u"c3", NullGenerator()]) assert_equal(4, len(generator))
def test_remove_raw(self): generator = HTMLChildGenerator() generator.extend_raw(["foo", "bar", "lower < than"]) generator.remove_raw("foo") generator.remove_raw("lower < than") assert_equal([b"bar"], list(iter(generator)))
def test_remove_raw_not_found(self): generator = HTMLChildGenerator() generator.extend(["foo", "bar"]) with assert_raises(ValueError): generator.remove_raw("baz")
def test_extend_raw(self): generator = HTMLChildGenerator() generator.append(u"c1") generator.extend_raw([_TestingGenerator([u"c&2", u"c3"]), u"<c4>"]) assert_equal([b"c1", b"c&2", b"c3", b"<c4>"], list(iter(generator)))
def test_append_raw(self): generator = HTMLChildGenerator() generator.append_raw(u"c1&c2") generator.append_raw(_TestingGenerator([u"c3", u"<c4>"])) assert_equal([b"c1&c2", b"c3", b"<c4>"], list(iter(generator)))
def __init__(self, element_name): super(Element, self).__init__(element_name) self.children = HTMLChildGenerator()