예제 #1
0
 def setUp(self):
     """SetUp default data for the tests.
     """
     self.day1 = ttcal.Day(date(2012, 4, 10))
     self.day2 = ttcal.Day(2012, 4, 8)
     self.day3 = ttcal.Day()
     self.today = ttcal.Today()
예제 #2
0
def days():
    return [
        ttcal.Day(date(2012, 4, 10)),
        ttcal.Day(2012, 4, 8),
        ttcal.Day(),
        ttcal.Today(),
    ]
예제 #3
0
def test_add_month():
    assert ttcal.Day(2020, 1, 30) + ttcal.Period(months=1) == ttcal.Day(
        2020, 2, 29)
    assert ttcal.Day(2020, 1, 30) + ttcal.Period(months=2) == ttcal.Day(
        2020, 3, 30)
    assert ttcal.Day(2020, 1, 30) + ttcal.Period(months=3) == ttcal.Day(
        2020, 4, 30)
    assert ttcal.Day(2020, 1, 30) + ttcal.Period(months=4) == ttcal.Day(
        2020, 5, 30)
    assert ttcal.Day(2020, 1, 30) + ttcal.Period(months=5) == ttcal.Day(
        2020, 6, 30)
예제 #4
0
def test_marked_days(months):
    """Test the mark method.
    """
    res = [ttcal.Day(2012, 10, 3), ttcal.Day(2012, 10, 10)]
    months[1].mark(ttcal.Day(2012, 10, 10))
    months[1].mark(ttcal.Day(2012, 10, 10), value='appended', method='append')
    months[1].mark(ttcal.Day(2012, 10, 3))
    days = []
    for day in months[1].marked_days():
        days.append(day)
    assert days == res
예제 #5
0
def test_mark_period(years):
    """Test the mark_period method.
    """
    res = [ttcal.Day(2025, 3, 1), ttcal.Day(2025, 3, 2), ttcal.Day(2025, 3, 3)]
    years[2].mark_period(years[2].march)
    days = []
    for i, day in enumerate(years[2].marked_days()):
        days.append(day)
        if i == 2:
            break
    assert days == res
예제 #6
0
def test_add_year_leap():
    assert ttcal.Day(2020, 2, 29) + ttcal.Period(years=1) == ttcal.Day(
        2021, 2, 28)
    assert ttcal.Day(2020, 2, 29) + ttcal.Period(years=2) == ttcal.Day(
        2022, 2, 28)
    assert ttcal.Day(2020, 2, 29) + ttcal.Period(years=3) == ttcal.Day(
        2023, 2, 28)
    assert ttcal.Day(2020, 2, 29) + ttcal.Period(years=4) == ttcal.Day(
        2024, 2, 29)
    assert ttcal.Day(2020, 2, 29) + ttcal.Period(years=5) == ttcal.Day(
        2025, 2, 28)
예제 #7
0
def test_dayiter(months):
    """Test the dayiter method.
    """
    res = [
        ttcal.Day(2012, 6, 25),
        ttcal.Day(2012, 6, 26),
        ttcal.Day(2012, 6, 27)
    ]
    days = []
    for i, day in enumerate(months[2].dayiter()):
        days.append(day)
    assert days[:3] == res
예제 #8
0
 def test_range(self):
     """The the range method defined in the RangeMixin class.
     """
     res = [
         ttcal.Day(2012, 1, 1),
         ttcal.Day(2012, 1, 2),
         ttcal.Day(2012, 1, 3),
         ttcal.Day(2012, 1, 4),
         ttcal.Day(2012, 1, 5),
         ttcal.Day(2012, 1, 6),
         ttcal.Day(2012, 1, 7),
         ttcal.Day(2012, 1, 8),
         ttcal.Day(2012, 1, 9),
         ttcal.Day(2012, 1, 10)
     ]
     assert self.days.range() == res
