Repository: borgbackup/borg

Issue:
test fails with pure-Python msgpack (borg 1.1.x)
ArchiverTestCase.test_compression_auto_compressible fails for me when using a pure Python msgpack.

borg 1.1.9 (also git version from "1.1-maint" branch)
Fedora 29 x86_64
msgpack 0.5.6
python3-pytest-3.6.4-1.fc29.noarch

    python3 setup.py build
    export MSGPACK_PUREPYTHON=1
    export PYTHONPATH=$(pwd)/build/$(ls build/ | grep 'lib.')
    py.test-3 -vx -k "ArchiverTestCase and test_compression"  $PYTHONPATH/borg/testsuite/*.py

        _________ ArchiverTestCase.test_compression_auto_compressible _________

        self = <borg.testsuite.archiver.ArchiverTestCase testMethod=test_compression_auto_compressible>

            def test_compression_auto_compressible(self):
                size, csize = self._get_sizes('auto,zlib', compressible=True)
        >       assert csize < size * 0.1
        E       AssertionError: assert 0 < (0 * 0.1)

        build/lib.linux-x86_64-3.7/borg/testsuite/archiver.py:2077: AssertionError

    unset MSGPACK_PUREPYTHON
    py.test-3 -vx -k "ArchiverTestCase and test_compression"  $PYTHONPATH/borg/testsuite/*.py
    (test passes)

I suspect this might be caused by the slow message warning.



Discussion:
The output of the borg command had warnings about the slow msgpack and that test couldn't cope with that.

I've fixed it, PR coming.

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -92,6 +92,8 @@
 
 STATS_HEADER = "                       Original size      Compressed size    Deduplicated size"
 
+PURE_PYTHON_MSGPACK_WARNING = "Using a pure-python msgpack! This will result in lower performance."
+
 
 def argument(args, str_or_bool):
     """If bool is passed, return it. If str is passed, retrieve named attribute from args."""
@@ -4398,7 +4400,7 @@ def run(self, args):
             logger.error("Do not contact borgbackup support about this.")
             return set_ec(EXIT_ERROR)
         if is_slow_msgpack():
-            logger.warning("Using a pure-python msgpack! This will result in lower performance.")
+            logger.warning(PURE_PYTHON_MSGPACK_WARNING)
         if args.debug_profile:
             # Import only when needed - avoids a further increase in startup time
             import cProfile
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -33,7 +33,7 @@
 import borg
 from .. import xattr, helpers, platform
 from ..archive import Archive, ChunkBuffer, flags_noatime, flags_normal
-from ..archiver import Archiver, parse_storage_quota
+from ..archiver import Archiver, parse_storage_quota, PURE_PYTHON_MSGPACK_WARNING
 from ..cache import Cache, LocalCache
 from ..constants import *  # NOQA
 from ..crypto.low_level import bytes_to_long, num_aes_blocks
@@ -284,12 +284,19 @@ def tearDown(self):
     def cmd(self, *args, **kw):
         exit_code = kw.pop('exit_code', 0)
         fork = kw.pop('fork', None)
+        binary_output = kw.get('binary_output', False)
         if fork is None:
             fork = self.FORK_DEFAULT
         ret, output = exec_cmd(*args, fork=fork, exe=self.EXE, archiver=self.archiver, **kw)
         if ret != exit_code:
             print(output)
         self.assert_equal(ret, exit_code)
+        # if tests are run with the pure-python msgpack, there will be warnings about
+        # this in the output, which would make a lot of tests fail.
+        pp_msg = PURE_PYTHON_MSGPACK_WARNING.encode() if binary_output else PURE_PYTHON_MSGPACK_WARNING
+        empty = b'' if binary_output else ''
+        output = empty.join(line for line in output.splitlines(keepends=True)
+                            if pp_msg not in line)
         return output
 
     def create_src_archive(self, name):
diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py
--- a/src/borg/testsuite/helpers.py
+++ b/src/borg/testsuite/helpers.py
@@ -580,7 +580,7 @@ def test_is_slow_msgpack():
         assert is_slow_msgpack()
     finally:
         msgpack.Packer = saved_packer
-    # this assumes that we have fast msgpack on test platform:
+    # this tests that we have fast msgpack on test platform:
     assert not is_slow_msgpack()
 
 


Test patch: