def test_check_dict_like_no_values_callable():
    try:
        ab = assert_that(None)
        ab._check_dict_like(CustomDictNoValuesCallable())
        fail('should have raised error')
    except TypeError as e:
        assert_that(str(e)).contains('is not dict-like: missing values()')
Exemplo n.º 2
0
 def test_is_type_of_subclass_failure(self):
     try:
         assert_that(Bar()).is_type_of(Foo)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).starts_with('Expected <')
         assert_that(str(ex)).ends_with(':Bar> to be of type <Foo>, but was not.')
Exemplo n.º 3
0
 def test_is_after_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_after(d2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be after <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
def test_check_dict_like_no_getitem():
    try:
        ab = assert_that(None)
        ab._check_dict_like(CustomDictNoGetitem())
        fail('should have raised error')
    except TypeError as e:
        assert_that(str(e)).contains('is not dict-like: missing [] accessor')
Exemplo n.º 5
0
 def test_is_equal_to_ignoring_milliseconds_failure(self):
     try:
         d2 = datetime.datetime.today() + datetime.timedelta(days=1)
         assert_that(self.d1).is_equal_to_ignoring_milliseconds(d2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be equal to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
Exemplo n.º 6
0
 def test_is_close_to_failure(self):
     try:
         d2 = self.d1 + datetime.timedelta(minutes=5)
         assert_that(self.d1).is_close_to(d2, datetime.timedelta(minutes=1))
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be close to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> within tolerance <\d+:\d{2}:\d{2}>, but was not.')
Exemplo n.º 7
0
 def test_is_close_to_bad_tolerance_arg_type_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_close_to(d2, 123)
         fail('should have raised error')
     except TypeError as ex:
         assert_that(str(ex)).is_equal_to('given tolerance arg must be timedelta, but was <int>')
Exemplo n.º 8
0
 def test_is_less_than_or_equal_to_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(d2).is_less_than_or_equal_to(self.d1)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be less than or equal to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
def test_is_before_failure():
    try:
        d2 = datetime.datetime.today()
        assert_that(d2).is_before(d1)
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be before <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
def test_traceback():
    try:
        assert_that('foo').is_equal_to('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to be equal to <bar>, but was not.')
        assert_that(ex).is_type_of(AssertionError)

        # extract all stack frames from the traceback
        _, _, tb = sys.exc_info()
        assert_that(tb).is_not_none()

        # walk_tb added in 3.5
        if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
            frames = [(f.f_code.co_filename, f.f_code.co_name, lineno) for f,lineno in traceback.walk_tb(tb)]

            assert_that(frames).is_length(3)
            
            assert_that(frames[0][0]).ends_with('test_traceback.py')
            assert_that(frames[0][1]).is_equal_to('test_traceback')
            assert_that(frames[0][2]).is_equal_to(35)

            assert_that(frames[1][0]).ends_with('assertpy.py')
            assert_that(frames[1][1]).is_equal_to('is_equal_to')
            assert_that(frames[1][2]).is_greater_than(160)

            assert_that(frames[2][0]).ends_with('assertpy.py')
            assert_that(frames[2][1]).is_equal_to('_err')
            assert_that(frames[2][2]).is_greater_than(1000)
Exemplo n.º 11
0
def step_impl( context, ammount ) :
    for i in range( 0, ammount ):
        id = 'sim-sampler-' + str( i )
        try:
            context.driver.find_element_by_id( id )
        except: 
            fail( 'live plot ' + id + ' is not found' )
def test_check_iterable_no_getitem():
    try:
        ab = assert_that(None)
        ab._check_iterable(set([1]), name='my-set')
        fail('should have raised error')
    except TypeError as e:
        assert_that(str(e)).contains('my-set <set> does not have [] accessor')
def test_check_iterable_not_iterable():
    try:
        ab = assert_that(None)
        ab._check_iterable(123, name='my-int')
        fail('should have raised error')
    except TypeError as e:
        assert_that(str(e)).contains('my-int <int> is not iterable')
Exemplo n.º 14
0
 def test_is_less_than_or_equal_to_failure(self):
     try:
         t2 = datetime.timedelta(seconds=90)
         assert_that(t2).is_less_than_or_equal_to(self.t1)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be less than or equal to <\d{1,2}:\d{2}:\d{2}>, but was not.')
Exemplo n.º 15
0
 def test_is_greater_than_failure(self):
     try:
         t2 = datetime.timedelta(seconds=90)
         assert_that(self.t1).is_greater_than(t2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be greater than <\d{1,2}:\d{2}:\d{2}>, but was not.')
def test_expected_exception_one_arg_failure():
    try:
        assert_that(func_noop).raises(RuntimeError).when_called_with('foo')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to(
            "Expected <func_noop> to raise <RuntimeError> when called with ('foo').")
def test_expected_exception_all_failure():
    try:
        assert_that(func_noop).raises(RuntimeError).when_called_with('a', 'b', 3, 4, foo=1, bar=2, baz='dog')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to(
            "Expected <func_noop> to raise <RuntimeError> when called with ('a', 'b', 3, 4, 'bar': 2, 'baz': 'dog', 'foo': 1).")
Exemplo n.º 18
0
 def test_extracting_dict_missing_key_failure(self):
     people_as_dicts = [{'first_name': p.first_name, 'last_name': p.last_name} for p in self.people]
     try:
         assert_that(people_as_dicts).extracting('foo')
         fail('should have raised error')
     except ValueError as ex:
         assert_that(str(ex)).matches(r'item keys \[.*\] did not contain key <foo>')
Exemplo n.º 19
0
def test_is_not_same_as_failure():
    for obj in [object(), 1, 'foo', True, None, 123.456]:
        try:
            assert_that(obj).is_not_same_as(obj)
            fail('should have raised error')
        except AssertionError as ex:
            assert_that(str(ex)).matches('Expected <.+> to be not identical to <.+>, but was.')
Exemplo n.º 20
0
 def test_is_file_directory_failure(self):
     try:
         dirname = os.path.dirname(self.tmp.name)
         assert_that(dirname).is_file()
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <.*> to be a file, but was not.')
Exemplo n.º 21
0
 def test_soft_assertions(self):
     try:
         with soft_assertions():
             assert_that('foo').is_length(4)
             assert_that('foo').is_empty()
             assert_that('foo').is_false()
             assert_that('foo').is_digit()
             assert_that('123').is_alpha()
             assert_that('foo').is_upper()
             assert_that('FOO').is_lower()
             assert_that('foo').is_equal_to('bar')
             assert_that('foo').is_not_equal_to('foo')
             assert_that('foo').is_equal_to_ignoring_case('BAR')
         fail('should have raised error')
     except AssertionError as e:
         assert_that(str(e)).contains('1. Expected <foo> to be of length <4>, but was <3>.')
         assert_that(str(e)).contains('2. Expected <foo> to be empty string, but was not.')
         assert_that(str(e)).contains('3. Expected <False>, but was not.')
         assert_that(str(e)).contains('4. Expected <foo> to contain only digits, but did not.')
         assert_that(str(e)).contains('5. Expected <123> to contain only alphabetic chars, but did not.')
         assert_that(str(e)).contains('6. Expected <foo> to contain only uppercase chars, but did not.')
         assert_that(str(e)).contains('7. Expected <FOO> to contain only lowercase chars, but did not.')
         assert_that(str(e)).contains('8. Expected <foo> to be equal to <bar>, but was not.')
         assert_that(str(e)).contains('9. Expected <foo> to be not equal to <foo>, but was.')
         assert_that(str(e)).contains('10. Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
Exemplo n.º 22
0
def test_failure():
    try:
        with soft_assertions():
            assert_that('foo').is_length(4)
            assert_that('foo').is_empty()
            assert_that('foo').is_false()
            assert_that('foo').is_digit()
            assert_that('123').is_alpha()
            assert_that('foo').is_upper()
            assert_that('FOO').is_lower()
            assert_that('foo').is_equal_to('bar')
            assert_that('foo').is_not_equal_to('foo')
            assert_that('foo').is_equal_to_ignoring_case('BAR')
            assert_that({'a': 1}).has_a(2)
            assert_that({'a': 1}).has_foo(1)
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Expected <foo> to be of length <4>, but was <3>.')
        assert_that(out).contains('Expected <foo> to be empty string, but was not.')
        assert_that(out).contains('Expected <False>, but was not.')
        assert_that(out).contains('Expected <foo> to contain only digits, but did not.')
        assert_that(out).contains('Expected <123> to contain only alphabetic chars, but did not.')
        assert_that(out).contains('Expected <foo> to contain only uppercase chars, but did not.')
        assert_that(out).contains('Expected <FOO> to contain only lowercase chars, but did not.')
        assert_that(out).contains('Expected <foo> to be equal to <bar>, but was not.')
        assert_that(out).contains('Expected <foo> to be not equal to <foo>, but was.')
        assert_that(out).contains('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
        assert_that(out).contains('Expected <1> to be equal to <2> on key <a>, but was not.')
        assert_that(out).contains('Expected key <foo>, but val has no key <foo>.')
Exemplo n.º 23
0
 def test_is_between_bad_arg2_type_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_between(d2, 123)
         fail('should have raised error')
     except TypeError as ex:
         assert_that(str(ex)).is_equal_to('given high arg must be datetime, but was <int>')
Exemplo n.º 24
0
    def test_strings(self):
        assert_that('').is_not_none()
        assert_that('').is_empty()
        assert_that('').is_false()
        assert_that('').is_type_of(str)
        assert_that('').is_instance_of(str)

        assert_that('foo').is_length(3)
        assert_that('foo').is_not_empty()
        assert_that('foo').is_true()
        assert_that('foo').is_alpha()
        assert_that('123').is_digit()
        assert_that('foo').is_lower()
        assert_that('FOO').is_upper()
        assert_that('foo').is_iterable()
        assert_that('foo').is_equal_to('foo')
        assert_that('foo').is_not_equal_to('bar')
        assert_that('foo').is_equal_to_ignoring_case('FOO')

        if sys.version_info[0] == 3:
            assert_that('foo').is_unicode()
        else:
            assert_that(u'foo').is_unicode()

        assert_that('foo').contains('f')
        assert_that('foo').contains('f','oo')
        assert_that('foo').contains_ignoring_case('F','oO')
        assert_that('foo').does_not_contain('x')
        assert_that('foo').contains_only('f','o')
        assert_that('foo').contains_sequence('o','o')

        assert_that('foo').contains_duplicates()
        assert_that('fox').does_not_contain_duplicates()

        assert_that('foo').is_in('foo','bar','baz')
        assert_that('foo').is_not_in('boo','bar','baz')
        assert_that('foo').is_subset_of('abcdefghijklmnopqrstuvwxyz')

        assert_that('foo').starts_with('f')
        assert_that('foo').ends_with('oo')

        assert_that('foo').matches(r'\w')
        assert_that('123-456-7890').matches(r'\d{3}-\d{3}-\d{4}')
        assert_that('foo').does_not_match(r'\d+')

        # partial matches, these all pass
        assert_that('foo').matches(r'\w')
        assert_that('foo').matches(r'oo')
        assert_that('foo').matches(r'\w{2}')

        # match the entire string with an anchored regex pattern, passes
        assert_that('foo').matches(r'^\w{3}$')

        # fails
        try:
            assert_that('foo').matches(r'^\w{2}$')
            fail('should have raised error')
        except AssertionError:
            pass
Exemplo n.º 25
0
def test_fail_with_msg():
    try:
        with soft_assertions():
            fail('foobar')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).is_equal_to('Fail: foobar!')
Exemplo n.º 26
0
def test_contains_single_item_dict_like_failure():
    if sys.version_info[0] == 3:
        ordered = collections.OrderedDict([('z',9),('x',7),('y',8)])
        try:
            assert_that(ordered).contains('a')
            fail('should have raised error')
        except AssertionError as ex:
            assert_that(str(ex)).ends_with('to contain key <a>, but did not.')
Exemplo n.º 27
0
def test_is_same_as_failure():
    try:
        obj = object()
        other = object()
        assert_that(obj).is_same_as(other)
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).matches('Expected <.+> to be identical to <.+>, but was not.')
Exemplo n.º 28
0
 def test_described_as_with_extract(self):
     try:
         assert_that(self.people).described_as("extra msg").extract("first_name").contains("Fred", "Bob")
         fail("should have raised error")
     except AssertionError as ex:
         assert_that(str(ex)).is_equal_to(
             "[extra msg] Expected <['Fred', 'John']> to contain items ('Fred', 'Bob'), but did not contain <Bob>."
         )
def test_extracting_sort_custom_func_failure():
    def _f(x):
        raise RuntimeError('foobar!')
    try:
        assert_that(users).extracting('user', sort=_f)
        fail('should have raised error')
    except RuntimeError as ex:
        assert_that(str(ex)).is_equal_to("foobar!")
def test_soft_fail_with_msg_without_context():
    try:
        soft_fail('some msg')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).is_equal_to('Fail: some msg!')
        assert_that(out).does_not_contain('should have raised error')
Exemplo n.º 31
0
def test_is_upper_empty_value_failure():
    try:
        assert_that('').is_upper()
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('val is empty')
Exemplo n.º 32
0
def test_does_not_match_bad_arg_empty_failure():
    try:
        assert_that('fred').does_not_match('')
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('given pattern arg must not be empty')
Exemplo n.º 33
0
def test_is_length_failure():
    try:
        assert_that('foo').is_length(4)
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to be of length <4>, but was <3>.')
Exemplo n.º 34
0
def test_contains_ignoring_case_type_failure():
    try:
        assert_that(123).contains_ignoring_case('f')
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not a string or iterable')
Exemplo n.º 35
0
def test_ends_with_bad_arg_type_failure():
    try:
        assert_that('fred').ends_with(123)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given suffix arg must be a string')
Exemplo n.º 36
0
def test_does_not_match_bad_arg_type_failure():
    try:
        assert_that('fred').does_not_match(123)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given pattern arg must be a string')
Exemplo n.º 37
0
def test_is_unicode_failure():
    try:
        assert_that(123).is_unicode()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <123> to be unicode, but was <int>.')
Exemplo n.º 38
0
def test_ends_with_bad_value_type_failure():
    try:
        assert_that(123).ends_with(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not a string or iterable')
Exemplo n.º 39
0
def test_contains_single_item_failure():
    try:
        assert_that('foo').contains('x')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to contain item <x>, but did not.')
Exemplo n.º 40
0
def test_does_not_contain_key_bad_val_failure():
    try:
        assert_that(123).does_not_contain_key(1)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).contains('is not dict-like')
Exemplo n.º 41
0
def test_contains_ignoring_case_single_item_failure():
    try:
        assert_that('foo').contains_ignoring_case('X')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to case-insensitive contain item <X>, but did not.')
Exemplo n.º 42
0
def test_contains_ignoring_case_missinge_item_failure():
    try:
        assert_that('foo').contains_ignoring_case()
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('one or more args must be given')
Exemplo n.º 43
0
def test_is_upper_bad_value_type_failure():
    try:
        assert_that(123).is_upper()
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not a string')
Exemplo n.º 44
0
def test_is_upper_failure():
    try:
        assert_that('foo').is_upper()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to contain only uppercase chars, but did not.')
Exemplo n.º 45
0
def test_does_not_match_failure():
    try:
        assert_that('fred').does_not_match(r'\w+')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <fred> to not match pattern <\\w+>, but did.')
Exemplo n.º 46
0
def test_is_digit_punctuation_failure():
    try:
        assert_that('-123').is_digit()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <-123> to contain only digits, but did not.')
Exemplo n.º 47
0
def test_matches_failure():
    try:
        assert_that('fred').matches(r'\d+')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <fred> to match pattern <\\d+>, but did not.')
Exemplo n.º 48
0
def test_is_digit_space_failure():
    try:
        assert_that('1 000 000').is_digit()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <1 000 000> to contain only digits, but did not.')
Exemplo n.º 49
0
def test_ends_with_bad_arg_empty_failure():
    try:
        assert_that('fred').ends_with('')
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('given suffix arg must not be empty')
Exemplo n.º 50
0
def test_is_alpha_punctuation_failure():
    try:
        assert_that('foo,bar').is_alpha()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo,bar> to contain only alphabetic chars, but did not.')
Exemplo n.º 51
0
def test_starts_with_bad_arg_none_failure():
    try:
        assert_that('fred').starts_with(None)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given prefix arg must not be none')
Exemplo n.º 52
0
def test_contains_multi_item_single_failure():
    try:
        assert_that('foo').contains('f','o', 'x')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to("Expected <foo> to contain items <'f', 'o', 'x'>, but did not contain <x>.")
Exemplo n.º 53
0
def test_is_equal_ignoring_case_failure():
    try:
        assert_that('foo').is_equal_to_ignoring_case('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to be case-insensitive equal to <bar>, but was not.')
Exemplo n.º 54
0
def test_ends_with_failure():
    try:
        assert_that('fred').ends_with('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <fred> to end with <bar>, but did not.')
Exemplo n.º 55
0
def test_does_not_contain_list_multi_item_failure():
    try:
        assert_that('foo').does_not_contain('x','f','o')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to("Expected <foo> to not contain items <'x', 'f', 'o'>, but did contain <'f', 'o'>.")
Exemplo n.º 56
0
def test_is_equal_ignoring_case_bad_arg_type_failure():
    try:
        assert_that('fred').is_equal_to_ignoring_case(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given arg must be a string')
Exemplo n.º 57
0
def test_contains_ignoring_case_list_multi_item_type_failure():
    try:
        assert_that(['foo','bar']).contains_ignoring_case('F', 12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given args must all be strings')
Exemplo n.º 58
0
def test_is_not_empty_failure():
    try:
        assert_that('').is_not_empty()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected not empty string, but was empty.')
Exemplo n.º 59
0
def test_contains_ignoring_case_list_multi_item_failure():
    try:
        assert_that(['foo','bar']).contains_ignoring_case('Foo','X','Y')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to("Expected <['foo', 'bar']> to case-insensitive contain items <'Foo', 'X', 'Y'>, but did not contain <'X', 'Y'>.")
Exemplo n.º 60
0
def test_does_not_contain_single_item_failure():
    try:
        assert_that('foo').does_not_contain('f')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to not contain item <f>, but did.')