コード例 #1
0
def test_check_if_paths_exist_positive():
    single_path_to_check = os.listdir(".")[0]
    list_of_paths_to_check = os.listdir(".")
    assert check_if_paths_exist(single_path_to_check) is None
    assert check_if_paths_exist(single_path_to_check, Warning) is None
    assert check_if_paths_exist(single_path_to_check, execution_mode="return")
    assert check_if_paths_exist(single_path_to_check,
                                handle_with=Warning,
                                execution_mode="return")
    assert check_if_paths_exist(Path(single_path_to_check)) is None

    assert check_if_paths_exist(list_of_paths_to_check) is None
    assert check_if_paths_exist(list_of_paths_to_check, Warning) is None
    assert (check_if_paths_exist(
        Path(path) for path in list_of_paths_to_check) is None)

    check_result = check_if_paths_exist(list_of_paths_to_check,
                                        execution_mode="return")
    assert len(check_result) == 2
    assert check_result[0] is None
    assert check_result[1] == []

    check_result = check_if_paths_exist(list_of_paths_to_check,
                                        handle_with=Warning,
                                        execution_mode="return")
    assert len(check_result) == 2
    assert check_result[0] is None
    assert check_result[1] == []
コード例 #2
0
def test_assert_functions():
    assert assert_if(10 > 5) == check_if(10 > 5)
    with pytest.raises(AssertionError):
        assert_if(10 < 5) and check_if(10 < 5) is None

    assert assert_if_not(10 < 5) == check_if_not(10 < 5)
    with pytest.raises(AssertionError):
        assert_if_not(10 > 5) and check_if_not(10 > 5) is None

    assert assert_type((10, 10), tuple) == check_type((10, 10), tuple)
    with pytest.raises(TypeError):
        assert_type(10, tuple) and check_type(10, tuple) is None

    assert assert_length("str", 3) == check_length("str", 3)
    assert assert_length(5, 1, assign_length_to_others=True) == check_length(
        5, 1, assign_length_to_others=True)
    with pytest.raises(TypeError):
        assert_length(5, 3) and check_length(5, 3) is None
    with pytest.raises(LengthError):
        (assert_length(5, 3, assign_length_to_others=True)
         and check_length(5, 3, assign_length_to_others=True) is None)

    existing_file = os.listdir(".")[0]
    assert check_if_paths_exist(existing_file,
                                execution_mode="return") == assert_paths(
                                    existing_file, execution_mode="return")
    assert (check_if_paths_exist("Q:/E/",
                                 execution_mode="return")[1] == assert_paths(
                                     "Q:/E/", execution_mode="return")[1])
    with pytest.raises(FileNotFoundError):
        assert_paths("Q:/E/") and check_if_paths_exist("Q:/E/") is None
コード例 #3
0
def test_assert_functions():
    assert assert_if(10 > 5) == check_if(10 > 5)
    with pytest.raises(AssertionError):
        assert_if(10 < 5) and check_if(10 < 5) is None

    assert assert_if_not(10 < 5) == check_if_not(10 < 5)
    with pytest.raises(AssertionError):
        assert_if_not(10 > 5) and check_if_not(10 > 5) is None

    assert assert_instance((10, 10), tuple) == check_instance((10, 10), tuple)
    with pytest.raises(TypeError):
        assert_instance(10, tuple) and check_instance(10, tuple) is None

    assert assert_length('str', 3) == check_length('str', 3)
    assert (assert_length(5, 1, assign_length_to_others=True) == check_length(
        5, 1, assign_length_to_others=True))
    with pytest.raises(TypeError):
        assert_length(5, 3) and check_length(5, 3) is None
    with pytest.raises(LengthError):
        (assert_length(5, 3, assign_length_to_others=True)
         and check_length(5, 3, assign_length_to_others=True) is None)

    existing_file = os.listdir('.')[0]
    assert (check_if_paths_exist(existing_file,
                                 execution_mode='return') == assert_paths(
                                     existing_file, execution_mode='return'))
    assert (check_if_paths_exist('Q:/E/',
                                 execution_mode='return')[1] == assert_paths(
                                     'Q:/E/', execution_mode='return')[1])
    with pytest.raises(FileNotFoundError):
        assert_paths('Q:/E/') and check_if_paths_exist('Q:/E/') is None
