示例#1
0
def test_concatenate_files():
    inputs = ["tests/data/cat_1.txt", "tests/data/cat_2.txt", "tests/data/cat_3.txt"]
    output = "tests/data/cat_output.txt"
    with mock.patch("locopy.utility.os.remove") as mock_remove:
        concatenate_files(inputs, output)
        assert mock_remove.call_count == 3
        assert [int(line.rstrip("\n")) for line in open(output)] == list(range(1, 16))
    os.remove(output)
示例#2
0
def test_concatenate_files_exception():
    inputs = ["tests/data/cat_1.txt", "tests/data/cat_2.txt", "tests/data/cat_3.txt"]
    output = "tests/data/cat_output.txt"
    with pytest.raises(LocopyConcatError):
        concatenate_files([], output, remove=False)

    with mock.patch("locopy.utility.open") as mock_open:
        mock_open.side_effect = Exception()
        with pytest.raises(LocopyConcatError):
            concatenate_files(inputs, output, remove=False)