def test_widget_base_element_attribute_dispatches_when_view_exists():
    view = FakeDispatchView({'name': 'attr', 'selector': '#id', 'attr': 'hello', 'value': 'world'})

    b_elem = BaseElement(id='id')
    b_elem.view = view
    b_elem._set_attribute('hello', 'world')
    view.verify()
def test_widget_base_element_property_parent_setter_sets_view():
    fake_parent = BaseElement(id='id')
    fake_parent.view = 3

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem.view == 3, "BaseElement.parent should set the value of BaseElement.view to the parent's view"
def test_widget_base_container_clear_children_removes_all():
    container = BaseContainer(id='id')

    child_1 = BaseElement(id='id', parent=container)
    child_2 = BaseElement(id='id2', parent=container)

    assert len(container.children) == 2
    container.clear_children()
    assert len(container.children) == 0
def test_widget_base_container_replace_child_replaces_child():
    fake_parent = BaseContainer(id='id')

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2')

    fake_parent.replace_child(b_elem_1, b_elem_2)

    assert len(fake_parent.children) == 1 and fake_parent.children[
        0] is b_elem_2, 'BaseContainer.replace_child() should replace the child in BaseContainer.children.'
def test_widget_base_container_replace_child_handles_parents():
    fake_parent = BaseContainer(id='id')

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2')

    fake_parent.replace_child(b_elem_1, b_elem_2)

    assert b_elem_1.parent is None, "BaseContainer.replace_child() should unset the old child's parent."
    assert b_elem_2.parent is fake_parent, "BaseContainer.replace_child() should set the new child's parent."
def test_widget_base_element_attribute_dispatches_when_view_exists():
    view = FakeDispatchView({
        'name': 'attr',
        'selector': '#id',
        'attr': 'hello',
        'value': 'world'
    })

    b_elem = BaseElement(id='id')
    b_elem.view = view
    b_elem._set_attribute('hello', 'world')
    view.verify()
def test_widget_base_container_add_child_dispatches_append():
    view_test = FakeDispatchView({
        'name': 'append',
        'html': '<x id="id">',
        'selector': '#id'
    })
    fake_parent = BaseContainer(id='id')
    fake_parent.view = view_test

    b_elem = BaseElement(id='id')
    b_elem.html_tag = 'x'
    b_elem.autoclosing = True

    fake_parent.add_child(b_elem)
    view_test.verify()
def test_widget_base_container_remove_child_dispatches_remove():
    view_test = FakeDispatchView({'name': 'remove', 'selector': '#id'})
    fake_parent = BaseContainer(id='id')

    b_elem = BaseElement(id='id')

    fake_parent.add_child(b_elem)
    fake_parent.view = view_test
    fake_parent.remove_child(b_elem)
    view_test.verify()
def test_widget_base_element_property_parent_setter_sets_view():
    fake_parent = BaseElement(id='id')
    fake_parent.view = 3

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem.view == 3, "BaseElement.parent should set the value of BaseElement.view to the parent's view"
def test_widget_base_container_compile_compiles_children():
    fake_parent = BaseContainer(id='id')
    fake_parent.html_tag = 'a'

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2', parent=fake_parent)

    b_elem_1.html_tag = 'b'
    b_elem_2.html_tag = 'c'

    assert fake_parent.compile(
    ) == '<a id="id"><b id="id1"></b><c id="id2"></c></a>'
def test_widget_base_element_remove_class_removes_class():
    b_elem = BaseElement(id='id', classname='hello')
    b_elem.remove_class('hello')
    assert len(b_elem._classes) == 0, 'BaseElement.remove_class() should delete specified class from BaseElement._classes.'
示例#12
0
def test_widget_base_element_property_id():
    b_elem = BaseElement(id='id')
    assert b_elem.id == 'id', 'BaseElement.id should return the value of internal BaseElement._attributes["id"]'
