Ejemplo n.º 1
0
    def test_all_input(self):
        self.assertEqual(Weeks.filter(self.datetimes, number=5, now=self.now),
                         set([datetime(1999, 12, 4, 0, 0, 0, 0),
                              datetime(1999, 12, 18, 0, 0, 0, 0),
                              datetime(1999, 12, 31, 23, 59, 59, 999999),
                              datetime(2000, 1, 1, 0, 0, 0, 0)]))

        self.assertEqual(Weeks.filter(self.datetimes, number=6, now=self.now),
                         set([datetime(1999, 12, 4, 0, 0, 0, 0),
                              datetime(1999, 12, 18, 0, 0, 0, 0),
                              datetime(1999, 12, 31, 23, 59, 59, 999999),
                              datetime(2000, 1, 1, 0, 0, 0, 0)]))
Ejemplo n.º 2
0
 def test_before_start(self):
     # datetime(1999, 12, 4, 0, 0, 0, 0) is too old to show up
     # in the results
     self.assertEqual(Weeks.filter(self.datetimes, number=4, now=self.now),
                      set([datetime(1999, 12, 18, 0, 0, 0, 0),
                           datetime(1999, 12, 31, 23, 59, 59, 999999),
                           datetime(2000, 1, 1, 0, 0, 0, 0)]))
Ejemplo n.º 3
0
    def test_mask(self):
        # 31 December 1999 is a Friday.
        dt = datetime(1999, 12, 31, 23, 59, 59, 999999)
        self.assertEqual(dt.weekday(), FRIDAY)

        # Default firstweekday is Saturday
        self.assertEqual(Weeks.mask(dt), Weeks.mask(dt, firstweekday=SATURDAY))
        self.assertEqual(Weeks.mask(dt), datetime(1999, 12, 25, 0, 0, 0, 0))

        # Sunday
        self.assertEqual(Weeks.mask(dt, firstweekday=SUNDAY),
                         datetime(1999, 12, 26, 0, 0, 0, 0))

        # If firstweekday is the same as dt.weekday, then it should return
        # the same day.
        self.assertEqual(Weeks.mask(dt, firstweekday=dt.weekday()),
                         Days.mask(dt))
Ejemplo n.º 4
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(
         Weeks.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)
         ]))
Ejemplo n.º 5
0
    def test_all_input(self):
        self.assertEqual(
            Weeks.filter(self.datetimes, number=5, now=self.now),
            set([
                datetime(1999, 12, 4, 0, 0, 0, 0),
                datetime(1999, 12, 18, 0, 0, 0, 0),
                datetime(1999, 12, 31, 23, 59, 59, 999999),
                datetime(2000, 1, 1, 0, 0, 0, 0)
            ]))

        self.assertEqual(
            Weeks.filter(self.datetimes, number=6, now=self.now),
            set([
                datetime(1999, 12, 4, 0, 0, 0, 0),
                datetime(1999, 12, 18, 0, 0, 0, 0),
                datetime(1999, 12, 31, 23, 59, 59, 999999),
                datetime(2000, 1, 1, 0, 0, 0, 0)
            ]))
Ejemplo n.º 6
0
    def test_mask(self):
        # 31 December 1999 is a Friday.
        dt = datetime(1999, 12, 31, 23, 59, 59, 999999)
        self.assertEqual(dt.weekday(), FRIDAY)

        # Default firstweekday is Saturday
        self.assertEqual(Weeks.mask(dt),
                         Weeks.mask(dt, firstweekday=SATURDAY))
        self.assertEqual(Weeks.mask(dt),
                         datetime(1999, 12, 25, 0, 0, 0, 0))

        # Sunday
        self.assertEqual(Weeks.mask(dt, firstweekday=SUNDAY),
                         datetime(1999, 12, 26, 0, 0, 0, 0))

        # If firstweekday is the same as dt.weekday, then it should return
        # the same day.
        self.assertEqual(Weeks.mask(dt, firstweekday=dt.weekday()),
                         Days.mask(dt))
