Esempio n. 1
0
def testMondayPairsIteratorFactory():
  """testMondayPairsIteratorFactory():
    - check that we get the Monday-to-Monday full week from one non-Monday
    - check that we get the appropriate weeks for a pair of Mondays
    - check that we get appropriate weeks for a leading Monday, trailing non-Monday
    - check that we raise ValueError for reverse-order arguments
    - check that we raise TypeError for non-date arguments
  """
  data = [
    (dt.date(2008,1,1),dt.date(2008,1,1),[(dt.date(2007, 12, 31), dt.date(2008, 1, 7))]),
    (dt.date(2008,1,7),dt.date(2008,1,19),[(dt.date(2008, 1, 7), dt.date(2008, 1, 14)), (dt.date(2008, 1, 14), dt.date(2008, 1, 21))]),
    (dt.date(2008,1,9),dt.date(2008,2,3),[(dt.date(2008, 1, 7), dt.date(2008, 1, 14)), (dt.date(2008, 1, 14), dt.date(2008, 1, 21)), (dt.date(2008, 1, 21), dt.date(2008, 1, 28)), (dt.date(2008, 1, 28), dt.date(2008, 2, 4))]),
    (dt.date(2008,1,7),dt.date(2008,1,1),ValueError),
    ("bad",dt.date(2008,1,1),TypeError),
    (dt.date(2008,1,1),"bad",TypeError),
    (39,"worse",TypeError),
    ]
  for datePair in data:
    expected = datePair[-1]
    if isinstance(expected,list):
      di = schema.mondayPairsIteratorFactory(*(datePair[:2]))
      got = [ x for x in di ]
      assert datePair[-1]  == got , 'Expected %s, got %s'%(datePair[-1],got)
    else:
      assert_raises(expected,schema.mondayPairsIteratorFactory,*(datePair[:2]))
 def testConstructor(self):
     """
 TestPartitionedTable.testConstructor(self):
   - (pause a moment if right at midnight, then ...)
   - check that the constructor works as expected
 """
     # make sure we don't fail if we are being run 'too close for comfort' to midnight
     now = utc_now()
     midnight = dt.datetime(now.year,
                            now.month,
                            now.day,
                            0,
                            0,
                            0,
                            tzinfo=UTC)
     midnight += dt.timedelta(days=1)
     middiff = midnight - now
     if middiff < dt.timedelta(0, 2):
         time.sleep(middiff.seconds)
     # end of midnight (time) creep
     today = dt.date.today()  # now guaranteed to be 'after' midnight
     expectedIntervalList = [
         x for x in schema.mondayPairsIteratorFactory(today, today)
     ]
     testPt = TPT(logger=me.logger)
     assert 'tpt' == testPt.name
     assert me.logger == testPt.logger
     assert '%s' == testPt.partitionNameTemplate
     assert tptCreationSql % 'tpt' == testPt.creationSql
     createdIntervalList = [x for xi in testPt.weekInterval]
     assert expectedIntervalList == createdIntervalList
Esempio n. 3
0
def testMondayPairsIteratorFactory():
    """testMondayPairsIteratorFactory():
    - check that we get the Monday-to-Monday full week from one non-Monday
    - check that we get the appropriate weeks for a pair of Mondays
    - check that we get appropriate weeks for a leading Monday, trailing non-Monday
    - check that we raise ValueError for reverse-order arguments
    - check that we raise TypeError for non-date arguments
  """
    data = [
        (dt.date(2008, 1, 1), dt.date(2008, 1, 1), [(dt.date(2007, 12, 31),
                                                     dt.date(2008, 1, 7))]),
        (dt.date(2008, 1,
                 7), dt.date(2008, 1,
                             19), [(dt.date(2008, 1, 7), dt.date(2008, 1, 14)),
                                   (dt.date(2008, 1, 14), dt.date(2008, 1,
                                                                  21))]),
        (dt.date(2008, 1,
                 9), dt.date(2008, 2,
                             3), [(dt.date(2008, 1, 7), dt.date(2008, 1, 14)),
                                  (dt.date(2008, 1, 14), dt.date(2008, 1, 21)),
                                  (dt.date(2008, 1, 21), dt.date(2008, 1, 28)),
                                  (dt.date(2008, 1, 28), dt.date(2008, 2,
                                                                 4))]),
        (dt.date(2008, 1, 7), dt.date(2008, 1, 1), ValueError),
        ("bad", dt.date(2008, 1, 1), TypeError),
        (dt.date(2008, 1, 1), "bad", TypeError),
        (39, "worse", TypeError),
    ]
    for datePair in data:
        expected = datePair[-1]
        if isinstance(expected, list):
            di = schema.mondayPairsIteratorFactory(*(datePair[:2]))
            got = [x for x in di]
            assert datePair[-1] == got, 'Expected %s, got %s' % (datePair[-1],
                                                                 got)
        else:
            assert_raises(expected, schema.mondayPairsIteratorFactory,
                          *(datePair[:2]))
 def testConstructor(self):
   """
   TestPartitionedTable.testConstructor(self):
     - (pause a moment if right at midnight, then ...)
     - check that the constructor works as expected
   """
   # make sure we don't fail if we are being run 'too close for comfort' to midnight
   now = utc_now()
   midnight = dt.datetime(now.year,now.month,now.day,0,0,0,tzinfo=UTC)
   midnight += dt.timedelta(days=1)
   middiff = midnight - now
   if middiff < dt.timedelta(0,2):
     time.sleep(middiff.seconds)
   # end of midnight (time) creep
   today = dt.date.today() # now guaranteed to be 'after' midnight
   expectedIntervalList = [x for x in schema.mondayPairsIteratorFactory(today,today)]
   testPt = TPT(logger=me.logger)
   assert 'tpt' == testPt.name
   assert me.logger == testPt.logger
   assert '%s' == testPt.partitionNameTemplate
   assert tptCreationSql%'tpt' == testPt.creationSql
   createdIntervalList = [x for xi in testPt.weekInterval]
   assert expectedIntervalList == createdIntervalList