Beispiel #1
0
    def test_sort_natural(self):
        periods = [
            YearPeriod('2016'),
            YearPeriod('2017'),
            YearPeriod('2015'),
        ]

        periods.sort()

        self.assertEqual([p.year for p in periods], [
            2015,
            2016,
            2017,
        ])
Beispiel #2
0
 def test_current_past_future(self):
     month = YearPeriod()
     self.assertTrue(month.is_current())
     self.assertFalse(month.next().is_current())
     self.assertTrue(month.next().is_future())
     self.assertFalse(month.next().is_past())
     self.assertTrue(month.previous().is_past())
     self.assertFalse(month.next().is_past())
Beispiel #3
0
 def test_from_string_month(self):
     self.assertEqual(period_from_string('2015'), YearPeriod(2015))
     self.assertEqual(period_from_string('201512'), MonthPeriod(year=2015, month=12))
Beispiel #4
0
 def test_period_factory(self):
     self.assertEqual(period_factory('year', '2015'), YearPeriod(2015))
     self.assertEqual(period_factory('month', '201512'), MonthPeriod(year=2015, month=12))
Beispiel #5
0
    def test_empty_constructor_uses_current_year(self):
        current_year = date.today().year

        period = YearPeriod()

        self.assertEqual(period.year, current_year)
Beispiel #6
0
 def test_create_from_empty_strings(self):
     self.assertEqual(str(YearPeriod('')), YearPeriod())
Beispiel #7
0
    def test_range_negative(self):
        generator = YearPeriod(2015).range(-2, 2)

        self.assertEqual([str(year) for year in generator],
                         ['2013', '2014', '2015', '2016', '2017'])
Beispiel #8
0
    def test_range_with_period(self):
        generator = YearPeriod(2015).range(stop=YearPeriod(2018))

        self.assertEqual([str(year) for year in generator],
                         ['2015', '2016', '2017', '2018'])
Beispiel #9
0
 def test_months(self):
     months_in_year = [str(m) for m in YearPeriod(2016).months]
     self.assertEqual(months_in_year, [
         '201601', '201602', '201603', '201604', '201605', '201606',
         '201607', '201608', '201609', '201610', '201611', '201612'
     ])
Beispiel #10
0
 def test_subtract(self):
     self.assertEqual(YearPeriod(2016) - 1, YearPeriod(2015))
Beispiel #11
0
 def test_add(self):
     self.assertEqual(YearPeriod(2016) + 1, YearPeriod(2017))
Beispiel #12
0
 def test_constructor(self):
     self.assertEqual(YearPeriod('2016').year, 2016)
     self.assertEqual(YearPeriod(2016).year, 2016)
Beispiel #13
0
 def test_serialize(self):
     self.assertEqual(_serialize(YearPeriod('2012')), {'year': 2012})
     self.assertEqual(_serialize(MonthPeriod('201202')), {'year': 2012, 'month': 2})
Beispiel #14
0
 def test_deserialize_from_string(self):
     self.assertEqual(_deserialize('2013'), YearPeriod('2013'))
     self.assertEqual(_deserialize('201305'), MonthPeriod('201305'))
Beispiel #15
0
 def test_deserialize_from_object(self):
     self.assertEqual(_deserialize({'year': 2012}), YearPeriod('2012'))
     self.assertEqual(_deserialize({'year': 2012, 'month': 2}), MonthPeriod('201202'))