- repeat with max_volume_size +1, +2, +10, ...
- repeat with file sizes -1, -2, -10, ...
-e.g. for max_volume_size = RECORDSIZE + 1 * BLOCKSIZE:
+Tests use max_volume_size = RECORDSIZE + 1 * BLOCKSIZE:
File 0 has Info0 and blocks Dat00, Dat01, ... Dat0K, (Dat0L, Dat0M, Dat0N)
File 1 has Info1 and blocks Dat10, (Dat11)
end of end of
#: number of blocks per tar volume file
MAX_VOLUME_BLOCKS = N_BLOCKS_PER_RECORD + 1
-#: always print all test output; will produce ~10 lines of text for each of the
-#: ~48000 tests --> not recommended
-ALWAYS_PRINT_EVERYTHING = False
-
def fill_file(file_handle, data_size):
""" fill given file handle with nonsense data of given size
return '{} (= {} BLKs + {})'.format(size, *divmod(size, BLOCKSIZE))
-def test(temp_dir, file_blocks, volume_blocks_arg, offset_blocks,
- file_size_offsets=(0, 0), volume_size_offset=0):
+def do_test(temp_dir, file_blocks, volume_blocks_arg, offset_blocks,
+ file_size_offsets=(0, 0), volume_size_offset=0,
+ print_everything=False):
""" create TarFile with given configuration """
# use delayed + conditional print dprnt, that only prints if necessary
dprnt('extracted {} has wrong contents!'.format(file_name))
# print output only if something went wrong
- if (not everything_ok) or ALWAYS_PRINT_EVERYTHING:
+ if (not everything_ok) or print_everything:
for line in output:
print(line)
return everything_ok
-def main():
- """ Main function, called when running file as script
+def run_all_tests(fast_fail=True, print_everything=False):
+ """ run test with lots of parameter combinations, will take quite a while
see module doc for more info
"""
+ # abbreviations for shorter lists
N = N_BLOCKS_PER_RECORD
M = MAX_VOLUME_BLOCKS
B = BLOCKSIZE
- fast_fail = True
-
# define tests by numbers of blocks:
# n_blocks file 0, 1; n_blocks vol0, 1, offset Info0, Info1, 0-blocks
- tests = (((N-5, 1), (N, 0), (0, N-4, N-2)),
- ((M-5, 1), (M, 0), (0, M-4, M-2)),
- ((M-4, 1), (M+1, 0), (0, M-3, M-1)),
- ((M-3, 1), (M+2, 0), (0, M-2, M)),
- ((M-2, 1), (M-2, 6), (0, 2, 4)),
- ((M-5, 2), (M-2, 4), (0, M-4, 2)),
- ((M-4, 2), (M-1, 4), (0, M-3, 2)))
- size_offsets = (0, 1, 2, 3, 5, 10, 20, 30, 50, 100) + \
- (B-1, B-2, B-3, B-5, B-10, B-20, B-30, B-50, B-100)[::-1]
+ tests = (((N-5, 1), (N, 0), (0, N-4, N-2)), # test case 0
+ ((M-5, 1), (M, 0), (0, M-4, M-2)), # test case 1
+ ((M-4, 1), (M+1, 0), (0, M-3, M-1)), # test case 2
+ ((M-3, 1), (M+2, 0), (0, M-2, M)), # test case 3
+ ((M-2, 1), (M-2, 6), (0, 2, 4)), # test case 4
+ ((M-5, 2), (M-2, 4), (0, M-4, 2)), # test case 5
+ ((M-4, 2), (M-1, 4), (0, M-3, 2))) # test case 6
+
+ # offsets for file and volume sizes in tests:
+ size_offsets = (0, 1, 2, 5, 10, 22, 46, 100) + \
+ (B-1, B-2, B-5, B-10, B-22, B-46, B-100)[::-1]
n_errs = 0
n_tests = 0
break
n_tests += 1
test_succeeded = \
- test(temp_dir, file_sizes, vol_sizes, offsets,
- file_size_offsets=(file_size_offset0,
- file_size_offset1),
- volume_size_offset=volume_size_offset)
+ do_test(temp_dir, file_sizes, vol_sizes, offsets,
+ file_size_offsets=(file_size_offset0,
+ file_size_offset1),
+ volume_size_offset=volume_size_offset,
+ print_everything=print_everything)
if not test_succeeded:
n_errs += 1
if fast_fail:
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(run_all_tests())