Example #1
0
def test_run_sort_high_low(file_system):
    """
    Test it can sort files high to low
    """
    instructions = {
        "Directory": "*",
        "Recursive": "False",
        "RegexExpression": r"file(\d)",
        "OutputName": "out.txt",
        "SortType": "HighLow"
    }
    workfolder = file_system["main"]["dir"].as_posix()
    var = MergeFiles(workfolder, instructions)
    run_success = var.run()

    assert run_success, "Expected to run successfully"
    output_file = file_system["main"]["dir"] / "out.txt"
    assert output_file.exists()

    output_file = output_file.as_posix()
    result = []
    with open(output_file, 'r') as file_read:
        for line in file_read:
            result.append(line)

    expected_result = ["3\n", "2\n", "1\n"]
    assert result == expected_result
Example #2
0
def test_run_instructions_none(file_system):
    """
    Testing run fails if necessary instructions is not given
    """
    workfolder = file_system["main"]["dir"].as_posix()
    var = MergeFiles(workfolder, None)
    run_success = var.run()
    assert not run_success
Example #3
0
def test_run_workfolder_none():
    """
    Test it cant run when no valid workfolder is given
    """
    instructions = {
        "Directory": "*",
        "Recursive": "False",
        "RegexExpression": r"file(\d)",
        "OutputName": "out.txt"
    }
    var = MergeFiles(None, instructions)
    run_success = var.run()
    assert not run_success
Example #4
0
def test_run_sub_directory(file_system):
    """
    Test it run in relative path
    """
    instructions = {
        "Directory": "sub",
        "Recursive": "False",
        "RegexExpression": r"file(\d)",
        "OutputName": "out.txt"
    }
    workfolder = file_system["main"]["dir"].as_posix()
    var = MergeFiles(workfolder, instructions)
    run_success = var.run()

    assert run_success, "Expected to run successfully"
    assert (file_system["sub"]["dir"] / "out.txt").exists()
Example #5
0
def test_run_delete(file_system):
    """
    Test delete files when running
    """
    instructions = {
        "Directory": "*",
        "Recursive": "False",
        "RegexExpression": r"file(\d)",
        "OutputName": "out.txt",
        "Delete": "True"
    }
    workfolder = file_system["main"]["dir"].as_posix()
    var = MergeFiles(workfolder, instructions)
    run_success = var.run()

    assert run_success, "Expected to run successfully"
    assert (file_system["main"]["dir"] / "out.txt").exists()
    assert not file_system["main"]["file1"].exists()
    assert not file_system["main"]["file2"].exists()
    assert not file_system["main"]["file3"].exists()