def dd(): return [ ttcal.Duration(days=1, hours=3, minutes=14, seconds=20), ttcal.Duration(days=0, hours=1, minutes=10, seconds=0), ttcal.Duration(days=0, hours=0, minutes=70, seconds=0), ttcal.Duration(timedelta(minutes=70)), ]
def test_eq(dd): assert dd[1] == timedelta(hours=1, minutes=10) assert timedelta(hours=1, minutes=10) == dd[1] assert ttcal.Duration() == 0 assert 0 == ttcal.Duration() assert dd[1] - dd[1] == 0 assert 0 == dd[1] - dd[1] assert not (dd[0] == "foo")
def test_duration_rmeth(): class Foo(object): def __req__(self, other): return 42 def __rne__(self, other): return 43 def __rlt__(self, other): return 44 def __rgt__(self, other): return 45 def __rle__(self, other): return 46 def __rge__(self, other): return 47 assert (ttcal.Duration(years=2) == Foo()) == 42 assert (ttcal.Duration(years=2) != Foo()) == 43 assert (ttcal.Duration(years=2) < Foo()) == 44 assert (ttcal.Duration(years=2) > Foo()) == 45 assert (ttcal.Duration(years=2) <= Foo()) == 46 assert (ttcal.Duration(years=2) >= Foo()) == 47
def test_div(dd): assert dd[2] / 2 == ttcal.Duration(minutes=35) assert dd[2] // 2 == ttcal.Duration(minutes=35) # there are 4 x 15mins in 1 hour.. assert ttcal.Duration(hours=1) / ttcal.Duration(minutes=15) == 4.0 # assert ttcal.Duration(hours=1) // ttcal.Duration(minutes=15) == 4 # we don't raise zero division errors. assert ttcal.Duration(hours=1) / ttcal.Duration() == 0.0
def execute(self, cursor): sql = self.get_sql() if self.cached: key = "CachedSelectStmt_{}_{}".format(sql, self.args) res = cache.get(key) if res: object_list, self.columns, self.rowcount = res else: object_list = self._execute(cursor, sql) cache.set( key, (object_list, [d[:] for d in cursor.description], cursor.rowcount), int(ttcal.Duration( hours=self.cache_duration_hours, minutes=self.cache_duration_minutes).total_seconds())) else: object_list = self._execute(cursor, sql) return object_list
def test_sum(dd): assert ttcal.Duration.sum(dd) == ttcal.Duration(days=1, hours=6, minutes=44, seconds=20) assert ttcal.Duration.sum(dd, ttcal.Duration(days=1)) == ttcal.Duration(days=2, hours=6, minutes=44, seconds=20)
def test_mul(dd): assert dd[2] * 3 == ttcal.Duration(hours=3, minutes=30)
def test_sub(dd): tmp = ttcal.Duration(days=1, hours=2, minutes=4, seconds=20) assert dd[0] - dd[1] == tmp
def test_add(dd): assert dd[2] + dd[3] == ttcal.Duration(hours=2, minutes=20)
def test_parse(dd): assert dd[1].parse('01:10:00') == dd[2] assert ttcal.Duration.parse("") is None assert ttcal.Duration.parse("-1:10") == ttcal.Duration(hours=-1, minutes=-10)
def test_sub(days): assert days[0] - days[1] == 2 assert days[0] - ttcal.Duration(days=2) == days[1] with pytest.raises(ValueError): days[0] - 'foo'