Beispiel #1
0
def test_apply_style_attributes(attrs: list, expected: dict):
    """should set attribute values"""
    attrs = [XmlAttr(attr[0], attr[1], attr[2]) for attr in attrs]
    xml_node = Mock(attrs=attrs)
    node = TtkStyle(xml_node)
    setup_value_setter(node, TkRenderingContext())

    apply_style_attributes(node, TkRenderingContext())

    assert node.values == expected
Beispiel #2
0
def test_setup_event_binding_should_restore_bind():
    """setup_event_binding() should restore canvas bind method"""
    canvas = Mock()
    canvas.bind = Mock()

    setup_temp_binding(canvas, TkRenderingContext())
    setup_event_binding(canvas, TkRenderingContext())
    canvas.bind()

    assert canvas.bind.called
Beispiel #3
0
    def test_raises_if_name_is_not_set(name):
        """should raise if name is not set"""
        with raises(KeyError):
            node = TtkStyle(Mock())
            node.name = name

            configure(node, TkRenderingContext())
Beispiel #4
0
    def test_sets_values(values: dict):
        """should set setter that sets to "values" property"""
        node = TtkStyle(Mock())

        setup_value_setter(node, TkRenderingContext())
        for key, value in values.items():
            node.set_attr(key, value)

        assert node.values == values
Beispiel #5
0
    def test_sets_name():
        """should set setter that sets node properties"""
        node = TtkStyle(Mock())
        name = 'some_name'

        setup_value_setter(node, TkRenderingContext())
        node.set_attr('name', name)

        assert node.name == name
Beispiel #6
0
    def test_configures(self, name: str, values: dict):
        """configure should call configure on ttk style and pass values"""
        node = TtkStyle(Mock())
        node.values = values
        node.name = name

        configure(node, TkRenderingContext())

        assert self.configure.call_args == call(node.full_name, **node.values)
Beispiel #7
0
def test_setup_config_setter_calls_config(key, value):
    """setup_config_setter() should set setter that calls config method"""
    canvas = TestCanvasNode(Mock(), Mock())
    canvas.config = Mock()

    setup_config_setter(canvas, TkRenderingContext())

    canvas.set_attr(key, value)
    assert canvas.config.call_args == call(**{key: value})
Beispiel #8
0
def test_create_item_calls_create():
    """create_item( should call create method of CanvasNode"""
    canvas = Mock()
    canvas.create = Mock()
    canvas.attr_values = {}

    create_item(canvas, TkRenderingContext())

    assert canvas.create.called
Beispiel #9
0
def test_setup_temp_binding_stores_commands(events):
    """setup_temp_binding() should set bind that stores callbacks it events property"""
    canvas = TestCanvasNode(Mock(), Mock())

    setup_temp_binding(canvas, TkRenderingContext())

    for key, command in events.items():
        canvas.bind(key, command)
    assert canvas.events == events
Beispiel #10
0
def test_setup_temp_setter(attrs: dict):
    """setup_temp_setter() should set setter that stores attrs it attr_values property"""
    canvas = TestCanvasNode(Mock(), Mock())

    setup_temp_setter(canvas, TkRenderingContext())

    for key, value in attrs.items():
        canvas.set_attr(key, value)
    assert canvas.attr_values == attrs
Beispiel #11
0
def test_apply_temp_events_should_bind(events: dict):
    """apply_temp_events() should bind events stored in temp dictionary"""
    canvas = Mock()
    canvas.bind = Mock()
    canvas.events = events

    apply_temp_events(canvas, TkRenderingContext())

    expected_calls = [call(event, command) for event, command in events.items()]
    assert canvas.bind.call_args_list == expected_calls
Beispiel #12
0
def test_clear_temp_deletes_temp_vars():
    """clear_temp() should delete temp properties"""
    canvas = TestCanvasNode(Mock(), Mock())
    canvas.attr_values = {}
    canvas.events = {}
    canvas.bind_source = {}

    clear_temp(canvas, TkRenderingContext())

    assert not hasattr(canvas, 'attr_values')
    assert not hasattr(canvas, 'events')
    assert not hasattr(canvas, 'bind_source')
Beispiel #13
0
def _get_child_context(xml_node: XmlNode, node: Scroll, _: TkRenderingContext):
    child_context = TkRenderingContext()
    child_context.xml_node = xml_node
    child_context.parent_node = node
    child_context.node_globals = node.node_globals
    child_context.master = node.container
    return child_context
Beispiel #14
0
def launch(root_view=None):
    """Runs application. Widgets are created from passed xml_files"""
    root_view = 'root' if root_view is None else root_view
    root: Root = cast(Root, render_view(root_view, TkRenderingContext()))
    root.instance.mainloop()