X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Ft%2Ftxstat.py;h=30b8284c68fe0b4d7ebaf9a3a79599b3e6c575a2;hb=afff24f20e1305ccdbbdc515780d607dc1447611;hp=a56ac05b07936e1d5f74699dca1c0cd72ec5c92c;hpb=d7bcb23ffad19a0484196ab8a53192aba642fc43;p=bup.git diff --git a/lib/bup/t/txstat.py b/lib/bup/t/txstat.py index a56ac05..30b8284 100644 --- a/lib/bup/t/txstat.py +++ b/lib/bup/t/txstat.py @@ -1,56 +1,39 @@ import math from wvtest import * import bup._helpers as _helpers -from bup.xstat import FSTime - -def _test_fstime(): - def approx_eq(x, y): - return math.fabs(x - y) < 1 / 10e8 - def ts_eq_ish(x, y): - return approx_eq(x[0], y[0]) and approx_eq(x[1], y[1]) - def fst_eq_ish(x, y): - return approx_eq(x.approx_secs(), y.approx_secs()) - def s_ns_eq_ish(fst, s, ns): - (fst_s, fst_ns) = fst.secs_nsecs() - return approx_eq(fst_s, s) and approx_eq(fst_ns, ns) - from_secs = FSTime.from_secs - from_ts = FSTime.from_timespec - WVPASS(from_secs(0) == from_secs(0)) - WVPASS(from_secs(0) < from_secs(1)) - WVPASS(from_secs(-1) < from_secs(1)) - WVPASS(from_secs(1) > from_secs(0)) - WVPASS(from_secs(1) > from_secs(-1)) - - WVPASS(fst_eq_ish(from_secs(0), from_ts((0, 0)))) - WVPASS(fst_eq_ish(from_secs(1), from_ts((1, 0)))) - WVPASS(fst_eq_ish(from_secs(-1), from_ts((-1, 0)))) - WVPASS(fst_eq_ish(from_secs(-0.5), from_ts((-1, 10**9 / 2)))) - WVPASS(fst_eq_ish(from_secs(-1.5), from_ts((-2, 10**9 / 2)))) - WVPASS(fst_eq_ish(from_secs(1 / 10e8), from_ts((0, 1)))) - WVPASS(fst_eq_ish(from_secs(-1 / 10e8), from_ts((-1, 10**9 - 1)))) - - WVPASS(ts_eq_ish(from_secs(0).to_timespec(), (0, 0))) - WVPASS(ts_eq_ish(from_secs(1).to_timespec(), (1, 0))) - WVPASS(ts_eq_ish(from_secs(-1).to_timespec(), (-1, 0))) - WVPASS(ts_eq_ish(from_secs(-0.5).to_timespec(), (-1, 10**9 / 2))) - WVPASS(ts_eq_ish(from_secs(-1.5).to_timespec(), (-2, 10**9 / 2))) - WVPASS(ts_eq_ish(from_secs(1 / 10e8).to_timespec(), (0, 1))) - WVPASS(ts_eq_ish(from_secs(-1 / 10e8).to_timespec(), (-1, 10**9 - 1))) - - WVPASS(s_ns_eq_ish(from_secs(0), 0, 0)) - WVPASS(s_ns_eq_ish(from_secs(1), 1, 0)) - WVPASS(s_ns_eq_ish(from_secs(-1), -1, 0)) - WVPASS(s_ns_eq_ish(from_secs(-0.5), 0, - 10**9 / 2)) - WVPASS(s_ns_eq_ish(from_secs(-1.5), -1, - 10**9 / 2)) - WVPASS(s_ns_eq_ish(from_secs(-1 / 10e8), 0, -1)) +from bup import xstat @wvtest def test_fstime(): - _test_fstime(); - if _helpers._have_ns_fs_timestamps: # Test native python timestamp rep too. - orig = _helpers._have_ns_fs_timestamps - try: - _helpers._have_ns_fs_timestamps = None - _test_fstime(); - finally: - _helpers._have_ns_fs_timestamps = orig + WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0) + WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9) + WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000) + WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000) + WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9) + WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000) + WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000) + WVEXCEPT(Exception, xstat.timespec_to_nsecs, (0, -1)) + WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0)) + WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0)) + + WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0)) + WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0)) + WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2)) + WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2)) + WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0)) + WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2)) + WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2)) + x = xstat.nsecs_to_timespec(1977777778) + WVPASSEQ(type(x[0]), type(0)) + WVPASSEQ(type(x[1]), type(0)) + x = xstat.nsecs_to_timespec(-1977777778) + WVPASSEQ(type(x[0]), type(0)) + WVPASSEQ(type(x[1]), type(0)) + + WVPASSEQ(xstat.fstime_floor_secs(0), 0) + WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0) + WVPASSEQ(xstat.fstime_floor_secs(10**9), 1) + WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1) + WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1) + WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0)) + WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))