]> arthur.barton.de Git - bup.git/blob - test/int/test_xstat.py
Remove Client __del__ in favor of context management
[bup.git] / test / int / test_xstat.py
1
2 from __future__ import absolute_import
3
4 from wvpytest import *
5
6 import bup._helpers as _helpers
7 from bup import xstat
8
9
10 def test_fstime():
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))
21
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))
35
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))
49
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))
57
58
59 def test_bup_utimensat(tmpdir):
60     if not xstat._bup_utimensat:
61         return
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)
67     atime_ts = st[8]
68     mtime_ts = st[9]
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])
73
74
75 def test_bup_utimes(tmpdir):
76     if not xstat._bup_utimes:
77         return
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)
83     atime_ts = st[8]
84     mtime_ts = st[9]
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)
89
90
91 def test_bup_lutimes(tmpdir):
92     if not xstat._bup_lutimes:
93         return
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)
99     atime_ts = st[8]
100     mtime_ts = st[9]
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)