Ver código fonte

ChunkerParams: fix parameter order

the parser for the --chunker-params argument had a wrong parameter order.
fixed the order so it conforms to the help text and the docs.
also added some tests for it and a text for the ValueError exception.
Thomas Waldmann 9 anos atrás
pai
commit
93a89d97fa
2 arquivos alterados com 11 adições e 4 exclusões
  1. 3 3
      borg/helpers.py
  2. 8 1
      borg/testsuite/helpers.py

+ 3 - 3
borg/helpers.py

@@ -277,12 +277,12 @@ def timestamp(s):
 
 
 
 
 def ChunkerParams(s):
 def ChunkerParams(s):
-    window_size, chunk_mask, chunk_min, chunk_max = s.split(',')
+    chunk_min, chunk_max, chunk_mask, window_size = s.split(',')
     if int(chunk_max) > 23:
     if int(chunk_max) > 23:
         # do not go beyond 2**23 (8MB) chunk size now,
         # do not go beyond 2**23 (8MB) chunk size now,
         # COMPR_BUFFER can only cope with up to this size
         # COMPR_BUFFER can only cope with up to this size
-        raise ValueError
-    return int(window_size), int(chunk_mask), int(chunk_min), int(chunk_max)
+        raise ValueError('max. chunk size exponent must not be more than 23 (2^23 = 8MiB max. chunk size)')
+    return int(chunk_min), int(chunk_max), int(chunk_mask), int(window_size)
 
 
 
 
 def CompressionSpec(s):
 def CompressionSpec(s):

+ 8 - 1
borg/testsuite/helpers.py

@@ -7,7 +7,7 @@ import msgpack
 
 
 from ..helpers import adjust_patterns, exclude_path, Location, format_timedelta, ExcludePattern, make_path_safe, \
 from ..helpers import adjust_patterns, exclude_path, Location, format_timedelta, ExcludePattern, make_path_safe, \
     prune_within, prune_split, \
     prune_within, prune_split, \
-    StableDict, int_to_bigint, bigint_to_int, parse_timestamp, CompressionSpec
+    StableDict, int_to_bigint, bigint_to_int, parse_timestamp, CompressionSpec, ChunkerParams
 from . import BaseTestCase
 from . import BaseTestCase
 
 
 
 
@@ -129,6 +129,13 @@ def test_compression_specs():
         CompressionSpec('invalid')
         CompressionSpec('invalid')
 
 
 
 
+def test_chunkerparams():
+    assert ChunkerParams('19,23,21,4095') == (19, 23, 21, 4095)
+    assert ChunkerParams('10,23,16,4095') == (10, 23, 16, 4095)
+    with pytest.raises(ValueError):
+        ChunkerParams('19,24,21,4095')
+
+
 class MakePathSafeTestCase(BaseTestCase):
 class MakePathSafeTestCase(BaseTestCase):
 
 
     def test(self):
     def test(self):