def test_qmp(months): """Test the cmp methods. """ assert months[0] == date(2012, 4, 5) assert not (months[1] == months[0]) # assert not (months[0] == 'foo') assert ttcal.Month(2020, 2) == ttcal.Month(2020, 2) assert ttcal.Month(2020, 2) != ttcal.Month(2020, 3)
def test_periods(years): """Test of periods using misc methods and properties. """ first_half = [ ttcal.Month(2005, 1), ttcal.Month(2005, 2), ttcal.Month(2005, 3), ttcal.Month(2005, 4), ttcal.Month(2005, 5), ttcal.Month(2005, 6) ] Q3 = [ttcal.Month(2005, 7), ttcal.Month(2005, 8), ttcal.Month(2005, 9)] assert years[0].H1 == first_half assert years[0].Q3 == Q3 assert years[0].halves() assert years[0].quarters() assert years[0].january assert years[0].february assert years[0].march assert years[0].april assert years[0].may assert years[0].june assert years[0].july assert years[0].august assert years[0].september assert years[0].october assert years[0].november assert years[0].december
def test_sub(months): """Test the __sub__ method. """ assert months[0] - 3 == ttcal.Month(2012, 1) assert months[0] - months[0] == 0 assert months[0] - months[0].prev() == 1 assert months[0].prev() - months[0] == -1
def test_parse(months): """ttcal.Month.parse(txt) """ assert ttcal.Month.parse('2012-04') == months[0] assert ttcal.Month.parse('2012-4') == months[0] assert ttcal.Month.parse('2012-09') == ttcal.Month(2012, 9) assert ttcal.Month.parse("") is None with pytest.raises(ValueError): ttcal.Month.parse('12-04')
def test_mark(months): m = ttcal.Month() d = m.first m.mark(d, 'foo') assert m[d].mark == 'foo' m.mark(d, 'bar', 'append') assert m[d].mark == 'foobar' e = m.last m.mark(e, 'baz', 'append') assert m[e].mark == 'baz'
def test_ctor(months): assert ttcal.Month() == ttcal.Today().Month with pytest.raises(ValueError): ttcal.Month(2012, 15)
def test_compare(months): a, b = ttcal.Month(2015, 10), ttcal.Month(2013, 3) print("ab:", a > b) print("ab:", a > b) print("Month compare:", ttcal.Month(2015, 10) > ttcal.Month(2013, 3)) print("Month compare:", ttcal.Month(2015, 10) > ttcal.Month(2013, 3)) assert ttcal.Month(2015, 10) > ttcal.Month(2013, 3) assert ttcal.Month() > months[0] assert months[0] < months[1] assert months[0] <= months[1] assert months[1] > months[0] assert months[1] >= months[0] assert ttcal.Day(2015, 1, 1) < ttcal.Month(2015, 2) assert ttcal.Day(2015, 1, 1) <= ttcal.Month(2015, 2) assert ttcal.Day(2015, 2, 1) == ttcal.Month(2015, 2) assert ttcal.Day(2015, 3, 1) >= ttcal.Month(2015, 2) assert ttcal.Day(2015, 3, 1) > ttcal.Month(2015, 2) assert not ttcal.Month(2015, 1) < None assert not ttcal.Month(2015, 1) <= None assert not ttcal.Month(2015, 1) == None assert not ttcal.Month(2015, 1) > None assert not ttcal.Month(2015, 1) >= None
def test_contains(): assert ttcal.Today() in ttcal.Month() with pytest.raises(KeyError): (ttcal.Month() + 2)[ttcal.Today()]
def test_timetuple(): assert ttcal.Month(2015, 10).timetuple() == datetime(2015, 10, 1, 0)
def test_daycount2(): assert ttcal.Month(2012, 2).daycount == 29
def test_add(months): """Test the __add__ method. """ assert months[0] + 3 == ttcal.Month(2012, 7) assert 3 + months[0] == ttcal.Month(2012, 7)
def months(): return [ ttcal.Month(2012, 4), ttcal.Month(year=2012, month=10), ttcal.Month(date=date(2012, 7, 10)), ]
def test_hash(months): assert hash(ttcal.Today().Month) == hash(ttcal.Month())
def test_month(years): assert years[0].Month == ttcal.Month(2005, 1)
def test_from_idtag(): assert ttcal.from_idtag('m20124') == ttcal.Month(2012, 4)
def test_Month(self): """Test of the Month property. """ month = ttcal.Month(2012, 4) assert self.day1.Month == month