Example #1
0
 def test_ghosts(self, dts):
     tmfrspec_dict = {
         'range_unit': 'QUARTER',
         'range_val': 1,
         'gran_unit': 'WEEK',
         'smooth_unit': 'DAY',
         'smooth_val': 14,
         'mode': 'CURRENT',
         'reframe_dt': dt('2014-02-14 16:30:45 001234'),
     }
     tmfrspec = framespec.FrameSpec(**tmfrspec_dict)
     #
     steps = list(stepper.Stepper(tmfrspec, ghost=None).steps())
     assert steps[0].anchor == dt('2014-01-01 00:00:00 000000')
     #
     g1 = "Not a Ghost"
     with pytest.raises(TypeError):
         steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     #
     g1 = ghost.Ghost('PREV_PERIOD1')
     str(g1)
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2013-10-01 00:00:00 000000')
     #
     g1 = ghost.Ghost('PREV_PERIOD2')
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2013-07-01 00:00:00 000000')
     #
     g1 = ghost.Ghost('PREV_YEAR1')
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2013-01-01 00:00:00 000000')
     #
     g1 = ghost.Ghost('PREV_YEAR2')
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2012-01-01 00:00:00 000000')
Example #2
0
 def _steps(self, tmfrspec_dict, options=dict()):
     """Given dict of FrameSpec attrs, return list of steps."""
     tmfrspec = framespec.FrameSpec(**tmfrspec_dict)
     step1 = stepper.Stepper(tmfrspec)
     for o, v in options.iteritems():
         step1.set_option(o, v)
     steps = list(step1.steps())
     # print "steps=", len(steps), "\n", "\n".join([str(s) for s in steps])
     return steps
Example #3
0
 def test_qtimeframe(self):
     qtimeframe1 = qtimeframe.QTimeFrame()
     str(qtimeframe1)
     qtimeframe1.tmfrspec = framespec.FrameSpec()
     assert qtimeframe1.tmfrspec
     with pytest.raises(TypeError):
         qtimeframe1.tmfrspec = 'Not FrameSpec'
     self.query1.qtimeframe = qtimeframe1
     with pytest.raises(TypeError):
         self.query1.qtimeframe = 'Not QTimeFrame'
Example #4
0
 def test_str(self, dts):
     tmfrspec_dict = {
         'range_unit': 'MONTH',
         'range_val': 1,
         'gran_unit': 'DAY',
         'mode': 'CURRENT',
     }
     frspec = framespec.FrameSpec(**tmfrspec_dict)
     step1 = stepper.Stepper(frspec)
     str(step1)
Example #5
0
 def test_invalid(self):
     tmfrspec = framespec.FrameSpec()
     with pytest.raises(ValueError):
         framespec.FrameSpec(range_unit='BOGUSUNIT')
     with pytest.raises(TypeError):
         framespec.FrameSpec(range_val='not an int')
     with pytest.raises(ValueError):
         framespec.FrameSpec(gran_unit='BOGUSUNIT')
     with pytest.raises(ValueError):
         framespec.FrameSpec(mode='BOGUSMODE')
     with pytest.raises(TypeError):
         framespec.FrameSpec(reframe_dt='not a datetime')
Example #6
0
 def test_ghosts_complex(self, dts):
     tmfrspec_dict = {
         'range_unit': 'DAY',
         'range_val': 7,
         'gran_unit': 'DAY',
         'mode': 'CURRENT',
         'reframe_dt': dt('2014-02-14 16:30:45 001234'),
     }
     tmfrspec = framespec.FrameSpec(**tmfrspec_dict)
     #
     steps = list(stepper.Stepper(tmfrspec, ghost=None).steps())
     assert len(steps) == 7
     assert steps[0].anchor == dt('2014-02-08 00:00:00 000000')
     #
     g1 = ghost.Ghost('PREV_PERIOD1')
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2014-02-01 00:00:00 000000')
     #
     g1 = ghost.Ghost('PREV_PERIOD2')
     steps = list(stepper.Stepper(tmfrspec, ghost=g1).steps())
     assert steps[0].anchor == dt('2014-01-25 00:00:00 000000')
Example #7
0
def tmfrspecs():
    """Fixture with common FrameSpec objects."""
    return [
        framespec.FrameSpec(),
        framespec.FrameSpec(smooth_val=4, smooth_unit='HOUR')
    ]
Example #8
0
 def test_smooth(self):
     tmfrspec = framespec.FrameSpec(smooth_val=4, smooth_unit='HOUR')
     assert tmfrspec.smooth_val == 4
Example #9
0
 def test_reframe(self, dts, tmfrspecs):
     assert tmfrspecs[0].is_reframed() == False
     tmfrspecs[0].reframe_dt = dts[4]
     assert tmfrspecs[0].is_reframed() == True
     tmfrspec = framespec.FrameSpec(reframe_dt=dts[4])
     assert tmfrspec.is_reframed() == True
Example #10
0
 def test_str(self):
     tmfrspec = framespec.FrameSpec()
     str(tmfrspec)
Example #11
0
 def test_simple(self):
     tmfrspec = framespec.FrameSpec()