def tmranges(dts): """Fixture with common TimeRange objects.""" return [ timerange.TimeRange(), timerange.TimeRange(inc_begin=dts[0], exc_end=dts[1], anchor=dts[0]), timerange.TimeRange(inc_begin=dts[2], exc_end=dts[3], anchor=dts[2]), timerange.TimeRange(inc_begin=dts[4], exc_end=dts[5], anchor=dts[4]), ]
def test_initial_invalid(self, dts): tmrange = timerange.TimeRange() assert not tmrange.is_valid() with pytest.raises(ValueError): tmrange.validate() tmrange = timerange.TimeRange(inc_begin=dts[4]) assert not tmrange.is_valid() tmrange = timerange.TimeRange(exc_end=dts[4]) assert not tmrange.is_valid()
def test_set_get_exc(self, dts): tmrange = timerange.TimeRange() tmrange.exc_begin = dts[4] tmrange.exc_end = dts[5] assert tmrange.is_valid() assert tmrange.inc_begin == (dts[4] + timerange.TIMERANGE_PRECISION) assert tmrange.inc_end == (dts[5] - timerange.TIMERANGE_PRECISION)
def test_init_inc(self, dts): tmrange = timerange.TimeRange(inc_begin=dts[4], inc_end=dts[5]) assert tmrange.is_valid() assert tmrange.inc_begin == dts[4] assert tmrange.inc_end == dts[5] assert tmrange.exc_begin == (dts[4] - timerange.TIMERANGE_PRECISION) assert tmrange.exc_end == (dts[5] + timerange.TIMERANGE_PRECISION)
def test_bad_timerange(self, mdefs): emf = emf_random.EMFetcher_random(mdefs[1]) with pytest.raises(TypeError): emf.fetch('Not TimeRange') tmrange3 = timerange.TimeRange() with pytest.raises(ValueError): emf.fetch(tmrange3)
def test_duration(self, dts): tmrange = timerange.TimeRange(inc_begin=dts[4], exc_end=dts[5]) assert tmrange.duration == timedelta(days=59, seconds=720)
def test_anchor(self, dts): tmrange = timerange.TimeRange(inc_begin=dts[4], inc_end=dts[5], anchor=dts[5] - timedelta(days=5)) assert tmrange.is_anchored() assert tmrange.is_valid()
def test_str(self): tmrange = timerange.TimeRange() str(tmrange)