Пример #1
0
def test_cleaning_up_temporary_files(batch_size):
    input_paths, _, temp_dir = setup_func()

    with NamedTemporaryFile('w+') as outfile:
        ivcfmerge_batch(input_paths, outfile.name, batch_size, temp_dir)

    # Will throw exception if not empty
    Path(temp_dir).rmdir()
Пример #2
0
def test_custom_temporary_directory(batch_size):
    input_paths, ref_merged_path, temp_dir = setup_func()

    with NamedTemporaryFile('w+') as outfile, open(ref_merged_path, 'r') as ref_merged:
        ivcfmerge_batch(input_paths, outfile.name, batch_size, temp_dir)
        output = outfile.read()

        assert output == ref_merged.read()
Пример #3
0
def test_merging_example_input(batch_size):
    input_paths, ref_merged_path, _ = setup_func()

    with NamedTemporaryFile('w+') as outfile, open(ref_merged_path, 'r') as ref_merged:
        ivcfmerge_batch(input_paths, outfile.name, batch_size)
        output = outfile.read()

        assert output == ref_merged.read()
Пример #4
0
def test_not_cleaning_up_other_files(batch_size):
    input_paths, _, temp_dir = setup_func()
    (Path(temp_dir) / 'other').touch()

    with NamedTemporaryFile('w+') as outfile:
        ivcfmerge_batch(input_paths, outfile.name, batch_size, temp_dir)

    with pytest.raises(OSError):
        Path(temp_dir).rmdir()
Пример #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--batch-size', type=int)
    parser.add_argument('--temp-dir', type=str)
    parser.add_argument('input_paths_file', type=str)
    parser.add_argument('output_path', type=str)
    args = parser.parse_args()

    with open(args.input_paths_file, 'r') as input_paths_file:
        input_paths = input_paths_file.read().splitlines()
        ivcfmerge_batch(input_paths, args.output_path, args.batch_size,
                        args.temp_dir)
Пример #6
0
def test_not_cleaning_up_temporary_directory_in_failures(batch_size):
    input_paths, _, temp_dir = setup_func()

    expected_error = Exception

    def write_file(temp_dir):
        open(Path(temp_dir) / 'random', 'w')

    with mock.patch('ivcfmerge.batch._ivcfmerge', side_effect=[write_file(temp_dir), expected_error]),\
            NamedTemporaryFile('w+') as outfile, pytest.raises(expected_error):
        ivcfmerge_batch(input_paths, outfile.name, batch_size, temp_dir)

    with pytest.raises(OSError):
        Path(temp_dir).rmdir()
Пример #7
0
def test_single_input_yields_the_same_output_as_normal_ivcfmerge(batch_size):
    input_paths = ['tests/data/input/1.vcf']

    with ExitStack() as stack:
        files = map(lambda fn: stack.enter_context(open(fn)), input_paths)
        with TemporaryFile('w+') as outfile:
            ivcfmerge(files, outfile)
            outfile.seek(0)
            expected = outfile.read()

    with NamedTemporaryFile('w+') as outfile:
        ivcfmerge_batch(input_paths, outfile.name, batch_size)
        output = outfile.read()

    assert output == expected
Пример #8
0
def test_out_of_bound_batch_sizes_yield_the_same_output_as_normal_ivcfmerge(batch_size):
    input_paths, _, _ = setup_func()

    with ExitStack() as stack:
        files = map(lambda fn: stack.enter_context(open(fn)), input_paths)
        with TemporaryFile('w+') as outfile:
            ivcfmerge(files, outfile)
            outfile.seek(0)
            expected = outfile.read()

    with NamedTemporaryFile('w+') as outfile:
        ivcfmerge_batch(input_paths, outfile.name, batch_size)
        output = outfile.read()

    assert output == expected