예제 #1
0
    def test_offset(self):
        tests = []

        tests.append((Week(), # not business week
                      {datetime(2008, 1, 1): datetime(2008, 1, 8),
                       datetime(2008, 1, 4): datetime(2008, 1, 11),
                       datetime(2008, 1, 5): datetime(2008, 1, 12),
                       datetime(2008, 1, 6): datetime(2008, 1, 13),
                       datetime(2008, 1, 7): datetime(2008, 1, 14)}))

        tests.append((Week(weekday=0), # Mon
                      {datetime(2007, 12, 31): datetime(2008, 1, 7),
                       datetime(2008, 1, 4): datetime(2008, 1, 7),
                       datetime(2008, 1, 5): datetime(2008, 1, 7),
                       datetime(2008, 1, 6): datetime(2008, 1, 7),
                       datetime(2008, 1, 7): datetime(2008, 1, 14)}))

        tests.append((Week(0, weekday=0), # n=0 -> roll forward. Mon
                      {datetime(2007, 12, 31): datetime(2007, 12, 31),
                       datetime(2008, 1, 4): datetime(2008, 1, 7),
                       datetime(2008, 1, 5): datetime(2008, 1, 7),
                       datetime(2008, 1, 6): datetime(2008, 1, 7),
                       datetime(2008, 1, 7): datetime(2008, 1, 7)}))

        tests.append((Week(-2, weekday=1), # n=0 -> roll forward. Mon
                      {datetime(2010, 4, 6): datetime(2010, 3, 23),
                       datetime(2010, 4, 8): datetime(2010, 3, 30),
                       datetime(2010, 4, 5): datetime(2010, 3, 23)}))

        for dateOffset, cases in tests:
            for baseDate, expected in cases.iteritems():
                assertEq(dateOffset, baseDate, expected)
예제 #2
0
def test_getOffset():
    assert_raises(Exception, getOffset, 'gibberish')

    assert getOffset('WEEKDAY') == BDay()
    assert getOffset('EOM') == BMonthEnd()
    assert getOffset('W@MON') == Week(weekday=0)
    assert getOffset('W@TUE') == Week(weekday=1)
    assert getOffset('W@WED') == Week(weekday=2)
    assert getOffset('W@THU') == Week(weekday=3)
    assert getOffset('W@FRI') == Week(weekday=4)
예제 #3
0
def test_getOffsetName():
    assert_raises(Exception, getOffsetName, BDay(2))

    assert getOffsetName(BDay()) == 'WEEKDAY'
    assert getOffsetName(BMonthEnd()) == 'EOM'
    assert getOffsetName(Week(weekday=0)) == 'W@MON'
    assert getOffsetName(Week(weekday=1)) == 'W@TUE'
    assert getOffsetName(Week(weekday=2)) == 'W@WED'
    assert getOffsetName(Week(weekday=3)) == 'W@THU'
    assert getOffsetName(Week(weekday=4)) == 'W@FRI'
예제 #4
0
    def test_onOffset(self):
        for weekday in range(7):
            offset = Week(weekday=weekday)

            for day in range(1, 8):
                date = datetime(2008, 1, day)

                if day % 7 == weekday:
                    expected = True
                else:
                    expected = False
            assertOnOffset(offset, date, expected)
예제 #5
0
 def test_offsets_compare_equal(self):
     # root cause of #456
     offset1 = Week()
     offset2 = Week()
     self.assertFalse(offset1 != offset2)
예제 #6
0
 def test_isAnchored(self):
     self.assert_(Week(weekday=0).isAnchored())
     self.assert_(not Week().isAnchored())
     self.assert_(not Week(2, weekday=2).isAnchored())
     self.assert_(not Week(2).isAnchored())
예제 #7
0
    def test_onOffset(self):

        tests = [
            (Week(weekday=0), datetime(2008, 1, 1), False),
            (Week(weekday=0), datetime(2008, 1, 2), False),
            (Week(weekday=0), datetime(2008, 1, 3), False),
            (Week(weekday=0), datetime(2008, 1, 4), False),
            (Week(weekday=0), datetime(2008, 1, 5), False),
            (Week(weekday=0), datetime(2008, 1, 6), False),
            (Week(weekday=0), datetime(2008, 1, 7), True),
            (Week(weekday=1), datetime(2008, 1, 1), True),
            (Week(weekday=1), datetime(2008, 1, 2), False),
            (Week(weekday=1), datetime(2008, 1, 3), False),
            (Week(weekday=1), datetime(2008, 1, 4), False),
            (Week(weekday=1), datetime(2008, 1, 5), False),
            (Week(weekday=1), datetime(2008, 1, 6), False),
            (Week(weekday=1), datetime(2008, 1, 7), False),
            (Week(weekday=2), datetime(2008, 1, 1), False),
            (Week(weekday=2), datetime(2008, 1, 2), True),
            (Week(weekday=2), datetime(2008, 1, 3), False),
            (Week(weekday=2), datetime(2008, 1, 4), False),
            (Week(weekday=2), datetime(2008, 1, 5), False),
            (Week(weekday=2), datetime(2008, 1, 6), False),
            (Week(weekday=2), datetime(2008, 1, 7), False),
            (Week(weekday=3), datetime(2008, 1, 1), False),
            (Week(weekday=3), datetime(2008, 1, 2), False),
            (Week(weekday=3), datetime(2008, 1, 3), True),
            (Week(weekday=3), datetime(2008, 1, 4), False),
            (Week(weekday=3), datetime(2008, 1, 5), False),
            (Week(weekday=3), datetime(2008, 1, 6), False),
            (Week(weekday=3), datetime(2008, 1, 7), False),
            (Week(weekday=4), datetime(2008, 1, 1), False),
            (Week(weekday=4), datetime(2008, 1, 2), False),
            (Week(weekday=4), datetime(2008, 1, 3), False),
            (Week(weekday=4), datetime(2008, 1, 4), True),
            (Week(weekday=4), datetime(2008, 1, 5), False),
            (Week(weekday=4), datetime(2008, 1, 6), False),
            (Week(weekday=4), datetime(2008, 1, 7), False),
            (Week(weekday=5), datetime(2008, 1, 1), False),
            (Week(weekday=5), datetime(2008, 1, 2), False),
            (Week(weekday=5), datetime(2008, 1, 3), False),
            (Week(weekday=5), datetime(2008, 1, 4), False),
            (Week(weekday=5), datetime(2008, 1, 5), True),
            (Week(weekday=5), datetime(2008, 1, 6), False),
            (Week(weekday=5), datetime(2008, 1, 7), False),
            (Week(weekday=6), datetime(2008, 1, 1), False),
            (Week(weekday=6), datetime(2008, 1, 2), False),
            (Week(weekday=6), datetime(2008, 1, 3), False),
            (Week(weekday=6), datetime(2008, 1, 4), False),
            (Week(weekday=6), datetime(2008, 1, 5), False),
            (Week(weekday=6), datetime(2008, 1, 6), True),
            (Week(weekday=6), datetime(2008, 1, 7), False),
        ]

        for offset, date, expected in tests:
            assertOnOffset(offset, date, expected)