예제 #1
0
def test_process_file_with_rename_should_remove_original_file(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_1_2_9_11_12_INPUT)

    process_file(input_file, OUTPUT_FILE_NAME, keep_input_file=False)

    assert os.listdir(input_file.dirname) == [OUTPUT_FILE_NAME]
예제 #2
0
def test_process_file_without_env_should_raise_error(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_3_10_INPUT)

    with pytest.raises(ValueError):
        process_file(input_file)

    input_file.remove()
예제 #3
0
def test_process_file_backup_file_deletion(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_1_2_9_11_12_INPUT)

    process_file(input_file)

    assert os.listdir(input_file.dirname) == [INPUT_FILE_NAME]
    input_file.remove()
예제 #4
0
def test_process_file_with_incorrect_fstring_syntax_2(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_7_INPUT)

    process_file(input_file)

    content = input_file.read()
    input_file.remove()

    assert content == TEST_CASE_7_OUTPUT
예제 #5
0
def test_process_file_with_multiple_fstrings(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_4_INPUT)

    process_file(input_file)

    content = input_file.read()
    input_file.remove()

    assert content == TEST_CASE_1_4_5_OUTPUT
예제 #6
0
def test_process_file_without_env(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_1_2_9_11_12_INPUT)

    process_file(input_file)

    content = input_file.read()
    input_file.remove()

    assert content == TEST_CASE_1_4_5_OUTPUT
예제 #7
0
def test_process_file_with_rename_should_not_remove_original_file(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_1_2_9_11_12_INPUT)

    process_file(input_file, OUTPUT_FILE_NAME)

    content = input_file.read()
    assert content == TEST_CASE_1_2_9_11_12_INPUT

    assert os.listdir(
        input_file.dirname) == [INPUT_FILE_NAME, OUTPUT_FILE_NAME]
예제 #8
0
def test_process_file_backup_if_exception_raised(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_3_10_INPUT)

    with pytest.raises(ValueError):
        process_file(input_file)

    content = input_file.read()
    input_file.remove()

    assert content == TEST_CASE_3_10_INPUT
예제 #9
0
def test_process_file_with_multiple_fstrings_on_different_strings(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_5_INPUT)

    os.environ['host'] = 'localhost'

    process_file(input_file)

    content = input_file.read()
    del os.environ['host']
    input_file.remove()

    assert content == TEST_CASE_1_4_5_OUTPUT
예제 #10
0
def test_process_file_with_env(tmpdir):
    input_file = tmpdir.mkdir('tmp').join(INPUT_FILE_NAME)
    input_file.write(TEST_CASE_1_2_9_11_12_INPUT)

    os.environ['log_file_path'] = 'env_file.tmp'

    process_file(input_file)

    content = input_file.read()
    del os.environ['log_file_path']
    input_file.remove()

    assert content == TEST_CASE_2_OUTPUT