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
def test_check_type_negative_warnings(): with warnings.catch_warnings(record=True) as w: check_type( "souvenir", (tuple, list), handle_with=Warning, message="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_type( True, [str, complex], handle_with=Warning, message="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_type( 20.1, (int, None), handle_with=Warning, message="This is a testing warning", ) assert "This is a testing warning" in str(w[-1].message)
def test_check_type_negative(): with pytest.raises(TypeError, match="Neither tuple nor list"): check_type("souvenir", (tuple, list), message="Neither tuple nor list") with pytest.raises(TypeError): check_type("souvenir", [tuple, list]) with pytest.raises(TypeError): check_type("souvenir", {tuple, list}) with pytest.raises(TypeError): check_type(True, (str, complex)) with pytest.raises(TypeError): check_type(20.1, (int, None)) with pytest.raises(TypeError): check_type((i for i in range(3)), tuple) with pytest.raises(TypeError, match="This is not tuple"): check_type((i for i in range(3)), tuple, message="This is not tuple") with pytest.raises(TypeError): check_type(10, None) with pytest.raises(TypeError): check_type("string", None) with pytest.raises(TypeError): check_type((10, 20), None) with pytest.raises(TypeError): check_type([10, 20], None)
def test_check_type_positive(): assert check_type(["string"], list) is None assert check_type(["string"], list, handle_with=Warning) is None assert check_type("string", str) is None assert check_type("string", str, handle_with=Warning) is None assert check_type((1, 2), tuple) is None assert check_type((1, 2), tuple, handle_with=Warning) is None assert check_type((1, 2), [tuple, list]) is None assert check_type((1, 2), [tuple, list], handle_with=Warning) is None assert check_type((1, 2), [list, tuple]) is None assert check_type((1, 2), {tuple, list}, handle_with=Warning) is None assert (check_type( (1, 2), (tuple, list), message="Neither tuple nor list") is None) assert (check_type( (1, 2), (tuple, list), message="Neither tuple nor list", handle_with=Warning, ) is None) assert check_type((i for i in range(3)), Generator) is None assert (check_type( (i for i in range(3)), Generator, handle_with=Warning) is None) assert check_type(None, (int, None)) is None assert check_type(None, (int, None), handle_with=Warning) is None assert check_type(20, (int, None)) is None assert check_type(20, (int, None), handle_with=Warning) is None assert check_type(None, None) is None assert check_type(None, None, handle_with=Warning) is None
def test_check_type_edge_cases(): with pytest.raises(TypeError, match="required positional argument"): check_type("tomato soup is good")