]> arthur.barton.de Git - bup.git/blob - lib/bup/t/txstat.py
Drop xstat floating point timestamp support -- use integer ns.
[bup.git] / lib / bup / t / txstat.py
1 import math
2 from wvtest import *
3 import bup._helpers as _helpers
4 from bup.xstat import FSTime
5
6 @wvtest
7 def test_fstime():
8     def approx_eq(x, y):
9         return math.fabs(x - y) < 1 / 10e8
10     def ts_eq_ish(x, y):
11         return approx_eq(x[0], y[0]) and approx_eq(x[1], y[1])
12     def fst_eq_ish(x, y):
13         return approx_eq(x.approx_secs(), y.approx_secs())
14     def s_ns_eq_ish(fst, s, ns):
15         (fst_s, fst_ns) = fst.secs_nsecs()
16         return approx_eq(fst_s, s) and approx_eq(fst_ns, ns)
17     from_secs = FSTime.from_secs
18     from_ts = FSTime.from_timespec
19     WVPASS(from_secs(0) == from_secs(0))
20     WVPASS(from_secs(0) < from_secs(1))
21     WVPASS(from_secs(-1) < from_secs(1))
22     WVPASS(from_secs(1) > from_secs(0))
23     WVPASS(from_secs(1) > from_secs(-1))
24
25     WVPASS(fst_eq_ish(from_secs(0), from_ts((0, 0))))
26     WVPASS(fst_eq_ish(from_secs(1), from_ts((1, 0))))
27     WVPASS(fst_eq_ish(from_secs(-1), from_ts((-1, 0))))
28     WVPASS(fst_eq_ish(from_secs(-0.5), from_ts((-1, 10**9 / 2))))
29     WVPASS(fst_eq_ish(from_secs(-1.5), from_ts((-2, 10**9 / 2))))
30     WVPASS(fst_eq_ish(from_secs(1 / 10e8), from_ts((0, 1))))
31     WVPASS(fst_eq_ish(from_secs(-1 / 10e8), from_ts((-1, 10**9 - 1))))
32
33     WVPASS(ts_eq_ish(from_secs(0).to_timespec(), (0, 0)))
34     WVPASS(ts_eq_ish(from_secs(1).to_timespec(), (1, 0)))
35     WVPASS(ts_eq_ish(from_secs(-1).to_timespec(), (-1, 0)))
36     WVPASS(ts_eq_ish(from_secs(-0.5).to_timespec(), (-1, 10**9 / 2)))
37     WVPASS(ts_eq_ish(from_secs(-1.5).to_timespec(), (-2, 10**9 / 2)))
38     WVPASS(ts_eq_ish(from_secs(1 / 10e8).to_timespec(), (0, 1)))
39     WVPASS(ts_eq_ish(from_secs(-1 / 10e8).to_timespec(), (-1, 10**9 - 1)))
40
41     WVPASS(s_ns_eq_ish(from_secs(0), 0, 0))
42     WVPASS(s_ns_eq_ish(from_secs(1), 1, 0))
43     WVPASS(s_ns_eq_ish(from_secs(-1), -1, 0))
44     WVPASS(s_ns_eq_ish(from_secs(-0.5), 0, - 10**9 / 2))
45     WVPASS(s_ns_eq_ish(from_secs(-1.5), -1, - 10**9 / 2))
46     WVPASS(s_ns_eq_ish(from_secs(-1 / 10e8), 0, -1))