]> arthur.barton.de Git - bup.git/blob - lib/bup/t/txstat.py
Use absolute_import from the __future__ everywhere
[bup.git] / lib / bup / t / txstat.py
1
2 from __future__ import absolute_import
3 import math, tempfile, subprocess
4
5 from wvtest import *
6
7 import bup._helpers as _helpers
8 from bup import xstat
9 from buptest import no_lingering_errors, test_tempdir
10
11
12 @wvtest
13 def test_fstime():
14     with no_lingering_errors():
15         WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
16         WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
17         WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
18         WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
19         WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
20         WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
21         WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
22         WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
23         WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
24         WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
25
26         WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
27         WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
28         WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
29         WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
30         WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
31         WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
32         WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
33         x = xstat.nsecs_to_timespec(1977777778)
34         WVPASSEQ(type(x[0]), type(0))
35         WVPASSEQ(type(x[1]), type(0))
36         x = xstat.nsecs_to_timespec(-1977777778)
37         WVPASSEQ(type(x[0]), type(0))
38         WVPASSEQ(type(x[1]), type(0))
39
40         WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
41         WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
42         WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
43         WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
44         WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
45         WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
46         WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
47         x = xstat.nsecs_to_timeval(1977777778)
48         WVPASSEQ(type(x[0]), type(0))
49         WVPASSEQ(type(x[1]), type(0))
50         x = xstat.nsecs_to_timeval(-1977777778)
51         WVPASSEQ(type(x[0]), type(0))
52         WVPASSEQ(type(x[1]), type(0))
53
54         WVPASSEQ(xstat.fstime_floor_secs(0), 0)
55         WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
56         WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
57         WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
58         WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
59         WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
60         WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
61
62
63 @wvtest
64 def test_bup_utimensat():
65     if not xstat._bup_utimensat:
66         return
67     with no_lingering_errors():
68         with test_tempdir('bup-txstat-') as tmpdir:
69             path = tmpdir + '/foo'
70             open(path, 'w').close()
71             frac_ts = (0, 10**9 / 2)
72             xstat._bup_utimensat(_helpers.AT_FDCWD, path, (frac_ts, frac_ts), 0)
73             st = _helpers.stat(path)
74             atime_ts = st[8]
75             mtime_ts = st[9]
76             WVPASSEQ(atime_ts[0], 0)
77             WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
78             WVPASSEQ(mtime_ts[0], 0)
79             WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
80
81
82 @wvtest
83 def test_bup_utimes():
84     if not xstat._bup_utimes:
85         return
86     with no_lingering_errors():
87         with test_tempdir('bup-txstat-') as tmpdir:
88             path = tmpdir + '/foo'
89             open(path, 'w').close()
90             frac_ts = (0, 10**6 / 2)
91             xstat._bup_utimes(path, (frac_ts, frac_ts))
92             st = _helpers.stat(path)
93             atime_ts = st[8]
94             mtime_ts = st[9]
95             WVPASSEQ(atime_ts[0], 0)
96             WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
97             WVPASSEQ(mtime_ts[0], 0)
98             WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
99
100
101 @wvtest
102 def test_bup_lutimes():
103     if not xstat._bup_lutimes:
104         return
105     with no_lingering_errors():
106         with test_tempdir('bup-txstat-') as tmpdir:
107             path = tmpdir + '/foo'
108             open(path, 'w').close()
109             frac_ts = (0, 10**6 / 2)
110             xstat._bup_lutimes(path, (frac_ts, frac_ts))
111             st = _helpers.stat(path)
112             atime_ts = st[8]
113             mtime_ts = st[9]
114             WVPASSEQ(atime_ts[0], 0)
115             WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
116             WVPASSEQ(mtime_ts[0], 0)
117             WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)