def test_to(self): other = self.month - 1 self.assertEqual(self.month.to(other), [self.month, other]) other = (2004, 5) self.assertEqual(self.month.to(*other)[-1], Month(*other)) self.assertEqual(self.month.to(other)[-1], Month(*other)) other = datetime.date(2004, 5, 10) self.assertEqual(self.month.to(other)[-1], Month.from_date(other))
# This is the project to impliment a simple Calender with some functionality # These are the import statements import time import os from months import Month from date import notes from tkinter import * m = Month() n = notes() root = Tk() def display_calender(date, month, year): month_no = get_month_no(month) month_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if m.leap == True: month_day[1] = 29 days = month_day[month_no - 1] print('\033[1m%16s' % (month), '%5s' % (year)) day_names = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] x = day_names.index(m.starting_day) for j in day_names: lable = Label(root, text=j) lable.pack(side=LEFT) print('\033[1;37;40m %3s \033[30;0m' % (j), end='') print('\n' + ' ' * 5 * x, end='') j = x + 1 for i in range(1, days + 1): if int(date) == i: lable = Label(root, text=i)
def make_month_list(self): self.month_list.append(Month("January", 1, 31, None, None)) self.month_list.append(Month("February", 2, 28, None, None)) self.month_list.append(Month("March", 3, 31, 14, "Pi Day")) self.month_list.append(Month("April", 4, 30, None, None)) self.month_list.append(Month("May", 5, 31, None, None)) self.month_list.append(Month("June", 6, 30, None, None)) self.month_list.append(Month("July", 7, 31, None, None)) self.month_list.append(Month("August", 8, 31, None, None)) self.month_list.append(Month("September", 9, 30, None, None)) self.month_list.append(Month("October", 10, 31, None, None)) self.month_list.append(Month("November", 11, 30, None, None)) self.month_list.append(Month("December", 12, 31, None, None))
def test_sub(self): self.assertEqual(self.month - 1, Month(2015, 3))
def test_sub_rollover(self): self.assertEqual(self.month - 4, Month(2014, 12))
def test_add(self): self.assertEqual(self.month + 1, Month(2015, 5))
def test_add_rollover(self): self.assertEqual(self.month + 9, Month(2016, 1))
def test_from_date(self): self.assertEqual(self.month, Month.from_date(self.date))
def setUp(self): self.datetime = datetime.datetime(2015, 4, 15) self.date = self.datetime.date() self.month = Month(2015, 4)
class TestMonths(unittest.TestCase): def setUp(self): self.datetime = datetime.datetime(2015, 4, 15) self.date = self.datetime.date() self.month = Month(2015, 4) def test_repr(self): self.assertEqual(repr(self.month), 'Month(2015, 4)') def test_str(self): self.assertEqual(str(self.month), '2015-04') def test_int(self): self.assertEqual(int(self.month), 201504) def test_float(self): self.assertEqual(float(self.month), 201504.0) def test_month_name(self): self.assertEqual(self.month.month_name, 'April') def test_month_abbr(self): self.assertEqual(self.month.month_abbr, 'Apr') def test_full_display(self): self.assertEqual(self.month.full_display, 'April 2015') def test_abbr_display(self): self.assertEqual(self.month.abbr_display, 'Apr 2015') def test_from_datetime(self): self.assertEqual(self.month, Month.from_date(self.datetime)) def test_from_date(self): self.assertEqual(self.month, Month.from_date(self.date)) def test_add(self): self.assertEqual(self.month + 1, Month(2015, 5)) def test_add_rollover(self): self.assertEqual(self.month + 9, Month(2016, 1)) def test_add_raises(self): self.assertRaises(ValueError, self.month.__add__, 'not_an_int') def test_sub(self): self.assertEqual(self.month - 1, Month(2015, 3)) def test_sub_rollover(self): self.assertEqual(self.month - 4, Month(2014, 12)) def test_sub_raises(self): self.assertRaises(ValueError, self.month.__sub__, 'not_an_int') def test_start_date(self): self.assertEqual(self.month.start_date, self.date.replace(day=1)) def test_end_date(self): self.assertEqual(self.month.end_date, self.date.replace(day=30)) def test_range(self): self.assertEqual(self.month.range, (self.date.replace(day=1), self.date.replace(day=30))) def test_dates(self): self.assertEqual(self.month.dates[0], self.month.start_date) def test_n_days(self): self.assertEqual(self.month.n_days, len(self.month.dates)) def test_nth(self): self.assertEqual(self.month.nth(-1), self.month.end_date) def test_to(self): other = self.month - 1 self.assertEqual(self.month.to(other), [self.month, other]) other = (2004, 5) self.assertEqual(self.month.to(*other)[-1], Month(*other)) self.assertEqual(self.month.to(other)[-1], Month(*other)) other = datetime.date(2004, 5, 10) self.assertEqual(self.month.to(other)[-1], Month.from_date(other)) def test_distance(self): d = 10 self.assertEqual(self.month.distance(self.month + d), d) self.assertEqual(self.month.distance(self.month - d), d) other_tup = ((self.month - d).year, (self.month - d).month) self.assertEqual(self.month.distance(*other_tup), d) self.assertEqual(self.month.distance(other_tup), d) other_dt = (self.month - d).nth(5) self.assertEqual(self.month.distance(other_dt), d) def test_gregorian_number(self): self.assertEqual(Month(1, 1).gregorian_month_number, 1) self.assertEqual(Month(-1, 2).gregorian_month_number, -2) self.assertEqual(Month(2, 2).gregorian_month_number, 14) def tearDown(self): pass
def test_gregorian_number(self): self.assertEqual(Month(1, 1).gregorian_month_number, 1) self.assertEqual(Month(-1, 2).gregorian_month_number, -2) self.assertEqual(Month(2, 2).gregorian_month_number, 14)