2 from __future__ import absolute_import
6 import bup._helpers as _helpers
11 WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
12 WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
13 WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
14 WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
15 WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
16 WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
17 WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
18 WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
19 WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
20 WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
22 WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
23 WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
24 WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
25 WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
26 WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
27 WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
28 WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
29 x = xstat.nsecs_to_timespec(1977777778)
30 WVPASSEQ(type(x[0]), type(0))
31 WVPASSEQ(type(x[1]), type(0))
32 x = xstat.nsecs_to_timespec(-1977777778)
33 WVPASSEQ(type(x[0]), type(0))
34 WVPASSEQ(type(x[1]), type(0))
36 WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
37 WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
38 WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
39 WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
40 WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
41 WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
42 WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
43 x = xstat.nsecs_to_timeval(1977777778)
44 WVPASSEQ(type(x[0]), type(0))
45 WVPASSEQ(type(x[1]), type(0))
46 x = xstat.nsecs_to_timeval(-1977777778)
47 WVPASSEQ(type(x[0]), type(0))
48 WVPASSEQ(type(x[1]), type(0))
50 WVPASSEQ(xstat.fstime_floor_secs(0), 0)
51 WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
52 WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
53 WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
54 WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
55 WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
56 WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
59 def test_bup_utimensat(tmpdir):
60 if not xstat._bup_utimensat:
62 path = tmpdir + b'/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])
75 def test_bup_utimes(tmpdir):
76 if not xstat._bup_utimes:
78 path = tmpdir + b'/foo'
79 open(path, 'w').close()
80 frac_ts = (0, 10**6 // 2)
81 xstat._bup_utimes(path, (frac_ts, frac_ts))
82 st = _helpers.stat(path)
85 WVPASSEQ(atime_ts[0], 0)
86 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
87 WVPASSEQ(mtime_ts[0], 0)
88 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
91 def test_bup_lutimes(tmpdir):
92 if not xstat._bup_lutimes:
94 path = tmpdir + b'/foo'
95 open(path, 'w').close()
96 frac_ts = (0, 10**6 // 2)
97 xstat._bup_lutimes(path, (frac_ts, frac_ts))
98 st = _helpers.stat(path)
101 WVPASSEQ(atime_ts[0], 0)
102 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
103 WVPASSEQ(mtime_ts[0], 0)
104 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)