]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/thelpers.py
Adds a strip and strip-path option to bup save.
[bup.git] / lib / bup / t / thelpers.py
index 9f24962644fb25072c27879968f98e38ee62fba8..306d39b943118b3dc0698354fd00e518ac3b2a9b 100644 (file)
@@ -10,3 +10,21 @@ def test_parse_num():
     WVPASSEQ(pn('2 gb'), 2*1024*1024*1024)
     WVPASSEQ(pn('1e+9 k'), 1000000000 * 1024)
     WVPASSEQ(pn('-3e-3mb'), int(-0.003 * 1024 * 1024))
+
+@wvtest
+def test_strip_path():
+    prefix = "/var/backup/daily.0/localhost"
+    empty_prefix = ""
+    non_matching_prefix = "/home"
+    path = "/var/backup/daily.0/localhost/etc/"
+
+    WVPASSEQ(strip_path(prefix, path), '/etc')
+    WVPASSEQ(strip_path(empty_prefix, path), path)
+    WVPASSEQ(strip_path(non_matching_prefix, path), path)
+    WVEXCEPT(Exception, strip_path, None, path)
+
+@wvtest
+def test_strip_base_path():
+    path = "/var/backup/daily.0/localhost/etc/"
+    base_paths = ["/var", "/var/backup", "/var/backup/daily.0/localhost"]
+    WVPASSEQ(strip_base_path(path, base_paths), '/etc')