]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/thelpers.py
get: adjust for python 3 and test there
[bup.git] / lib / bup / t / thelpers.py
index 428970352716e593dcaf7cb20d4627a3963b2540..17ee6357debac8960c9130a2ce6a5f1856a4ee17 100644 (file)
@@ -9,6 +9,7 @@ from bup.compat import bytes_from_byte, bytes_from_uint, environ
 from bup.helpers import (atomically_replaced_file, batchpipe, detect_fakeroot,
                          grafted_path_components, mkdirp, parse_num,
                          path_components, readpipe, stripped_path_components,
+                         shstr,
                          utc_offset_str)
 from buptest import no_lingering_errors, test_tempdir
 import bup._helpers as _helpers
@@ -102,6 +103,28 @@ def test_grafted_path_components():
         WVEXCEPT(Exception, grafted_path_components, b'foo', [])
 
 
+@wvtest
+def test_shstr():
+    with no_lingering_errors():
+        # Do nothing for strings and bytes
+        WVPASSEQ(shstr(b''), b'')
+        WVPASSEQ(shstr(b'1'), b'1')
+        WVPASSEQ(shstr(b'1 2'), b'1 2')
+        WVPASSEQ(shstr(b"1'2"), b"1'2")
+        WVPASSEQ(shstr(''), '')
+        WVPASSEQ(shstr('1'), '1')
+        WVPASSEQ(shstr('1 2'), '1 2')
+        WVPASSEQ(shstr("1'2"), "1'2")
+
+        # Escape parts of sequences
+        WVPASSEQ(shstr((b'1 2', b'3')), b"'1 2' 3")
+        WVPASSEQ(shstr((b"1'2", b'3')), b"'1'\"'\"'2' 3")
+        WVPASSEQ(shstr((b"'1", b'3')), b"''\"'\"'1' 3")
+        WVPASSEQ(shstr(('1 2', '3')), "'1 2' 3")
+        WVPASSEQ(shstr(("1'2", '3')), "'1'\"'\"'2' 3")
+        WVPASSEQ(shstr(("'1", '3')), "''\"'\"'1' 3")
+
+
 @wvtest
 def test_readpipe():
     with no_lingering_errors():
@@ -110,11 +133,9 @@ def test_readpipe():
         try:
             readpipe([b'bash', b'-c', b'exit 42'])
         except Exception as ex:
-            if not re.match("^subprocess b?'bash -c exit 42' failed with status 42$",
-                            str(ex)):
-                WVPASSEQ(str(ex),
-                         "^subprocess b?'bash -c exit 42' failed with status 42$")
-
+            rx = '^subprocess b?"bash -c \'exit 42\'" failed with status 42$'
+            if not re.match(rx, str(ex)):
+                WVPASSEQ(str(ex), rx)
 
 
 @wvtest