def test_collect_file_size_filter(temp_dir):
    # Create a file that should be collected
    test_file = os.path.join(temp_dir, 'test_file.txt')

    with open(test_file, 'w') as f:
        f.write('content')

    # Create a file that should be ignored due to its size
    test_big_file = os.path.join(temp_dir, 'test_big_file.txt')

    with open(test_big_file, 'w') as f:
        f.write('some bigger content')

    output = Outputs(temp_dir, '10', False)  # Set maximum size to 10 bytes
    output.add_collected_file('TestArtifact',
                              OSFileSystem('/').get_fullpath(test_file))
    output.add_collected_file('TestArtifact',
                              OSFileSystem('/').get_fullpath(test_big_file))
    output.close()

    zip_content = io.BytesIO(output_file_content(temp_dir, '*-files.zip'))
    zipfile = ZipFile(zip_content)
    zipped_files = zipfile.namelist()

    assert len(zipped_files) == 1
    assert zipped_files[0].endswith('test_file.txt')

    logs = output_file_content(temp_dir, '*-logs.txt')
    assert b"test_big_file.txt' because of its size" in logs
示例#2
0
def test_collect_file(temp_dir, test_file):
    output = Outputs(temp_dir, None, False)
    output.add_collected_file('TestArtifact',
                              OSFileSystem('/').get_fullpath(test_file))
    output.close()

    zip_content = io.BytesIO(output_file_content(temp_dir, '*-files.zip'))
    zipfile = ZipFile(zip_content)
    zipped_file = zipfile.namelist()[0]

    assert zipped_file.endswith('test_file.txt')