def test_leap_year(self): # 2004 is a leap year, because it is divisible by 4 now = datetime(2004, 3, 1, 0, 0, 0, 0) datetimes_2004 = [ datetime(2004, 3, 1, 0, 0, 0, 0), datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 2, 28, 0, 0, 0, 0), datetime(2004, 2, 27, 0, 0, 0, 0), ] self.assertEqual(Days.filter(datetimes_2004, number=1, now=now), set([datetime(2004, 3, 1, 0, 0, 0, 0)])) self.assertEqual( Days.filter(datetimes_2004, number=2, now=now), set([ datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 3, 1, 0, 0, 0, 0) ])) self.assertEqual( Days.filter(datetimes_2004, number=3, now=now), set([ datetime(2004, 2, 28, 0, 0, 0, 0), datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 3, 1, 0, 0, 0, 0) ]))
def test_not_leap_year(self): # 1900 was not a leap year, because it is divisible by 400 now = datetime(1900, 3, 1, 0, 0, 0, 0) datetimes_1900 = [ datetime(1900, 3, 1, 0, 0, 0, 0), datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 2, 27, 0, 0, 0, 0), ] self.assertEqual(Days.filter(datetimes_1900, number=1, now=now), set([datetime(1900, 3, 1, 0, 0, 0, 0)])) self.assertEqual( Days.filter(datetimes_1900, number=2, now=now), set([ datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 3, 1, 0, 0, 0, 0) ])) self.assertEqual( Days.filter(datetimes_1900, number=3, now=now), set([ datetime(1900, 2, 27, 0, 0, 0, 0), datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 3, 1, 0, 0, 0, 0) ]))
def test_all_input(self): self.assertEqual(Days.filter(self.datetimes, number=5, now=self.now), set([datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0)])) self.assertEqual(Days.filter(self.datetimes, number=6, now=self.now), set([datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_before_start(self): # datetime(1999, 12, 28, 0, 0, 0, 0) is too old to show up # in the results self.assertEqual(Days.filter(self.datetimes, number=4, now=self.now), set([datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_with_date(self): today = date(2000, 1, 1) self.assertEqual(Days.filter(self.datetimes, number=5, now=today), set([datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_duplicates(self): # Ensure we get the oldest per-day datetime when there are # duplicates: i.e. not datetime(2000, 1, 1, 1, 0, 0, 0) self.assertEqual( Days.filter(self.datetimes, number=2, now=self.now), set([ datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0) ]))
def test_all_input(self): self.assertEqual( Days.filter(self.datetimes, number=5, now=self.now), set([ datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0) ])) self.assertEqual( Days.filter(self.datetimes, number=6, now=self.now), set([ datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0) ]))
def test_before_start(self): # datetime(1999, 12, 28, 0, 0, 0, 0) is too old to show up # in the results self.assertEqual( Days.filter(self.datetimes, number=4, now=self.now), set([ datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0) ]))
def test_with_date(self): today = date(2000, 1, 1) self.assertEqual( Days.filter(self.datetimes, number=5, now=today), set([ datetime(1999, 12, 28, 0, 0, 0, 0), datetime(1999, 12, 30, 0, 0, 0, 0), datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0) ]))
def test_not_leap_year(self): # 1900 was not a leap year, because it is divisible by 400 now = datetime(1900, 3, 1, 0, 0, 0, 0) datetimes_1900 = [ datetime(1900, 3, 1, 0, 0, 0, 0), datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 2, 27, 0, 0, 0, 0), ] self.assertEqual(Days.filter(datetimes_1900, number=1, now=now), set([datetime(1900, 3, 1, 0, 0, 0, 0)])) self.assertEqual(Days.filter(datetimes_1900, number=2, now=now), set([datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 3, 1, 0, 0, 0, 0)])) self.assertEqual(Days.filter(datetimes_1900, number=3, now=now), set([datetime(1900, 2, 27, 0, 0, 0, 0), datetime(1900, 2, 28, 0, 0, 0, 0), datetime(1900, 3, 1, 0, 0, 0, 0)]))
def test_leap_year(self): # 2004 is a leap year, because it is divisible by 4 now = datetime(2004, 3, 1, 0, 0, 0, 0) datetimes_2004 = [ datetime(2004, 3, 1, 0, 0, 0, 0), datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 2, 28, 0, 0, 0, 0), datetime(2004, 2, 27, 0, 0, 0, 0), ] self.assertEqual(Days.filter(datetimes_2004, number=1, now=now), set([datetime(2004, 3, 1, 0, 0, 0, 0)])) self.assertEqual(Days.filter(datetimes_2004, number=2, now=now), set([datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 3, 1, 0, 0, 0, 0)])) self.assertEqual(Days.filter(datetimes_2004, number=3, now=now), set([datetime(2004, 2, 28, 0, 0, 0, 0), datetime(2004, 2, 29, 0, 0, 0, 0), datetime(2004, 3, 1, 0, 0, 0, 0)]))
def test_with_tzinfo_and_date(self): tzinfo_datetimes = [ utcdatetime(2000, 1, 1, 1, 0, 0, 0), utcdatetime(2000, 1, 1, 0, 0, 0, 0), utcdatetime(1999, 12, 31, 23, 59, 59, 999999), utcdatetime(1999, 12, 30, 0, 0, 0, 0), utcdatetime(1999, 12, 28, 0, 0, 0, 0), ] today = date(2000, 1, 1) self.assertEqual(Days.filter(tzinfo_datetimes, number=5, now=today), set([utcdatetime(1999, 12, 28, 0, 0, 0, 0), utcdatetime(1999, 12, 30, 0, 0, 0, 0), utcdatetime(1999, 12, 31, 23, 59, 59, 999999), utcdatetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_with_tzinfo_and_date(self): tzinfo_datetimes = [ utcdatetime(2000, 1, 1, 1, 0, 0, 0), utcdatetime(2000, 1, 1, 0, 0, 0, 0), utcdatetime(1999, 12, 31, 23, 59, 59, 999999), utcdatetime(1999, 12, 30, 0, 0, 0, 0), utcdatetime(1999, 12, 28, 0, 0, 0, 0), ] today = date(2000, 1, 1) self.assertEqual( Days.filter(tzinfo_datetimes, number=5, now=today), set([ utcdatetime(1999, 12, 28, 0, 0, 0, 0), utcdatetime(1999, 12, 30, 0, 0, 0, 0), utcdatetime(1999, 12, 31, 23, 59, 59, 999999), utcdatetime(2000, 1, 1, 0, 0, 0, 0) ]))
def test_no_results(self): self.assertEqual(Days.filter([self.now], number=0, now=self.now), set()) self.assertEqual(Days.filter(self.datetimes, number=0, now=self.now), set())
def test_current(self): self.assertEqual(Days.filter(self.datetimes, number=1, now=self.now), set([datetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_no_input(self): self.assertEqual(Days.filter([], number=1, now=self.now), set())
def test_duplicates(self): # Ensure we get the oldest per-day datetime when there are # duplicates: i.e. not datetime(2000, 1, 1, 1, 0, 0, 0) self.assertEqual(Days.filter(self.datetimes, number=2, now=self.now), set([datetime(1999, 12, 31, 23, 59, 59, 999999), datetime(2000, 1, 1, 0, 0, 0, 0)]))
def test_future(self): datetimes = [datetime(2010, 1, 15, 0, 0, 0, 0)] # Wikipedia self.assertEqual(Days.filter(datetimes, number=0, now=self.now), set(datetimes)) self.assertEqual(Days.filter(datetimes, number=1, now=self.now), set(datetimes))