1 import math, tempfile, subprocess
3 import bup._helpers as _helpers
8 WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
9 WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
10 WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
11 WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
12 WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
13 WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
14 WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
15 WVEXCEPT(Exception, xstat.timespec_to_nsecs, (0, -1))
16 WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
17 WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
19 WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
20 WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
21 WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
22 WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
23 WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
24 WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
25 WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
26 x = xstat.nsecs_to_timespec(1977777778)
27 WVPASSEQ(type(x[0]), type(0))
28 WVPASSEQ(type(x[1]), type(0))
29 x = xstat.nsecs_to_timespec(-1977777778)
30 WVPASSEQ(type(x[0]), type(0))
31 WVPASSEQ(type(x[1]), type(0))
33 WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
34 WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
35 WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
36 WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
37 WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
38 WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
39 WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
40 x = xstat.nsecs_to_timeval(1977777778)
41 WVPASSEQ(type(x[0]), type(0))
42 WVPASSEQ(type(x[1]), type(0))
43 x = xstat.nsecs_to_timeval(-1977777778)
44 WVPASSEQ(type(x[0]), type(0))
45 WVPASSEQ(type(x[1]), type(0))
47 WVPASSEQ(xstat.fstime_floor_secs(0), 0)
48 WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
49 WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
50 WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
51 WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
52 WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
53 WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
57 def test_bup_utimensat():
58 if not xstat._bup_utimensat:
60 tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
62 path = tmpdir + '/foo'
63 open(path, 'w').close()
64 frac_ts = (0, 10**9 / 2)
65 xstat._bup_utimensat(_helpers.AT_FDCWD, path, (frac_ts, frac_ts), 0)
66 st = _helpers.stat(path)
69 WVPASSEQ(atime_ts[0], 0)
70 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
71 WVPASSEQ(mtime_ts[0], 0)
72 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
74 subprocess.call(['rm', '-rf', tmpdir])
78 def test_bup_utimes():
79 if not xstat._bup_utimes:
81 tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
83 path = tmpdir + '/foo'
84 open(path, 'w').close()
85 frac_ts = (0, 10**6 / 2)
86 xstat._bup_utimes(path, (frac_ts, frac_ts))
87 st = _helpers.stat(path)
90 WVPASSEQ(atime_ts[0], 0)
91 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
92 WVPASSEQ(mtime_ts[0], 0)
93 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
95 subprocess.call(['rm', '-rf', tmpdir])
99 def test_bup_lutimes():
100 if not xstat._bup_lutimes:
102 tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
104 path = tmpdir + '/foo'
105 open(path, 'w').close()
106 frac_ts = (0, 10**6 / 2)
107 xstat._bup_lutimes(path, (frac_ts, frac_ts))
108 st = _helpers.stat(path)
111 WVPASSEQ(atime_ts[0], 0)
112 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
113 WVPASSEQ(mtime_ts[0], 0)
114 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
116 subprocess.call(['rm', '-rf', tmpdir])