Ejemplo n.º 7
0
 def test_before_start(self):
     # datetime(1999, 12, 4, 0, 0, 0, 0) is too old to show up
     # in the results
     self.assertEqual(
         Weeks.filter(self.datetimes, number=4, now=self.now),
         set([
             datetime(1999, 12, 18, 0, 0, 0, 0),
             datetime(1999, 12, 31, 23, 59, 59, 999999),
             datetime(2000, 1, 1, 0, 0, 0, 0)
         ]))
Ejemplo n.º 8
0
 def test_different_firstweekday(self):
     self.assertEqual(
         Weeks.filter(
             self.datetimes, number=3, firstweekday=3, now=self.now
         ),
         set([datetime(1999, 12, 18, 0, 0, 0, 0),
              datetime(1999, 12, 31, 23, 59, 59, 999999)])
     )
     filtered = Weeks.filter(
             self.datetimes, number=5, firstweekday=3, now=self.now
         )
     self.assertEqual(
         Weeks.filter(
             self.datetimes, number=5, firstweekday=3, now=self.now
         ),
         set([datetime(1999, 12, 18, 0, 0, 0, 0),
              datetime(1999, 12, 4, 0, 0, 0, 0),
              datetime(1999, 12, 31, 23, 59, 59, 999999)])
     )
Ejemplo n.º 9
0
 def test_different_firstweekday(self):
     self.assertEqual(
         Weeks.filter(self.datetimes,
                      number=3,
                      firstweekday=3,
                      now=self.now),
         set([
             datetime(1999, 12, 18, 0, 0, 0, 0),
             datetime(1999, 12, 31, 23, 59, 59, 999999)
         ]))
     filtered = Weeks.filter(self.datetimes,
                             number=5,
                             firstweekday=3,
                             now=self.now)
     self.assertEqual(
         Weeks.filter(self.datetimes,
                      number=5,
                      firstweekday=3,
                      now=self.now),
         set([
             datetime(1999, 12, 18, 0, 0, 0, 0),
             datetime(1999, 12, 4, 0, 0, 0, 0),
             datetime(1999, 12, 31, 23, 59, 59, 999999)
         ]))
Ejemplo n.º 10
0
 def test_no_input(self):
     self.assertEqual(Weeks.filter([], number=1, now=self.now),
                      set())
Ejemplo n.º 11
0
 def test_no_results(self):
     self.assertEqual(Weeks.filter([self.now], number=0, now=self.now),
                      set())
     self.assertEqual(Weeks.filter(self.datetimes, number=0, now=self.now),
                      set())
Ejemplo n.º 12
0
 def test_current(self):
     self.assertEqual(Weeks.filter(self.datetimes, number=1, now=self.now),
                      set([datetime(2000, 1, 1, 0, 0, 0, 0)]))
Ejemplo n.º 13
0
 def test_no_results(self):
     self.assertEqual(Weeks.filter([self.now], number=0, now=self.now),
                      set())
     self.assertEqual(Weeks.filter(self.datetimes, number=0, now=self.now),
                      set())
Ejemplo n.º 14
0
 def test_no_input(self):
     self.assertEqual(Weeks.filter([], number=1, now=self.now), set())
Ejemplo n.º 15
0
 def test_future(self):
     datetimes = [datetime(2010, 1, 15, 0, 0, 0, 0)]  # Wikipedia
     self.assertEqual(Weeks.filter(datetimes, number=0, now=self.now),
                      set(datetimes))
     self.assertEqual(Weeks.filter(datetimes, number=1, now=self.now),
                      set(datetimes))
Ejemplo n.º 16
0
 def test_future(self):
     datetimes = [datetime(2010, 1, 15, 0, 0, 0, 0)]  # Wikipedia
     self.assertEqual(Weeks.filter(datetimes, number=0, now=self.now),
                      set(datetimes))
     self.assertEqual(Weeks.filter(datetimes, number=1, now=self.now),
                      set(datetimes))
Ejemplo n.º 17
0
 def test_current(self):
     self.assertEqual(Weeks.filter(self.datetimes, number=1, now=self.now),
                      set([datetime(2000, 1, 1, 0, 0, 0, 0)]))
Ejemplo n.º 18
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(Weeks.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)]))