示例#13
0
def test_widget_base_element_property_parent_setter():
    fake_parent = BaseElement(id='id')

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem._parent is fake_parent, 'BaseElement.parent should set the value of internal BaseElement._parent'
示例#14
0
def test_widget_base_element_property_parent_getter():
    b_elem = BaseElement(id='id')
    assert b_elem.parent is b_elem._parent, 'BaseElement.parent should return the value of internal BaseElement._parent'
示例#15
0
def test_widget_base_element_property_id_setter():
    b_elem = BaseElement(id='id')
    b_elem.id = 'id2'
    assert b_elem.id == 'id2', 'BaseElement.id should set the value of BaseElement._attributes["id"]'
示例#16
0
def test_widget_base_element_doesnt_set_attribute_when_none():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', None)
    assert 'hello' not in b_elem._attributes, 'BaseElement._set_attribute should do nothing when attribute value is None'
def test_widget_base_element_compile_not_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = 'x'
    b_elem.content = "b"
    assert b_elem.compile() == '<x id="a">b</x>'
def test_widget_base_element_property_parent_setter():
    fake_parent = BaseElement(id='id')

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem._parent is fake_parent, 'BaseElement.parent should set the value of internal BaseElement._parent'
def test_widget_base_element_sets_attributes():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', 'there')
    assert b_elem._attributes.get('hello') == 'there', "BaseElement._set_attribute should set the specified attribute in BaseElement._attributes"
示例#20
0
def test_widget_base_element_remove_class_removes_class():
    b_elem = BaseElement(id='id', classname='hello')
    b_elem.remove_class('hello')
    assert len(
        b_elem._classes
    ) == 0, 'BaseElement.remove_class() should delete specified class from BaseElement._classes.'
示例#21
0
def test_widget_base_element_property_classname_getter():
    b_elem = BaseElement(id='hello', classname="hello")
    assert b_elem.classname == "hello", 'BaseElement.classname should return an aggregate of BaseElement._classes.'
示例#22
0
def test_widget_base_element_classname_is_set():
    b_elem = BaseElement(id='hello', classname="hello")
    err = 'BaseElement constructor should be able to set a class via the "classname" keyword arg.'

    assert len(b_elem._classes) == 1, err
    assert b_elem._classes[0] == "hello", err
示例#23
0
def test_widget_base_element_compile_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = "x"
    b_elem.autoclosing = True
    assert b_elem.compile() == '<x id="a">'
示例#24
0
def test_widget_base_element_sets_attributes():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', 'there')
    assert b_elem._attributes.get(
        'hello'
    ) == 'there', "BaseElement._set_attribute should set the specified attribute in BaseElement._attributes"
def test_widget_base_element_doesnt_set_attribute_when_none():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', None)
    assert 'hello' not in b_elem._attributes, 'BaseElement._set_attribute should do nothing when attribute value is None'
示例#26
0
def test_widget_base_element_compile_not_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = 'x'
    b_elem.content = "b"
    assert b_elem.compile() == '<x id="a">b</x>'
def test_widget_base_element_property_id_setter():
    b_elem = BaseElement(id='id')
    b_elem.id = 'id2'
    assert b_elem.id == 'id2', 'BaseElement.id should set the value of BaseElement._attributes["id"]'
示例#28
0
 def element(self):
     return BaseElement(id='id')
def test_widget_base_element_compile_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = "x"
    b_elem.autoclosing = True
    assert b_elem.compile() == '<x id="a">'
示例#30
0
def test_widget_base_element_property_view_getter():
    b_elem = BaseElement(id='id')
    assert b_elem.view is b_elem._view, 'BaseElement.view should return the value of internal BaseElement._view.'
def test_widget_base_element_property_view_setter():
    b_elem = BaseElement(id='id')
    b_elem.view = 42
    assert b_elem._view == 42, 'BaseElement.view should set the value of internal BaseElement._view'
示例#32
0
def test_widget_base_element_property_view_setter():
    b_elem = BaseElement(id='id')
    b_elem.view = 42
    assert b_elem._view == 42, 'BaseElement.view should set the value of internal BaseElement._view'