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_instance_negative_warnings(): with warnings.catch_warnings(record=True) as w: check_instance('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_instance(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_instance(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_instance_negative(): with pytest.raises(TypeError, match='Neither tuple nor list'): check_instance('souvenir', (tuple, list), message='Neither tuple nor list') with pytest.raises(TypeError): check_instance('souvenir', [tuple, list]) with pytest.raises(TypeError): check_instance('souvenir', {tuple, list}) with pytest.raises(TypeError): check_instance(True, (str, complex)) with pytest.raises(TypeError): check_instance(20.1, (int, None)) with pytest.raises(TypeError): check_instance((i for i in range(3)), tuple) with pytest.raises(TypeError, match='This is not tuple'): check_instance((i for i in range(3)), tuple, message='This is not tuple') with pytest.raises(TypeError): check_instance(10, None) with pytest.raises(TypeError): check_instance('string', None) with pytest.raises(TypeError): check_instance((10, 20), None) with pytest.raises(TypeError): check_instance([10, 20], None)
def test_check_instance_positive(): assert check_instance(['string'], list) is None assert check_instance(['string'], list, handle_with=Warning) is None assert check_instance('string', str) is None assert check_instance('string', str, handle_with=Warning) is None assert check_instance((1, 2), tuple) is None assert check_instance((1, 2), tuple, handle_with=Warning) is None assert check_instance((1, 2), [tuple, list]) is None assert check_instance((1, 2), [tuple, list], handle_with=Warning) is None assert check_instance((1, 2), [list, tuple]) is None assert check_instance((1, 2), {tuple, list}, handle_with=Warning) is None assert check_instance( (1, 2), (tuple, list), message='Neither tuple nor list') is None assert check_instance((1, 2), (tuple, list), message='Neither tuple nor list', handle_with=Warning) is None assert check_instance((i for i in range(3)), Generator) is None assert check_instance( (i for i in range(3)), Generator, handle_with=Warning) is None assert check_instance(None, (int, None)) is None assert check_instance(None, (int, None), handle_with=Warning) is None assert check_instance(20, (int, None)) is None assert check_instance(20, (int, None), handle_with=Warning) is None assert check_instance(None, None) is None assert check_instance(None, None, handle_with=Warning) is None
def test_check_instance_edge_cases(): with pytest.raises(TypeError, match='required positional argument'): check_instance('tomato soup is good')