def test_calendar_virtual_events(self): widget = Calendar(self.window, year=2010, month=1, day=3) widget.pack() self.window.update() self.event_triggered = False def binding(event): self.event_triggered = True widget.bind('<<CalendarSelected>>', binding) widget._on_click(TestEvent(widget=widget._calendar[2][1])) self.window.update() self.assertTrue(self.event_triggered) widget.bind('<<CalendarMonthChanged>>', binding) self.event_triggered = False widget._l_month.invoke() self.window.update() self.assertTrue(self.event_triggered) self.event_triggered = False widget._r_month.invoke() self.window.update() self.assertTrue(self.event_triggered) self.event_triggered = False widget._l_year.invoke() self.window.update() self.assertTrue(self.event_triggered) self.event_triggered = False widget._r_year.invoke() self.window.update() self.assertTrue(self.event_triggered)
def test_calendar_buttons_functions(self): widget = Calendar(self.window) widget.pack() widget._prev_month() widget._next_month() widget._prev_year() widget._next_year() widget._remove_selection() widget.selection_set(format_date(date(2018, 12, 31), 'short')) self.assertEqual(widget.selection_get(), date(2018, 12, 31)) with self.assertRaises(ValueError): widget.selection_set("ab") widget.selection_set(None) self.assertIsNone(widget.selection_get()) widget.selection_set(date(2015, 12, 31)) self.assertEqual(widget.selection_get(), date(2015, 12, 31)) widget.config(selectmode='none') self.assertIsNone(widget.selection_get()) l = ttk.Label(widget, text="12") widget._on_click(TestEvent(widget=l)) self.assertIsNone(widget.selection_get()) self.window.update() widget.config(selectmode='day') l = ttk.Label(widget, text="12") widget._on_click(TestEvent(widget=l)) self.window.update() self.assertEqual(widget.selection_get(), date(2015, 12, 12)) widget.config(state='disabled') l = ttk.Label(widget, text="14") widget._on_click(TestEvent(widget=l)) self.window.update() self.assertEqual(widget.selection_get(), date(2015, 12, 12))
def test_calendar_buttons_functions(self): widget = Calendar(self.window) widget.pack() widget._prev_month() widget._next_month() widget._prev_year() widget._next_year() widget._remove_selection() widget.selection_set(datetime(2018, 12, 31).strftime('%x')) self.assertEqual(widget.selection_get(), datetime(2018, 12, 31)) with self.assertRaises(ValueError): widget.selection_set("ab") widget.selection_set(None) self.assertIsNone(widget.selection_get()) widget.selection_set(datetime(2015, 12, 31)) self.assertEqual(widget.selection_get(), datetime(2015, 12, 31)) widget.config(selectmode='none') self.assertIsNone(widget.selection_get()) l = ttk.Label(widget, text="12") widget._on_click(TestEvent(widget=l))