def test_calendar_get_set(self): widget = Calendar(self.window, foreground="red") widget.pack() self.window.update() options = [ 'cursor', 'font', 'borderwidth', 'selectmode', 'locale', 'selectbackground', 'selectforeground', 'normalbackground', 'normalforeground', 'background', 'foreground', 'bordercolor', 'othermonthforeground', 'othermonthbackground', 'othermonthweforeground', 'othermonthwebackground', 'weekendbackground', 'weekendforeground', 'headersbackground', 'headersforeground' ] self.assertEqual(sorted(widget.keys()), sorted(options)) with self.assertRaises(AttributeError): widget.cget("test") self.assertEqual(widget["foreground"], "red") widget["foreground"] = "blue" self.window.update() self.assertEqual(widget["foreground"], "blue") widget.config(cursor="watch") self.window.update() self.assertEqual(widget["cursor"], "watch") widget.config(font="Arial 20 bold") self.window.update() self.assertEqual(widget["font"], "Arial 20 bold") widget.config(borderwidth=5) self.window.update() self.assertEqual(widget["borderwidth"], 5) with self.assertRaises(ValueError): widget.config(borderwidth="a") widget.config(selectmode="none") self.window.update() self.assertEqual(widget["selectmode"], "none") widget.config(selectmode="day") self.window.update() self.assertEqual(widget["selectmode"], "day") with self.assertRaises(ValueError): widget.config(selectmode="a") with self.assertRaises(AttributeError): widget.config(locale="en_US.UTF-8") with self.assertRaises(AttributeError): widget.config(test="test") dic = {op: "yellow" for op in options[5:]} widget.configure(**dic) self.window.update() for op in options[5:]: self.assertEqual(widget.cget(op), "yellow")
def test_calendar_get_set(self): widget = Calendar(self.window, foreground="red") widget.pack() self.window.update() options = [ 'cursor', 'font', 'borderwidth', 'state', 'selectmode', 'textvariable', 'locale', 'showweeknumbers', 'selectbackground', 'selectforeground', 'disabledselectbackground', 'disabledselectforeground', 'normalbackground', 'normalforeground', 'background', 'foreground', 'bordercolor', 'othermonthforeground', 'othermonthbackground', 'othermonthweforeground', 'othermonthwebackground', 'weekendbackground', 'weekendforeground', 'headersbackground', 'headersforeground', 'disableddaybackground', 'disableddayforeground' ] self.assertEqual(sorted(widget.keys()), sorted(options)) with self.assertRaises(AttributeError): widget.cget("test") self.assertEqual(widget["foreground"], "red") widget["foreground"] = "blue" self.window.update() self.assertEqual(widget["foreground"], "blue") widget.config(cursor="watch") self.window.update() self.assertEqual(widget["cursor"], "watch") self.assertTrue(widget["showweeknumbers"]) widget.config(showweeknumbers=False) self.window.update() self.assertFalse(widget["showweeknumbers"]) self.assertFalse(widget._week_nbs[0].winfo_ismapped()) widget.config(font="Arial 20 bold") self.window.update() self.assertEqual(widget["font"], "Arial 20 bold") widget.config(borderwidth=5) self.window.update() self.assertEqual(widget["borderwidth"], 5) with self.assertRaises(ValueError): widget.config(borderwidth="a") widget.config(selectmode="none") self.window.update() self.assertEqual(widget["selectmode"], "none") widget.config(selectmode="day") self.window.update() self.assertEqual(widget["selectmode"], "day") with self.assertRaises(ValueError): widget.config(selectmode="a") self.assertEqual(widget.cget('state'), tk.NORMAL) with self.assertRaises(ValueError): widget.config(state="test") with self.assertRaises(AttributeError): widget.config(locale="en_US.UTF-8") with self.assertRaises(AttributeError): widget.config(test="test") dic = {op: "yellow" for op in options[7:]} widget.configure(**dic) self.window.update() for op in options[7:]: self.assertEqual(widget.cget(op), "yellow")
def test_calendar_get_set(self): widget = Calendar(self.window, foreground="red", year=2010, month=1, day=3) widget.pack() self.window.update() options = [ 'cursor', 'font', 'borderwidth', 'state', 'selectmode', 'textvariable', 'locale', 'date_pattern', 'mindate', 'maxdate', 'firstweekday', 'weekenddays', 'showweeknumbers', 'showothermonthdays', 'selectbackground', 'selectforeground', 'disabledselectbackground', 'disabledselectforeground', 'normalbackground', 'normalforeground', 'background', 'foreground', 'bordercolor', 'disabledbackground', 'disabledforeground', 'othermonthforeground', 'othermonthbackground', 'othermonthweforeground', 'othermonthwebackground', 'weekendbackground', 'weekendforeground', 'headersbackground', 'headersforeground', 'disableddaybackground', 'disableddayforeground', 'tooltipbackground', 'tooltipforeground', 'tooltipalpha', 'tooltipdelay' ] self.assertEqual(sorted(widget.keys()), sorted(options)) with self.assertRaises(AttributeError): widget.cget("test") self.assertEqual(widget["foreground"], "red") widget["foreground"] = "blue" self.window.update() self.assertEqual(widget["foreground"], "blue") widget.configure({ 'foreground': 'cyan', 'background': 'green' }, background="blue", borderwidth=4) self.window.update() self.assertEqual(widget["foreground"], "cyan") self.assertEqual(widget["background"], "blue") self.assertEqual(widget["borderwidth"], 4) widget.config(locale='fr_FR') self.assertEqual(widget['locale'], 'fr_FR') self.assertEqual(widget._week_days[0].cget('text'), 'lun.') widget.config(locale='en_US') self.assertEqual(widget['locale'], 'en_US') self.assertEqual(widget._week_days[0].cget('text'), 'Mon') with self.assertRaises(UnknownLocaleError): widget.config(locale="jp") widget.config(cursor="watch") self.window.update() self.assertEqual(widget["cursor"], "watch") self.assertTrue(widget["showweeknumbers"]) self.assertNotEqual(widget._week_nbs[0].grid_info(), {}) widget.config(showweeknumbers=False) self.window.update() self.assertFalse(widget["showweeknumbers"]) self.assertEqual(widget._week_nbs[0].grid_info(), {}) self.assertFalse(widget._week_nbs[0].winfo_ismapped()) self.assertNotEqual(widget._calendar[-1][-1].cget('text'), '') self.assertTrue(widget["showothermonthdays"]) widget.config(showothermonthdays=False) self.window.update() self.assertFalse(widget["showothermonthdays"]) self.assertEqual(widget._calendar[-1][-1].cget('text'), '') widget.config(font="Arial 20 bold") self.window.update() self.assertEqual(widget["font"], "Arial 20 bold") widget.config(borderwidth=5) self.window.update() self.assertEqual(widget["borderwidth"], 5) with self.assertRaises(ValueError): widget.config(borderwidth="a") widget.config(firstweekday='sunday') self.window.update() self.assertEqual(widget["firstweekday"], 'sunday') with self.assertRaises(ValueError): widget.config(firstweekday="a") widget.config(weekenddays=[5, 7]) self.window.update() we_style = 'we.%s.TLabel' % widget._style_prefixe normal_style = 'normal.%s.TLabel' % widget._style_prefixe for i in range(7): self.assertEqual(widget._calendar[0][i].cget('style'), we_style if (i + 1) in [5, 7] else normal_style) widget["mindate"] = datetime(2018, 9, 10) self.assertEqual(widget["mindate"], date(2018, 9, 10)) widget.selection_set(date(2018, 9, 23)) self.window.update() i, j = widget._get_day_coords(date(2018, 9, 2)) self.assertIn('disabled', widget._calendar[i][j].state()) i, j = widget._get_day_coords(date(2018, 9, 21)) self.assertNotIn('disabled', widget._calendar[i][j].state()) self.assertIn('disabled', widget._l_month.state()) self.assertIn('disabled', widget._l_year.state()) i, j = widget._get_day_coords(date(2018, 9, 10)) self.assertNotIn('disabled', widget._calendar[i][j].state()) i, j = widget._get_day_coords(date(2018, 9, 9)) self.assertIn('disabled', widget._calendar[i][j].state()) with self.assertRaises(TypeError): widget.config(mindate="a") self.assertEqual(widget["mindate"], date(2018, 9, 10)) widget["mindate"] = None self.window.update() self.assertIsNone(widget["mindate"]) i, j = widget._get_day_coords(date(2018, 9, 2)) self.assertNotIn('disabled', widget._calendar[i][j].state()) self.assertNotIn('disabled', widget._l_month.state()) self.assertNotIn('disabled', widget._l_year.state()) widget["maxdate"] = datetime(2018, 9, 10) self.assertEqual(widget["maxdate"], date(2018, 9, 10)) widget.selection_set(date(2018, 9, 2)) self.window.update() i, j = widget._get_day_coords(date(2018, 9, 22)) self.assertIn('disabled', widget._calendar[i][j].state()) i, j = widget._get_day_coords(date(2018, 9, 4)) self.assertNotIn('disabled', widget._calendar[i][j].state()) self.assertIn('disabled', widget._r_month.state()) self.assertIn('disabled', widget._r_year.state()) i, j = widget._get_day_coords(date(2018, 9, 10)) self.assertNotIn('disabled', widget._calendar[i][j].state()) i, j = widget._get_day_coords(date(2018, 9, 11)) self.assertIn('disabled', widget._calendar[i][j].state()) with self.assertRaises(TypeError): widget.config(maxdate="a") self.assertEqual(widget["maxdate"], date(2018, 9, 10)) widget["maxdate"] = None self.window.update() self.assertIsNone(widget["maxdate"]) i, j = widget._get_day_coords(date(2018, 9, 22)) self.assertNotIn('disabled', widget._calendar[i][j].state()) self.assertNotIn('disabled', widget._r_month.state()) self.assertNotIn('disabled', widget._r_year.state()) widget.config(selectmode="none") self.window.update() self.assertEqual(widget["selectmode"], "none") widget.config(selectmode="day") self.window.update() self.assertEqual(widget["selectmode"], "day") with self.assertRaises(ValueError): widget.config(selectmode="a") self.assertEqual(widget.cget('state'), tk.NORMAL) with self.assertRaises(ValueError): widget.config(state="test") widget['date_pattern'] = 'MM/dd/yyyy' self.window.update() self.assertEqual(widget["date_pattern"], 'MM/dd/yyyy') with self.assertRaises(ValueError): widget.config(date_pattern="mm-dd-cc") with self.assertRaises(AttributeError): widget.config(test="test") dic = {op: "yellow" for op in options[12:-4]} widget.configure(**dic) self.window.update() for op in options[12:-4]: self.assertEqual(widget.cget(op), "yellow") widget.config(tooltipalpha=0.5) self.assertEqual(widget["tooltipalpha"], 0.5) self.assertEqual(widget.tooltip_wrapper["alpha"], 0.5) widget.config(tooltipdelay=1000) self.assertEqual(widget["tooltipdelay"], 1000) self.assertEqual(widget.tooltip_wrapper["delay"], 1000) widget.config(tooltipforeground='black') self.assertEqual(widget["tooltipforeground"], 'black') widget.config(tooltipbackground='cyan') self.assertEqual(widget["tooltipbackground"], 'cyan')
def test_calendar_get_set(self): widget = Calendar(self.window, foreground="red") widget.pack() self.window.update() options = [ 'cursor', 'font', 'borderwidth', 'state', 'selectmode', 'textvariable', 'locale', 'firstweekday', 'showweeknumbers', 'showothermonthdays', 'selectbackground', 'selectforeground', 'disabledselectbackground', 'disabledselectforeground', 'normalbackground', 'normalforeground', 'background', 'foreground', 'bordercolor', 'othermonthforeground', 'othermonthbackground', 'othermonthweforeground', 'othermonthwebackground', 'weekendbackground', 'weekendforeground', 'headersbackground', 'headersforeground', 'disableddaybackground', 'disableddayforeground', 'tooltipbackground', 'tooltipforeground', 'tooltipalpha', 'tooltipdelay' ] self.assertEqual(sorted(widget.keys()), sorted(options)) with self.assertRaises(AttributeError): widget.cget("test") self.assertEqual(widget["foreground"], "red") widget["foreground"] = "blue" self.window.update() self.assertEqual(widget["foreground"], "blue") widget.config(cursor="watch") self.window.update() self.assertEqual(widget["cursor"], "watch") self.assertTrue(widget["showweeknumbers"]) self.assertNotEqual(widget._week_nbs[0].grid_info(), {}) widget.config(showweeknumbers=False) self.window.update() self.assertFalse(widget["showweeknumbers"]) self.assertEqual(widget._week_nbs[0].grid_info(), {}) self.assertFalse(widget._week_nbs[0].winfo_ismapped()) self.assertNotEqual(widget._calendar[-1][-1].cget('text'), '') self.assertTrue(widget["showothermonthdays"]) widget.config(showothermonthdays=False) self.window.update() self.assertFalse(widget["showothermonthdays"]) self.assertEqual(widget._calendar[-1][-1].cget('text'), '') widget.config(font="Arial 20 bold") self.window.update() self.assertEqual(widget["font"], "Arial 20 bold") widget.config(borderwidth=5) self.window.update() self.assertEqual(widget["borderwidth"], 5) with self.assertRaises(ValueError): widget.config(borderwidth="a") widget.config(firstweekday='sunday') self.window.update() self.assertEqual(widget["firstweekday"], 'sunday') with self.assertRaises(ValueError): widget.config(firstweekday="a") widget.config(selectmode="none") self.window.update() self.assertEqual(widget["selectmode"], "none") widget.config(selectmode="day") self.window.update() self.assertEqual(widget["selectmode"], "day") with self.assertRaises(ValueError): widget.config(selectmode="a") self.assertEqual(widget.cget('state'), tk.NORMAL) with self.assertRaises(ValueError): widget.config(state="test") with self.assertRaises(AttributeError): widget.config(locale="en_US.UTF-8") with self.assertRaises(AttributeError): widget.config(test="test") dic = {op: "yellow" for op in options[8:-4]} widget.configure(**dic) self.window.update() for op in options[8:-4]: self.assertEqual(widget.cget(op), "yellow") widget.config(tooltipalpha=0.5) self.assertEqual(widget["tooltipalpha"], 0.5) self.assertEqual(widget.tooltip_wrapper["alpha"], 0.5) widget.config(tooltipdelay=1000) self.assertEqual(widget["tooltipdelay"], 1000) self.assertEqual(widget.tooltip_wrapper["delay"], 1000) widget.config(tooltipforeground='black') self.assertEqual(widget["tooltipforeground"], 'black') widget.config(tooltipbackground='cyan') self.assertEqual(widget["tooltipbackground"], 'cyan')