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', [])
52 def test_grafted_path_components():
53 WVPASSEQ(grafted_path_components([('/chroot', '/')], '/foo'),
54 [('', '/'), ('foo', '/foo')])
55 WVPASSEQ(grafted_path_components([('/foo/bar', '')], '/foo/bar/baz/bax'),
56 [('', None), ('baz', None), ('bax', '/foo/bar/baz/bax')])
57 WVEXCEPT(Exception, grafted_path_components, 'foo', [])