def test_widget_arrange_margin(root): parent = Widget(root) Widget(parent, name='child_a', y=1, x=1, position='fixed', height=10, width=10, margin={'top': 5}) Widget(parent, name='child_b', y=16, x=1, position='fixed', height=10, width=10, margin={'bottom': 2}) Widget(parent, name='child_c', y=1, x=1, position='fixed', height=10, width=10, margin={'left': 3}) Widget(parent, name='child_d', y=1, x=85, position='fixed', height=10, width=10, margin={'right': 4}) parent.render() arrangement = parent.arrange(parent.children) assert len(arrangement) == 4 _, child_a_dimensions = arrangement[0] assert child_a_dimensions == {'y': 5, 'x': 1, 'height': 10, 'width': 10} _, child_b_dimensions = arrangement[1] assert child_b_dimensions == {'y': 6, 'x': 1, 'height': 10, 'width': 10} _, child_c_dimensions = arrangement[2] assert child_c_dimensions == {'y': 1, 'x': 3, 'height': 10, 'width': 10} _, child_d_dimensions = arrangement[3] assert child_d_dimensions == {'y': 1, 'x': 76, 'height': 10, 'width': 10}
def test_widget_arrange_align(root): parent = Widget(root) Widget(parent, name='child_a', position='fixed', height=10, width=10, align='LL') Widget(parent, name='child_b', position='fixed', height=10, width=10, align='LC') Widget(parent, name='child_c', position='fixed', height=10, width=10, align='LR') Widget(parent, name='child_d', position='fixed', height=10, width=10, align='CL') Widget(parent, name='child_e', position='fixed', height=10, width=10, align='CC') Widget(parent, name='child_f', position='fixed', height=10, width=10, align='CR') Widget(parent, name='child_g', position='fixed', height=10, width=10, align='RL') Widget(parent, name='child_h', position='fixed', height=10, width=10, align='RC') Widget(parent, name='child_i', position='fixed', height=10, width=10, align='RR') parent.render() arrangement = parent.arrange(parent.children) assert len(arrangement) == 9 _, child_a_dimensions = arrangement[0] assert child_a_dimensions == {'y': 0, 'x': 0, 'height': 10, 'width': 10} _, child_b_dimensions = arrangement[1] assert child_b_dimensions == {'y': 0, 'x': 40, 'height': 10, 'width': 10} _, child_c_dimensions = arrangement[2] assert child_c_dimensions == {'y': 0, 'x': 80, 'height': 10, 'width': 10} _, child_d_dimensions = arrangement[3] assert child_d_dimensions == {'y': 4, 'x': 0, 'height': 10, 'width': 10} _, child_e_dimensions = arrangement[4] assert child_e_dimensions == {'y': 4, 'x': 40, 'height': 10, 'width': 10} _, child_f_dimensions = arrangement[5] assert child_f_dimensions == {'y': 4, 'x': 80, 'height': 10, 'width': 10} _, child_g_dimensions = arrangement[6] assert child_g_dimensions == {'y': 8, 'x': 0, 'height': 10, 'width': 10} _, child_h_dimensions = arrangement[7] assert child_h_dimensions == {'y': 8, 'x': 40, 'height': 10, 'width': 10} _, child_i_dimensions = arrangement[8] assert child_i_dimensions == {'y': 8, 'x': 80, 'height': 10, 'width': 10}
def test_modal_launch(root): parent = Widget(root) modal = Modal(parent) modal.launch() assert modal.window is None parent.render() modal.launch() assert parent.children[0] == modal assert modal.window is not None assert modal.close.window is not None
def test_widget_render_children(root): parent = Widget(root) child_a = Widget(parent) child_b = Widget(parent) child_c = Widget(parent) parent.render() curses.doupdate() assert parent.window is not None assert child_a.window is not None assert child_b.window is not None assert child_c.window is not None
def test_widget_layout_weight(root): parent = Widget(root) child_a = Widget(parent).span(2, 2) child_b = Widget(parent).grid(1, 2).span(2).weight(col=2) child_c = Widget(parent).grid(3, 4).span(col=2).weight(2) parent.render() layout = parent.layout(parent.children) assert isinstance(layout, list) assert layout[0][0] == child_a assert layout[0][1] == {'y': 0, 'x': 0, 'height': 9, 'width': 68} assert layout[1][0] == child_b assert layout[1][1] == {'y': 5, 'x': 23, 'height': 13, 'width': 45} assert layout[2][0] == child_c assert layout[2][1] == {'y': 10, 'x': 68, 'height': 8, 'width': 22}
def test_widget_layout_span(root): parent = Widget(root) child_a = Widget(parent).span(2, 2) child_b = Widget(parent).grid(1, 2).span(2) child_c = Widget(parent).grid(3, 4).span(col=2) parent.render() layout = parent.layout(parent.children) assert isinstance(layout, list) assert layout[0][0] == child_a assert layout[0][1] == {'y': 0, 'x': 0, 'height': 12, 'width': 60} assert layout[1][0] == child_b assert layout[1][1] == {'y': 6, 'x': 30, 'height': 12, 'width': 30} assert layout[2][0] == child_c assert layout[2][1] == {'y': 12, 'x': 60, 'height': 6, 'width': 30}
def test_widget_layout_with_border(root): parent = Widget(root) parent.styling.border = [0] child_a = Widget(parent).span(2, 2) child_b = Widget(parent).grid(1, 2).span(2).weight(col=2) child_c = Widget(parent).grid(3, 4).span(col=2).weight(2) parent.render() layout = parent.layout(parent.children) assert isinstance(layout, list) assert layout[0][0] == child_a assert layout[0][1] == {'y': 1, 'x': 1, 'height': 8, 'width': 66} assert layout[1][0] == child_b assert layout[1][1] == {'y': 5, 'x': 23, 'height': 12, 'width': 44} assert layout[2][0] == child_c assert layout[2][1] == {'y': 9, 'x': 67, 'height': 8, 'width': 22}
def test_widget_focus(root): parent = Widget(root).focus() assert isinstance(parent, Widget) child_a = Widget(parent).grid(0, 0) child_b = Widget(parent).grid(0, 1) assert isinstance(child_a, Widget) assert isinstance(child_b, Widget) parent.render() child_a.focus() curses.doupdate() cursor_y, cursor_x = curses.getsyx() assert (cursor_y, cursor_x) == (0, 0) child_b.focus() curses.doupdate() cursor_y, cursor_x = curses.getsyx() assert (cursor_y, cursor_x) == (0, 45)
def test_widget_layout_mode(root): parent = Widget(root, mode='compact') child_a = Widget(parent) child_b = Widget(parent).grid(1) child_c = Widget(parent).grid(2) child_d = Widget(parent).grid(3) parent.render() layout = parent.layout(parent.children) assert isinstance(layout, list) assert layout[0][0] == child_a assert layout[0][1] == {'y': 0, 'x': 0, 'height': 4, 'width': 90} assert layout[1][0] == child_b assert layout[1][1] == {'y': 4, 'x': 0, 'height': 4, 'width': 90} assert layout[2][0] == child_c assert layout[2][1] == {'y': 8, 'x': 0, 'height': 4, 'width': 90} assert layout[3][0] == child_d assert layout[3][1] == {'y': 12, 'x': 0, 'height': 4, 'width': 90}
def test_widget_update_without_window(root): root.window.resize(1, 1) widget = Widget(root) widget.content = 'Hello World' root.window = None widget = widget.render() curses.doupdate() assert isinstance(widget, Widget) assert widget.window is None
def test_widget_render_error(root): root.window.resize(1, 1) widget = Widget(root) widget.content = 'Hello World' widget = widget.render() curses.doupdate() window_text = widget.window.instr(0, 0, 1) assert window_text == b'H'
def test_widget_arrange_proportion(root): parent = Widget(root) child_a = Widget(parent, position='fixed').pin(y=5, x=5, height=5, width=5) child_b = Widget(parent) child_c = Widget( parent, position='fixed', proportion={'height': 0.8, 'width': 0.8}) assert parent.arrange(parent.children) == [] parent.render() arrangement = parent.arrange(parent.children) assert len(arrangement) == 2 _, child_a_dimensions = arrangement[0] assert child_a_dimensions == {'y': 5, 'x': 5, 'height': 5, 'width': 5} _, child_c_dimensions = arrangement[1] assert child_c_dimensions == {'y': 0, 'x': 0, 'height': 14, 'width': 72}
def test_widget_render_fixed_children(root): parent = Widget(root) child_a = Widget(parent) child_b = Widget(parent, position='fixed') child_c = Widget(parent) parent.render() curses.doupdate() assert parent.window is not None assert child_a.window is not None assert child_b.window is None assert child_c.window is not None child_b.pin(5, 5, 10, 10).render() parent.render() curses.doupdate() assert child_b.window is not None
def test_widget_render_content(root): widget = Widget(root) assert widget.content == '' content = 'Hello World' widget.content = content widget = widget.render() curses.doupdate() window_text = widget.window.instr(0, 0, 11) assert widget.content == content assert window_text == b'Hello World'
def test_widget_size(root): widget = Widget(root) assert widget.size() == (0, 0) widget.render() assert widget.size() == (18, 90)