use KiB, MiB (factor 1024) instead of KB, MB (factor 1000)
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 07:31:16 +0000 (09:31 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 07:31:16 +0000 (09:31 +0200)
testing/test_multivol_compression_sizes.py

index 5b50331..a2cdf4b 100644 (file)
@@ -29,10 +29,12 @@ from deltatar.tarfile import TarFile, BLOCKSIZE
 
 
 #: tolerances of volume sizes
-SIZE_TOLERANCE_GZ = 32*1024   # 32 KiB due to Gzip/Bzip2 compression object buffer
-SIZE_TOLERANCE_BZ2 = 1024*1024   # 1MB!
-SIZE_TOLERANCE_XZ = 72*1024
-SIZE_TOLERANCE_NONE = 5*BLOCKSIZE
+KiB = 1024
+MiB = KiB * KiB
+SIZE_TOLERANCE_GZ = 32*KiB   # Gzip compression object buffer
+SIZE_TOLERANCE_BZ2 = MiB
+SIZE_TOLERANCE_XZ = 72*KiB
+SIZE_TOLERANCE_NONE = 3*BLOCKSIZE   # should be little
 
 #: variables for find_random_files
 DIR_RETURN_MIN_REC = 5
@@ -139,7 +141,7 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
          clean_up_if_error=False, debug_level=0):
     """ create TarFile with given vol_size, add vol_size*input_size
 
-    :param volume_size: in MB
+    :param volume_size: in MiB
     :param str prefix: optional output prefix
     :param str mode: compression mode for TarFile's mode argument
     :param bool clean_up_if_error: True will ensure there are no files left;
@@ -149,7 +151,7 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
     :returns: True if test failed (some size wrong, file missing, ...)
     """
 
-    input_size = volume_size * input_size_factor * 1e6
+    input_size = volume_size * input_size_factor * MiB
     something_strange = False
 
     if 'gz' in mode:
@@ -180,14 +182,14 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
         if debug_level:
             print(prefix + 'tarfile: ' + temp_name)
 
-        volume_prefix = prefix + 'vol={}MB, in=*{}, mode={}: ' \
+        volume_prefix = prefix + 'vol={}MiB, in=*{}, mode={}: ' \
                                  .format(volume_size, input_size_factor, mode)
         def vol_handler(a,b,c):
             return new_volume_handler(a,b,c, volume_prefix, debug_level)
 
         # create tar object
         tarobj = TarFile.open(temp_name, mode=mode,
-                              max_volume_size=volume_size*1.e6,
+                              max_volume_size=volume_size*MiB,
                               new_volume_handler=vol_handler,
                               password='test1234', debug=debug_level)
 
@@ -199,7 +201,7 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
             if file_name.startswith(base_name):
                 continue    # do not accidentally add self
             new_size = os.lstat(file_name).st_size
-            if new_size > max(volume_size*1.e6, input_size-added_size):
+            if new_size > max(volume_size*MiB, input_size-added_size):
                 continue    # add at most one volume_size too much
             new_name = '{}_{:04d}_{}_{:09d}' \
                        .format(base_name, count,
@@ -209,9 +211,9 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
             files_added.append(new_name)
             added_size += new_size
             if debug_level > 2:
-                print('{}vol={}MB, in=*{}, mode={}: added {:.1f}MB/{:.1f}MB'
+                print('{}vol={}MiB, in=*{}, mode={}: added {:.1f}MiB/{:.1f}MiB'
                       .format(prefix, volume_size, input_size_factor, mode,
-                              added_size/1e6, input_size/1e6))
+                              added_size/MiB, input_size/MiB))
             if added_size > input_size:
                 break
         tarobj.close()
@@ -226,8 +228,8 @@ def test(volume_size, input_size_factor, mode, temp_dir, prefix='',
             volume_size_sum += vol_size
             if debug_level:
                 print('{} - {}: {:.3f}'.format(prefix, file_name,
-                                               vol_size/1.e6))
-            if abs(vol_size - volume_size*1e6) > size_tolerance:
+                                               vol_size/MiB))
+            if abs(vol_size - volume_size*MiB) > size_tolerance:
                 n_wrong_size += 1
 
         if debug_level:
@@ -321,7 +323,7 @@ def test_lots(fast_fail=False):
     :retuns: number of failed tests
     """
 
-    # volume sizes in MB
+    # volume sizes in MiB
     volume_sizes = 10, 100
 
     # input size factor (multiplied with volume size)