Exemple #1
0
    def test_a_couple_week_and_year_returns_the_right_sequence_of_days(self):
        """Test that a couple week/year returns the right sequence of days."""
        generator = seven_days_of_week(2018, 10)

        monday = next(generator)
        self.assertEqual(3, monday.month)
        self.assertEqual(5, monday.day)
        self.assertEqual(2018, monday.year)

        tuesday = next(generator)
        self.assertEqual(3, tuesday.month)
        self.assertEqual(6, tuesday.day)
        self.assertEqual(2018, tuesday.year)

        wednesday = next(generator)
        self.assertEqual(3, wednesday.month)
        self.assertEqual(7, wednesday.day)
        self.assertEqual(2018, wednesday.year)

        thursday = next(generator)
        self.assertEqual(3, thursday.month)
        self.assertEqual(8, thursday.day)
        self.assertEqual(2018, thursday.year)

        friday = next(generator)
        self.assertEqual(3, friday.month)
        self.assertEqual(9, friday.day)
        self.assertEqual(2018, friday.year)

        saturday = next(generator)
        self.assertEqual(3, saturday.month)
        self.assertEqual(10, saturday.day)
        self.assertEqual(2018, saturday.year)

        sunday = next(generator)
        self.assertEqual(3, sunday.month)
        self.assertEqual(11, sunday.day)
        self.assertEqual(2018, sunday.year)

        with self.assertRaises(StopIteration):
            next(generator)
Exemple #2
0
    def test_a_couple_week_and_year_returns_the_right_monday(self):
        """Test that a couple week/year returns the right monday."""
        expected = {
            (2014, 52): (22, 12),
            (2015, 52): (21, 12),
            (2015, 53): (28, 12),
            (2016, 52): (26, 12),
            (2017, 52): (25, 12),
            (2018, 52): (24, 12),
            (2019, 1): (31, 12),
            (2018, 1): (1, 1),
            (2018, 2): (8, 1),
            (2018, 35): (27, 8),
            (2019, 38): (16, 9),
            (2016, 5): (1, 2),
            (2015, 14): (30, 3),
        }

        for (year, week), (day, month) in expected.items():
            with self.subTest(name='year {}, week {}'.format(year, week)):
                generator = seven_days_of_week(year, week)
                monday = next(generator)
                self.assertEqual(month, monday.month)
                self.assertEqual(day, monday.day)
Exemple #3
0
 def __create_days(self):
     """Create the days of this week."""
     for date_ in seven_days_of_week(self._week.year,
                                     self._week.week_number):
         DayModel(date_, self._week, self.parent)
Exemple #4
0
 def test_none_returns_none(self):
     """Test that None returns None."""
     self.assertEqual([], list(seven_days_of_week(None, None)))
     self.assertEqual([], list(seven_days_of_week(2018, None)))
     self.assertEqual([], list(seven_days_of_week(None, 15)))
Exemple #5
0
 def test_negative_week_number_returns_empty(self):
     """Test that negative week number returns empty."""
     self.assertEqual([], list(seven_days_of_week(2018, 0)))
     self.assertEqual([], list(seven_days_of_week(2018, -1)))
     self.assertEqual(7, len(list(seven_days_of_week(2018, 1))))
Exemple #6
0
 def test_float_returns_seven_days_list(self):
     """Test that float returns seven days list."""
     self.assertEqual(7, len(list(seven_days_of_week(2018.243, 52.13))))
     self.assertEqual(7, len(list(seven_days_of_week(2018.243, 52))))
     self.assertEqual(7, len(list(seven_days_of_week(2018, 52.13))))
Exemple #7
0
 def test_int_in_string_returns_seven_days_list(self):
     """Test that int in string returns seven days list.."""
     self.assertEqual(7, len(list(seven_days_of_week('2018', '52'))))
     self.assertEqual(7, len(list(seven_days_of_week('2018', 52))))
     self.assertEqual(7, len(list(seven_days_of_week(2018, '52'))))
Exemple #8
0
 def test_non_number_string_returns_empty(self):
     """Test that non number string returns empty."""
     self.assertEqual([], list(seven_days_of_week('str1', 'str2')))
     self.assertEqual([], list(seven_days_of_week('str1', 52)))
     self.assertEqual([], list(seven_days_of_week(2018, 'str2')))
Exemple #9
0
 def test_number_of_weeks_too_big_returns_empty(self):
     """Test that number of weeks too big returns empty."""
     self.assertEqual([], list(seven_days_of_week(2018, 54)))
     self.assertEqual([], list(seven_days_of_week(2018, 53)))
     self.assertNotEqual([], list(seven_days_of_week(2018, 52)))