""" open/dulcinea/lib/test/utest_period.py """ from datetime import timedelta, datetime from dulcinea.period import Period from qp.lib.tz import UTC from sancho.utest import UTest class TestPeriod (UTest): def a(self): p = Period() t = datetime.now(UTC) assert t in p assert p assert not p.is_bounded() q = Period(t) assert t not in q assert p.intersection(q) == q assert p.intersection(p) == p assert q.intersection(q) == q assert not q.is_bounded() a = Period(None, t) assert t - timedelta(seconds=1) in a assert t + timedelta(seconds=1) not in a b = Period(t, None) str(b) repr(b) assert not a.intersection(b), a.intersection(b) assert not b.intersection(a) t1 = t + timedelta(seconds=1) t2 = t1 + timedelta(seconds=1) t3 = t2 + timedelta(seconds=1) assert Period(t, t2).intersection(Period(t1, t3)) == Period(t1, t2) if __name__ == "__main__": TestPeriod()