def test_widget_link_bidirectional(): t1 = TextInput() t2 = TextInput() t1.link(t2, value='value', bidirectional=True) t1.value = 'ABC' assert t1.value == 'ABC' assert t2.value == 'ABC' t2.value = 'DEF' assert t1.value == 'DEF' assert t2.value == 'DEF'
def test_tabulator_widget_scalar_filter(document, comm): df = makeMixedDataFrame() table = Tabulator(df) model = table.get_root(document, comm) widget = TextInput(value='foo3') table.add_filter(widget, 'C') expected = { 'index': np.array([2]), 'A': np.array([2]), 'B': np.array([0]), 'C': np.array(['foo3']), 'D': np.array(['2009-01-05T00:00:00.000000000'], dtype='datetime64[ns]') } for col, values in model.source.data.items(): np.testing.assert_array_equal(values, expected[col]) widget.value = 'foo1' expected = { 'index': np.array([0]), 'A': np.array([0]), 'B': np.array([0]), 'C': np.array(['foo1']), 'D': np.array(['2009-01-01T00:00:00.000000000'], dtype='datetime64[ns]') } for col, values in model.source.data.items(): np.testing.assert_array_equal(values, expected[col])
def test_text_input_controls(): text_input = TextInput() controls = text_input.controls() assert isinstance(controls, Tabs) assert len(controls) == 2 wb1, wb2 = controls assert isinstance(wb1, WidgetBox) assert len(wb1) == 4 name, disabled, text1, text2 = wb1 if text1.name == 'Placeholder': placeholder, value = text1, text2 else: placeholder, value = text2, text1 assert isinstance(name, StaticText) assert isinstance(disabled, Checkbox) assert isinstance(value, TextInput) assert isinstance(placeholder, TextInput) text_input.disabled = True assert disabled.value text_input.placeholder = "Test placeholder..." assert placeholder.value == "Test placeholder..." text_input.value = "New value" assert value.value == "New value" assert isinstance(wb2, WidgetBox) assert len(wb2) == len(list(Layoutable.param)) + 1
def test_element_apply_dynamic_with_widget_kwarg(self): text = TextInput() applied = self.element.apply(lambda x, label: x.relabel(label), label=text) self.assertEqual(len(applied.streams), 1) self.assertEqual(applied[()].label, '') text.value = 'Test' self.assertEqual(applied[()].label, 'Test')
def test_text_input(document, comm): text = TextInput(value='ABC', name='Text:') widget = text.get_root(document, comm=comm) assert isinstance(widget, text._widget_type) assert widget.value == 'ABC' assert widget.title == 'Text:' text._comm_change({'value': 'CBA'}) assert text.value == 'CBA' text.value = 'A' assert widget.value == 'A'
def test_tabulator_function_filter(document, comm): df = makeMixedDataFrame() table = Tabulator(df) model = table.get_root(document, comm) widget = TextInput(value='foo3') def filter_c(df, value): return df[df.C.str.contains(value)] table.add_filter(bind(filter_c, value=widget), 'C') expected = { 'index': np.array([2]), 'A': np.array([2]), 'B': np.array([0]), 'C': np.array(['foo3']), 'D': np.array(['2009-01-05T00:00:00.000000000'], dtype='datetime64[ns]').astype(np.int64) / 10e5 } for col, values in model.source.data.items(): np.testing.assert_array_equal(values, expected[col]) widget.value = 'foo1' expected = { 'index': np.array([0]), 'A': np.array([0]), 'B': np.array([0]), 'C': np.array(['foo1']), 'D': np.array(['2009-01-01T00:00:00.000000000'], dtype='datetime64[ns]').astype(np.int64) / 10e5 } for col, values in model.source.data.items(): np.testing.assert_array_equal(values, expected[col])
def test_text_input(document, comm): text = TextInput(value='ABC', name='Text:') box = text._get_model(document, comm=comm) assert isinstance(box, WidgetBox) widget = box.children[0] assert isinstance(widget, text._widget_type) assert widget.value == 'ABC' assert widget.title == 'Text:' text._comm_change({'value': 'CBA'}) assert text.value == 'CBA' text.value = 'A' assert widget.value == 'A'
def test_widget_triggers_events(document, comm): """ Ensure widget events don't get swallowed in comm mode """ text = TextInput(value='ABC', name='Text:') widget = text.get_root(document, comm=comm) document.add_root(widget) document.hold() # Simulate client side change document._held_events = document._held_events[:-1] # Set new value with block_comm(): text.value = '123' assert len(document._held_events) == 1 event = document._held_events[0] assert event.attr == 'value' assert event.model is widget assert event.new == '123'
def test_text_input_controls(): text_input = TextInput() controls = text_input.controls() assert isinstance(controls, Tabs) assert len(controls) == 2 wb1, wb2 = controls assert isinstance(wb1, WidgetBox) assert len(wb1) == 7 name, disabled, visible, *(ws) = wb1 assert isinstance(name, StaticText) assert isinstance(disabled, Checkbox) assert isinstance(visible, Checkbox) not_checked = [] for w in ws: print(w.name) if w.name == 'Value': assert isinstance(w, TextInput) text_input.value = "New value" assert w.value == "New value" elif w.name == 'Value input': assert isinstance(w, TextInput) elif w.name == 'Placeholder': assert isinstance(w, TextInput) text_input.placeholder = "Test placeholder..." assert w.value == "Test placeholder..." elif w.name == 'Max length': assert isinstance(w, IntInput) else: not_checked.append(w) assert not not_checked assert isinstance(wb2, WidgetBox) assert len(wb2) == len(list(Viewable.param)) + 1