Exemple #1
0
 def __previous_week(self):
     """Go to the previous week."""
     current_week = int(self.week_edit.value())
     if current_week - 1 == 0:
         current_year = int(self.year_edit.value())
         weeks_of_previous_year = weeks_for_year(current_year - 1)
         self.week_edit.setValue(weeks_of_previous_year)
         self.year_edit.setValue(current_year - 1)
     else:
         self.week_edit.setValue(current_week - 1)
Exemple #2
0
 def __next_week(self):
     """Go to the next week."""
     current_week = int(self.week_edit.value())
     current_year = int(self.year_edit.value())
     weeks_of_current_year = weeks_for_year(current_year)
     if current_week + 1 > weeks_of_current_year:
         self.week_edit.setValue(1)
         self.year_edit.setValue(current_year + 1)
     else:
         self.week_edit.setValue(current_week + 1)
Exemple #3
0
    def test_number_of_weeks_for_several_years(self):
        """Test number of weeks for several years."""
        expected = {
            2000: 52,
            2001: 52,
            2002: 52,
            2003: 52,
            2004: 53,
            2005: 52,
            2006: 52,
            2007: 52,
            2008: 52,
            2009: 53,
            2010: 52,
            2011: 52,
            2012: 52,
            2013: 52,
            2014: 52,
            2015: 53,
            2016: 52,
            2017: 52,
            2018: 52,
            2019: 52,
            2020: 53,
            2021: 52,
            2022: 52,
            2023: 52,
            2024: 52,
            2025: 52,
            2026: 53,
            2027: 52,
            2028: 52,
            2029: 52,
            2030: 52,
        }

        for year, week in expected.items():
            with self.subTest(name='year {}'.format(year)):
                self.assertEqual(week, weeks_for_year(year))
Exemple #4
0
 def __update_week_edit(self, year):
     """Update the week edit max value for a given year."""
     weeks = weeks_for_year(int(year))
     self.week_edit.setMaximum(weeks)
Exemple #5
0
 def test_none_returns_none(self):
     """Test that None returns None."""
     self.assertIsNone(weeks_for_year(None))
Exemple #6
0
 def test_float_value_returns_correct_value(self):
     """Test that float value returns correct value."""
     self.assertEqual(52, weeks_for_year(2000.43))
Exemple #7
0
 def test_int_in_string_returns_correct_value(self):
     """Test that int in string returns correct value."""
     self.assertEqual(52, weeks_for_year("2000"))
Exemple #8
0
 def test_non_number_string_returns_none(self):
     """Test that non number string returns None."""
     self.assertIsNone(weeks_for_year("two thousand"))