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
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():
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