def test_compress_artifact_if_supported(filename, original_content, expected_content_type, expected_encoding): with tempfile.TemporaryDirectory() as temp_dir: absolute_path = os.path.join(temp_dir, filename) with open(absolute_path, 'w') as f: f.write(original_content) old_number_of_files = _get_number_of_children_in_directory(temp_dir) content_type, encoding = compress_artifact_if_supported(absolute_path) assert (content_type, encoding) == (expected_content_type, expected_encoding) # compress_artifact_if_supported() should replace the existing file assert _get_number_of_children_in_directory(temp_dir) == old_number_of_files open_function = gzip.open if expected_encoding == 'gzip' else open with open_function(absolute_path, 'rt') as f: assert f.read() == original_content
def test_compress_artifact_if_supported(filename, original_content, expected_content_type, expected_encoding): with tempfile.TemporaryDirectory() as temp_dir: absolute_path = os.path.join(temp_dir, filename) with open(absolute_path, 'w') as f: f.write(original_content) old_number_of_files = _get_number_of_children_in_directory(temp_dir) content_type, encoding = compress_artifact_if_supported(absolute_path) assert content_type, encoding == (expected_content_type, expected_encoding) # compress_artifact_if_supported() should replace the existing file assert _get_number_of_children_in_directory(temp_dir) == old_number_of_files open_function = gzip.open if expected_encoding == 'gzip' else open with open_function(absolute_path, 'rt') as f: assert f.read() == original_content