예제 #9
0
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
예제 #10
0
    def test_parse(self):
        """Test the parse method.
        """
        assert self.day1.parse('04/08/2011') == ttcal.Day(2011, 8, 4)
        assert self.day1.parse('2012-04-06') == ttcal.Day(2012, 4, 6)
        assert self.day1.parse('2012-4-6') == ttcal.Day(2012, 4, 6)
        assert self.day1.parse('20130619') == ttcal.Day(2013, 6, 19)
        assert self.day1.parse('12.11.2013') == ttcal.Day(2013, 11, 12)
        assert self.day1.parse('12.10.13') == ttcal.Day(2013, 10, 12)

        self.assertRaises(ValueError, self.day1.parse, '12.10.11')
        self.assertRaises(ValueError, self.day1.parse, '21/13/2011')
예제 #11
0
def test_cmp():
    assert not ttcal.Day(2015, 1, 1) < None
    assert not ttcal.Day(2015, 1, 1) <= None
    assert not ttcal.Day(2015, 1, 1) == None
    assert not ttcal.Day(2015, 1, 1) > None
    assert not ttcal.Day(2015, 1, 1) >= None
예제 #12
0
def test_days(months):
    """Test the days method.
    """
    res = [ttcal.Day(2012, 7, 1), ttcal.Day(2012, 7, 2), ttcal.Day(2012, 7, 3)]
    assert months[2].days()[:3] == res
예제 #13
0
def test_middle(years):
    assert years[0].middle == (ttcal.Day(2005, 1, 1) + 365 // 2)
예제 #14
0
 def test_add_(self):
     """Test of the __add__ method.
     """
     assert self.day2 + 3 == ttcal.Day(2012, 4, 11)
예제 #15
0
def test_ctor_raises():
    with pytest.raises(TypeError):
        ttcal.Day(1, 2, 3, 4, 5)
예제 #16
0
def test_parse():
    assert ttcal.Day.parse("") is None
    assert ttcal.Day.parse('02051970') == ttcal.Day(1970, 5, 2)
    assert ttcal.Day.parse('02.05.1970') == ttcal.Day(1970, 5, 2)
예제 #17
0
 def test_sub_(self):
     """Test of the __sub__ method.
     """
     assert self.day1 - 5 == ttcal.Day(2012, 4, 5)
예제 #18
0
def test_add_month_lastday():
    jan1 = ttcal.Day(2020, 1, 1)
    jan31 = ttcal.Day(2020, 1, 31)
    feb29 = ttcal.Day(2020, 2, 29)
    months1 = ttcal.Period(months=1)
    months2 = ttcal.Period(months=2)
    months3 = ttcal.Period(months=3)
    months4 = ttcal.Period(months=4)
    months5 = ttcal.Period(months=5)
    years1 = ttcal.Period(years=1)

    print("jan1 + 1month=", jan1 + months1)
    assert jan1 + months1 == ttcal.Day(2020, 2, 1)
    assert feb29 + years1 == ttcal.Day(2021, 2, 28)
    assert feb29 + months1 == ttcal.Day(2020, 3, 29)
    assert jan31 + months1 == feb29
    assert jan31 + months2 == ttcal.Day(2020, 3, 31)
    assert jan31 + months3 == ttcal.Day(2020, 4, 30)
    assert jan31 + months4 == ttcal.Day(2020, 5, 31)
    assert jan31 + months5 == ttcal.Day(2020, 6, 30)

    # assert ttcal.Period(months=1) + ttcal.Period(months=1) == ttcal.Period(months=2)

    print("feb29 + months1 + months1 = ", feb29 + (months1 + months1))
    assert feb29 + (months1 + months1) == ttcal.Day(2020, 4, 29)

    print("(d + 1m) + 1m =", (feb29 + months1) + months1)
    assert feb29 + months1 == ttcal.Day(2020, 3, 29)
    assert (feb29 + months1) + months1 == ttcal.Day(2020, 4, 29)
예제 #19
0
def test_timetuple(days):
    assert isinstance(days[0].timetuple(), datetime)
    assert ttcal.Today().timetuple() == ttcal.Day().timetuple()