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_strip_path():
26 prefix = "/NOT_EXISTING/var/backup/daily.0/localhost"
28 non_matching_prefix = "/home"
29 path = "/NOT_EXISTING/var/backup/daily.0/localhost/etc/"
31 WVPASSEQ(strip_path(prefix, path), '/etc')
32 WVPASSEQ(strip_path(empty_prefix, path), path)
33 WVPASSEQ(strip_path(non_matching_prefix, path), path)
34 WVEXCEPT(Exception, strip_path, None, path)
37 def test_strip_base_path():
38 path = "/NOT_EXISTING/var/backup/daily.0/localhost/etc/"
39 base_paths = ["/NOT_EXISTING/var",
40 "/NOT_EXISTING/var/backup",
41 "/NOT_EXISTING/var/backup/daily.0/localhost"
43 WVPASSEQ(strip_base_path(path, base_paths), '/etc')
46 def test_strip_symlinked_base_path():
47 tmpdir = os.path.join(os.getcwd(),"test_strip_symlinked_base_path.tmp")
48 symlink_src = os.path.join(tmpdir, "private", "var")
49 symlink_dst = os.path.join(tmpdir, "var")
50 path = os.path.join(symlink_dst, "a")
53 os.mkdir(os.path.join(tmpdir, "private"))
55 os.symlink(symlink_src, symlink_dst)
57 result = strip_base_path(path, [symlink_dst])
59 os.remove(symlink_dst)
61 os.rmdir(os.path.join(tmpdir, "private"))
64 WVPASSEQ(result, "/a")
67 def test_graft_path():
68 middle_matching_old_path = "/NOT_EXISTING/user"
69 non_matching_old_path = "/NOT_EXISTING/usr"
70 matching_old_path = "/NOT_EXISTING/home"
71 matching_full_path = "/NOT_EXISTING/home/user"
74 all_graft_points = [(middle_matching_old_path, new_path),
75 (non_matching_old_path, new_path),
76 (matching_old_path, new_path)]
78 path = "/NOT_EXISTING/home/user/"
80 WVPASSEQ(graft_path([(middle_matching_old_path, new_path)], path),
81 "/NOT_EXISTING/home/user")
82 WVPASSEQ(graft_path([(non_matching_old_path, new_path)], path),
83 "/NOT_EXISTING/home/user")
84 WVPASSEQ(graft_path([(matching_old_path, new_path)], path), "/opt/user")
85 WVPASSEQ(graft_path(all_graft_points, path), "/opt/user")
86 WVPASSEQ(graft_path([(matching_full_path, new_path)], path),