예제 #1
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
예제 #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_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
예제 #3
0
def test_check_if_not_negative_warnings():
    with warnings.catch_warnings(record=True) as w:
        check_if_not(2 > 1, Warning, "This is a testing warning")
        assert "This is a testing warning" in str(w[-1].message)

    with warnings.catch_warnings(record=True) as w:
        check_if_not(2 > 1, UserWarning, "This is a testing warning")
        assert issubclass(w[-1].category, Warning)
        assert "This is a testing warning" in str(w[-1].message)
예제 #4
0
def test_check_if_not_negative():
    with pytest.raises(AssertionError):
        check_if_not(2 > 1)
    with pytest.raises(ValueError):
        check_if_not(2 > 1, handle_with=ValueError)
    with pytest.raises(ValueError, match="incorrect value"):
        check_if_not(2 > 1, handle_with=ValueError, message="incorrect value")
예제 #5
0
def test_check_if_not_edge_cases():
    with pytest.raises(TypeError, match="required positional argument"):
        check_if_not()
    with pytest.raises(ValueError, match="The condition does not return"):
        check_if_not("tomato soup is good")
    with pytest.raises(ValueError, match="The condition does not return"):
        check_if_not("")
    with pytest.raises(ValueError, match="The condition does not return"):
        check_if_not(1)
    with pytest.raises(ValueError, match="The condition does not return"):
        check_if_not(0)
    assert check_if_not(False) is None
    with pytest.raises(AssertionError):
        check_if_not(True)
    with pytest.raises(TypeError, match="handle_with must be an exception"):
        check_if_not(1, 1)
    with pytest.raises(TypeError,
                       match="message must be either None or string"):
        check_if_not(1, ValueError, 1)
    with pytest.raises(TypeError, match="takes from 1 to 3 positional"):
        check_if_not(1, 1, 1, 1)
예제 #6
0
def test_check_if_not_positive():
    assert check_if_not(2 < 1) is None
    assert check_if_not(2 < 1, Warning) is None
    assert check_if_not("a" == "A") is None
    assert check_if_not("a" == "A", Warning) is None
예제 #7
0
def test_check_if_not_positive():
    assert check_if_not(2 < 1) is None
    assert check_if_not(2 < 1, Warning) is None
    assert check_if_not('a' == 'A') is None
    assert check_if_not('a' == 'A', Warning) is None