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_length_negative_warnings(): with warnings.catch_warnings(record=True) as w: check_length([1, 2], expected_length=1, handle_with=Warning, message='This is a testing warning') assert 'This is a testing warning' in str(w[-1].message)
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
def test_check_length_positive(): assert check_length(["string"], 1) is None assert check_length(["string"], 1, handle_with=Warning) is None assert check_length("string", 6) is None assert check_length("string", 6, handle_with=Warning) is None assert check_length([1, 2], 2) is None assert check_length([1, 2], 2, handle_with=Warning) is None assert check_length(range(0, 3), 3) is None assert check_length(range(0, 3), 3, handle_with=Warning) is None assert check_length(10, 1, assign_length_to_others=True) is None assert (check_length( 10, 1, assign_length_to_others=True, handle_with=Warning) is None)
def test_check_length_negative(): with pytest.raises(TypeError): check_length(len(i for i in range(3)), 3) with pytest.raises(TypeError): check_length(None) with pytest.raises(TypeError, match="object of type 'int' has"): check_length(10, 1)
def test_check_length_edge_cases(): with pytest.raises(TypeError, match="required positional argument"): check_length("tomato soup is good") with pytest.raises(OperatorError, match="Incorrect operator"): check_length(1, 1, operator=1)