3 import bup._helpers as _helpers
4 from bup.xstat import FSTime
8 return math.fabs(x - y) < 1 / 10e8
10 return approx_eq(x[0], y[0]) and approx_eq(x[1], y[1])
12 return approx_eq(x.approx_secs(), y.approx_secs())
13 def s_ns_eq_ish(fst, s, ns):
14 (fst_s, fst_ns) = fst.secs_nsecs()
15 return approx_eq(fst_s, s) and approx_eq(fst_ns, ns)
16 from_secs = FSTime.from_secs
17 from_ts = FSTime.from_timespec
18 WVPASS(from_secs(0) == from_secs(0))
19 WVPASS(from_secs(0) < from_secs(1))
20 WVPASS(from_secs(-1) < from_secs(1))
21 WVPASS(from_secs(1) > from_secs(0))
22 WVPASS(from_secs(1) > from_secs(-1))
24 WVPASS(fst_eq_ish(from_secs(0), from_ts((0, 0))))
25 WVPASS(fst_eq_ish(from_secs(1), from_ts((1, 0))))
26 WVPASS(fst_eq_ish(from_secs(-1), from_ts((-1, 0))))
27 WVPASS(fst_eq_ish(from_secs(-0.5), from_ts((-1, 10**9 / 2))))
28 WVPASS(fst_eq_ish(from_secs(-1.5), from_ts((-2, 10**9 / 2))))
29 WVPASS(fst_eq_ish(from_secs(1 / 10e8), from_ts((0, 1))))
30 WVPASS(fst_eq_ish(from_secs(-1 / 10e8), from_ts((-1, 10**9 - 1))))
32 WVPASS(ts_eq_ish(from_secs(0).to_timespec(), (0, 0)))
33 WVPASS(ts_eq_ish(from_secs(1).to_timespec(), (1, 0)))
34 WVPASS(ts_eq_ish(from_secs(-1).to_timespec(), (-1, 0)))
35 WVPASS(ts_eq_ish(from_secs(-0.5).to_timespec(), (-1, 10**9 / 2)))
36 WVPASS(ts_eq_ish(from_secs(-1.5).to_timespec(), (-2, 10**9 / 2)))
37 WVPASS(ts_eq_ish(from_secs(1 / 10e8).to_timespec(), (0, 1)))
38 WVPASS(ts_eq_ish(from_secs(-1 / 10e8).to_timespec(), (-1, 10**9 - 1)))
40 WVPASS(s_ns_eq_ish(from_secs(0), 0, 0))
41 WVPASS(s_ns_eq_ish(from_secs(1), 1, 0))
42 WVPASS(s_ns_eq_ish(from_secs(-1), -1, 0))
43 WVPASS(s_ns_eq_ish(from_secs(-0.5), 0, - 10**9 / 2))
44 WVPASS(s_ns_eq_ish(from_secs(-1.5), -1, - 10**9 / 2))
45 WVPASS(s_ns_eq_ish(from_secs(-1 / 10e8), 0, -1))
50 if _helpers._have_ns_fs_timestamps: # Test native python timestamp rep too.
51 orig = _helpers._have_ns_fs_timestamps
53 _helpers._have_ns_fs_timestamps = None
56 _helpers._have_ns_fs_timestamps = orig