]> arthur.barton.de Git - bup.git/blob - lib/bup/t/thelpers.py
Adds --graft option to bup save.
[bup.git] / lib / bup / t / thelpers.py
1 from bup.helpers import *
2 from wvtest import *
3
4 @wvtest
5 def test_parse_num():
6     pn = parse_num
7     WVPASSEQ(pn('1'), 1)
8     WVPASSEQ(pn('0'), 0)
9     WVPASSEQ(pn('1.5k'), 1536)
10     WVPASSEQ(pn('2 gb'), 2*1024*1024*1024)
11     WVPASSEQ(pn('1e+9 k'), 1000000000 * 1024)
12     WVPASSEQ(pn('-3e-3mb'), int(-0.003 * 1024 * 1024))
13
14 @wvtest
15 def test_strip_path():
16     prefix = "/var/backup/daily.0/localhost"
17     empty_prefix = ""
18     non_matching_prefix = "/home"
19     path = "/var/backup/daily.0/localhost/etc/"
20
21     WVPASSEQ(strip_path(prefix, path), '/etc')
22     WVPASSEQ(strip_path(empty_prefix, path), path)
23     WVPASSEQ(strip_path(non_matching_prefix, path), path)
24     WVEXCEPT(Exception, strip_path, None, path)
25
26 @wvtest
27 def test_strip_base_path():
28     path = "/var/backup/daily.0/localhost/etc/"
29     base_paths = ["/var", "/var/backup", "/var/backup/daily.0/localhost"]
30     WVPASSEQ(strip_base_path(path, base_paths), '/etc')
31
32 @wvtest
33 def test_graft_path():
34     middle_matching_old_path = "/user"
35     non_matching_old_path = "/usr"
36     matching_old_path = "/home"
37     matching_full_path = "/home/user"
38     new_path = "/opt"
39
40     all_graft_points = [(middle_matching_old_path, new_path),
41                         (non_matching_old_path, new_path),
42                         (matching_old_path, new_path)]
43
44     path = "/home/user/"
45
46     WVPASSEQ(graft_path([(middle_matching_old_path, new_path)], path),
47                         "/home/user")
48     WVPASSEQ(graft_path([(non_matching_old_path, new_path)], path),
49                         "/home/user")
50     WVPASSEQ(graft_path([(matching_old_path, new_path)], path), "/opt/user")
51     WVPASSEQ(graft_path(all_graft_points, path), "/opt/user")
52     WVPASSEQ(graft_path([(matching_full_path, new_path)], path),
53                         "/opt")