3 import bup._helpers as _helpers
4 from bup.helpers import *
12 WVPASSEQ(pn('1.5k'), 1536)
13 WVPASSEQ(pn('2 gb'), 2*1024*1024*1024)
14 WVPASSEQ(pn('1e+9 k'), 1000000000 * 1024)
15 WVPASSEQ(pn('-3e-3mb'), int(-0.003 * 1024 * 1024))
18 def test_detect_fakeroot():
19 if os.getenv('FAKEROOTKEY'):
20 WVPASS(detect_fakeroot())
22 WVPASS(not detect_fakeroot())
25 def test_path_components():
26 WVPASSEQ(path_components('/'), [('', '/')])
27 WVPASSEQ(path_components('/foo'), [('', '/'), ('foo', '/foo')])
28 WVPASSEQ(path_components('/foo/'), [('', '/'), ('foo', '/foo')])
29 WVPASSEQ(path_components('/foo/bar'),
30 [('', '/'), ('foo', '/foo'), ('bar', '/foo/bar')])
31 WVEXCEPT(Exception, path_components, 'foo')
35 def test_stripped_path_components():
36 WVPASSEQ(stripped_path_components('/', []), [('', '/')])
37 WVPASSEQ(stripped_path_components('/', ['']), [('', '/')])
38 WVPASSEQ(stripped_path_components('/', ['/']), [('', '/')])
39 WVPASSEQ(stripped_path_components('/', ['/foo']), [('', '/')])
40 WVPASSEQ(stripped_path_components('/foo', ['/bar']),
41 [('', '/'), ('foo', '/foo')])
42 WVPASSEQ(stripped_path_components('/foo', ['/foo']), [('', '/foo')])
43 WVPASSEQ(stripped_path_components('/foo/bar', ['/foo']),
44 [('', '/foo'), ('bar', '/foo/bar')])
45 WVPASSEQ(stripped_path_components('/foo/bar', ['/bar', '/foo', '/baz']),
46 [('', '/foo'), ('bar', '/foo/bar')])
47 WVPASSEQ(stripped_path_components('/foo/bar/baz', ['/foo/bar/baz']),
48 [('', '/foo/bar/baz')])
49 WVEXCEPT(Exception, stripped_path_components, 'foo', [])
53 def test_grafted_path_components():
54 WVPASSEQ(grafted_path_components([('/chroot', '/')], '/foo'),
55 [('', '/'), ('foo', '/foo')])
56 WVPASSEQ(grafted_path_components([('/foo/bar', '/')], '/foo/bar/baz/bax'),
58 ('baz', '/foo/bar/baz'),
59 ('bax', '/foo/bar/baz/bax')])
60 WVPASSEQ(grafted_path_components([('/foo/bar/baz', '/bax')],
63 ('bax', '/foo/bar/baz'),
64 ('1', '/foo/bar/baz/1'),
65 ('2', '/foo/bar/baz/1/2')])
66 WVPASSEQ(grafted_path_components([('/foo', '/bar/baz/bax')],
73 WVPASSEQ(grafted_path_components([('/foo/bar/baz', '/a/b/c')],
75 [('', None), ('a', None), ('b', None), ('c', '/foo/bar/baz')])
76 WVPASSEQ(grafted_path_components([('/', '/a/b/c/')], '/foo/bar'),
77 [('', None), ('a', None), ('b', None), ('c', '/'),
78 ('foo', '/foo'), ('bar', '/foo/bar')])
79 WVEXCEPT(Exception, grafted_path_components, 'foo', [])
84 x = readpipe(['echo', '42'])
87 readpipe(['bash', '-c', 'exit 42'])
89 WVPASSEQ(str(ex), "subprocess 'bash -c exit 42' failed with status 42")