コード例 #4
0
def test_check_if_paths_exist_negative_warnings():
    non_existing_path = "Z:/Op/Oop"
    with warnings.catch_warnings(record=True):
        check_if_paths_exist(non_existing_path, Warning, "Path issue")
    with warnings.catch_warnings(record=True):
        check_if_paths_exist(Path(non_existing_path), Warning, "Path issue")
    with warnings.catch_warnings(record=True):
        check_if_paths_exist([non_existing_path] + os.listdir("."), Warning,
                             "Path issue")

    check_result = check_if_paths_exist(
        non_existing_path,
        handle_with=Warning,
        message="Path issue",
        execution_mode="return",
    )
    assert len(check_result) == 2
    assert type(check_result[0]) == Warning
    assert "Path issue" in str(check_result[0])
    assert check_result[1] == [non_existing_path]

    check_result = check_if_paths_exist(
        [non_existing_path] + os.listdir("."),
        handle_with=Warning,
        message="Path issue",
        execution_mode="return",
    )
    assert len(check_result) == 2
    assert type(check_result[0]) == Warning
    assert "Path issue" in str(check_result[0])
    assert check_result[1] == [non_existing_path]
コード例 #5
0
def test_check_if_paths_exist_negative_warnings():
    non_existing_path = 'Z:/Op/Oop'
    with warnings.catch_warnings(record=True):
        check_if_paths_exist(non_existing_path, Warning, 'Path issue')
    with warnings.catch_warnings(record=True):
        check_if_paths_exist(Path(non_existing_path), Warning, 'Path issue')
    with warnings.catch_warnings(record=True):
        check_if_paths_exist([non_existing_path] + os.listdir('.'), Warning,
                             'Path issue')

    check_result = check_if_paths_exist(non_existing_path,
                                        handle_with=Warning,
                                        message='Path issue',
                                        execution_mode='return')
    assert len(check_result) == 2
    assert type(check_result[0]) == Warning
    assert 'Path issue' in str(check_result[0])
    assert check_result[1] == [non_existing_path]

    check_result = check_if_paths_exist([non_existing_path] + os.listdir('.'),
                                        handle_with=Warning,
                                        message='Path issue',
                                        execution_mode='return')
    assert len(check_result) == 2
    assert type(check_result[0]) == Warning
    assert 'Path issue' in str(check_result[0])
    assert check_result[1] == [non_existing_path]
コード例 #6
0
def test_check_if_paths_exist_negative():
    non_existing_path = "Z:/Op/Oop"
    with pytest.raises(ValueError):
        check_if_paths_exist(non_existing_path, execution_mode="buuu")
    with pytest.raises(FileNotFoundError):
        check_if_paths_exist(non_existing_path)
    with pytest.raises(FileNotFoundError):
        check_if_paths_exist(Path(non_existing_path))
    with pytest.raises(FileNotFoundError):
        check_if_paths_exist([non_existing_path] + os.listdir("."))
    with pytest.raises(IOError):
        check_if_paths_exist(non_existing_path, handle_with=IOError)

    check_result = check_if_paths_exist(non_existing_path,
                                        execution_mode="return")
    assert len(check_result) == 2
    assert type(check_result[0]) == FileNotFoundError
    with pytest.raises(FileNotFoundError):
        raise check_result[0]
    assert check_result[1] == [non_existing_path]

    check_result = check_if_paths_exist(os.listdir(".") + [non_existing_path],
                                        execution_mode="return")
    assert len(check_result) == 2
    assert type(check_result[0]) == FileNotFoundError
    with pytest.raises(FileNotFoundError):
        raise check_result[0]
    assert check_result[1] == [non_existing_path]
コード例 #7
0
def test_check_if_paths_exist_edge_cases():
    with pytest.raises(TypeError, match="required positional argument"):
        check_if_paths_exist()
    with pytest.raises(TypeError, match="unexpected keyword"):
        check_if_paths_exist(path="tomato soup is good")
    with pytest.raises(TypeError, match="Argument paths must be string"):
        check_if_paths_exist(20)
    with pytest.raises(TypeError, match="Argument paths must be string"):
        check_if_paths_exist(True)
    with pytest.raises(TypeError, match="Argument paths must be string"):
        check_if_paths_exist(["/some/path", 1, 2])
    with pytest.raises(TypeError, match="Argument paths must be string"):
        check_if_paths_exist(["/some/path", Path("/some/path"), False])
    with pytest.raises(ValueError):
        check_if_paths_exist(os.listdir(".")[0], execution_mode="buuu")
コード例 #8
0
def test_check_if_paths_exist_edge_cases():
    with pytest.raises(TypeError, match='required positional argument'):
        check_if_paths_exist()
    with pytest.raises(TypeError, match='unexpected keyword'):
        check_if_paths_exist(path='tomato soup is good')
    with pytest.raises(TypeError, match='Argument paths must be string'):
        check_if_paths_exist(20)
    with pytest.raises(TypeError, match='Argument paths must be string'):
        check_if_paths_exist(True)
    with pytest.raises(TypeError, match='Argument paths must be string'):
        check_if_paths_exist(['/some/path', 1, 2])
    with pytest.raises(TypeError, match='Argument paths must be string'):
        check_if_paths_exist(['/some/path', Path('/some/path'), False])
    with pytest.raises(ValueError):
        check_if_paths_exist(os.listdir('.')[0], execution_mode='buuu')