2 import bup._helpers as _helpers
4 from bup.helpers import *
12 WVPASSEQ(pn('1.5k'), 1536)
13 WVPASSEQ(pn('2 gb'), 2*1024*1024*1024)
14 WVPASSEQ(pn('1e+9 k'), 1000000000 * 1024)
15 WVPASSEQ(pn('-3e-3mb'), int(-0.003 * 1024 * 1024))
19 def test_detect_fakeroot():
20 if os.getenv('FAKEROOTKEY'):
21 WVPASS(detect_fakeroot())
23 WVPASS(not detect_fakeroot())
28 return math.fabs(x - y) < 1 / 10e8
30 return approx_eq(x[0], y[0]) and approx_eq(x[1], y[1])
32 return approx_eq(x.approx_secs(), y.approx_secs())
33 def s_ns_eq_ish(fst, s, ns):
34 (fst_s, fst_ns) = fst.secs_nsecs()
35 return approx_eq(fst_s, s) and approx_eq(fst_ns, ns)
36 from_secs = FSTime.from_secs
37 from_ts = FSTime.from_timespec
38 WVPASS(from_secs(0) == from_secs(0))
39 WVPASS(from_secs(0) < from_secs(1))
40 WVPASS(from_secs(-1) < from_secs(1))
41 WVPASS(from_secs(1) > from_secs(0))
42 WVPASS(from_secs(1) > from_secs(-1))
44 WVPASS(fst_eq_ish(from_secs(0), from_ts((0, 0))))
45 WVPASS(fst_eq_ish(from_secs(1), from_ts((1, 0))))
46 WVPASS(fst_eq_ish(from_secs(-1), from_ts((-1, 0))))
47 WVPASS(fst_eq_ish(from_secs(-0.5), from_ts((-1, 10**9 / 2))))
48 WVPASS(fst_eq_ish(from_secs(-1.5), from_ts((-2, 10**9 / 2))))
49 WVPASS(fst_eq_ish(from_secs(1 / 10e8), from_ts((0, 1))))
50 WVPASS(fst_eq_ish(from_secs(-1 / 10e8), from_ts((-1, 10**9 - 1))))
52 WVPASS(ts_eq_ish(from_secs(0).to_timespec(), (0, 0)))
53 WVPASS(ts_eq_ish(from_secs(1).to_timespec(), (1, 0)))
54 WVPASS(ts_eq_ish(from_secs(-1).to_timespec(), (-1, 0)))
55 WVPASS(ts_eq_ish(from_secs(-0.5).to_timespec(), (-1, 10**9 / 2)))
56 WVPASS(ts_eq_ish(from_secs(-1.5).to_timespec(), (-2, 10**9 / 2)))
57 WVPASS(ts_eq_ish(from_secs(1 / 10e8).to_timespec(), (0, 1)))
58 WVPASS(ts_eq_ish(from_secs(-1 / 10e8).to_timespec(), (-1, 10**9 - 1)))
60 WVPASS(s_ns_eq_ish(from_secs(0), 0, 0))
61 WVPASS(s_ns_eq_ish(from_secs(1), 1, 0))
62 WVPASS(s_ns_eq_ish(from_secs(-1), -1, 0))
63 WVPASS(s_ns_eq_ish(from_secs(-0.5), 0, - 10**9 / 2))
64 WVPASS(s_ns_eq_ish(from_secs(-1.5), -1, - 10**9 / 2))
65 WVPASS(s_ns_eq_ish(from_secs(-1 / 10e8), 0, -1))
70 if _helpers._have_ns_fs_timestamps: # Test native python timestamp rep too.
71 orig = _helpers._have_ns_fs_timestamps
73 _helpers._have_ns_fs_timestamps = None
76 _helpers._have_ns_fs_timestamps = orig