Beispiel #1
0
 def test_unicode_diff2(self):
     unicode_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąźy dōğ.'
     utf8_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąży dōğ.'
     def assert_with_unicode_msg():
         assertions.assert_equal(unicode_string, utf8_string)
     assertions.assert_raises_and_contains(AssertionError, 'łą<ź>y', assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'łą<ż>y', assert_with_unicode_msg)
 def test_validate_regex_failed(self):
     pattern = "((this) regex is broken"
     assert_raises_and_contains(
             errors.ValidationError,
             pattern,
             validation.validate_regex,
             pattern)
Beispiel #3
0
 def test_unicode_diff(self):
     ascii_string = 'abc'
     unicode_string = u'ü and some more'
     def assert_with_unicode_msg():
         assert_equal(unicode_string, ascii_string)
     assertions.assert_raises_and_contains(AssertionError, 'abc', assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'and some more', assert_with_unicode_msg)
Beispiel #4
0
    def test_passes_when_exception_contains_string_with_non_matching_case(
            self):
        def raises_value_error():
            raise ValueError('abc')

        assertions.assert_raises_and_contains(ValueError, 'ABC',
                                              raises_value_error)
Beispiel #5
0
 def test_fails_when_exception_is_not_raised(self):
     raises_nothing = lambda: None
     try:
         assertions.assert_raises_and_contains(ValueError, 'abc', raises_nothing)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
Beispiel #6
0
 def test_callable_is_called_with_all_arguments(self):
     class GoodArguments(Exception): pass
     arg1, arg2, kwarg = object(), object(), object()
     def check_arguments(*args, **kwargs):
         assert_equal((arg1, arg2), args)
         assert_equal({'kwarg': kwarg}, kwargs)
         raise GoodArguments('abc')
     assertions.assert_raises_and_contains(GoodArguments, 'abc', check_arguments, arg1, arg2, kwarg=kwarg)
Beispiel #7
0
 def test_fails_when_exception_is_not_raised(self):
     raises_nothing = lambda: None
     try:
         assertions.assert_raises_and_contains(ValueError, 'abc',
                                               raises_nothing)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
Beispiel #8
0
 def test_fails_when_exception_does_not_contains_all_strings(self):
     def raises_value_error():
         raise ValueError('abc xyz')
     try:
         assertions.assert_raises_and_contains(ValueError, ['ABC', '123'], raises_value_error)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
Beispiel #9
0
 def test_fails_when_wrong_exception_is_raised(self):
     def raises_value_error():
         raise ValueError
     try:
         assertions.assert_raises_and_contains(MyException, 'abc', raises_value_error)
     except ValueError:
         pass
     else:
         assert_not_reached('ValueError should have been raised')
Beispiel #10
0
    def test_fails_when_exception_does_not_contains_all_strings(self):
        def raises_value_error():
            raise ValueError('abc xyz')

        try:
            assertions.assert_raises_and_contains(ValueError, ['ABC', '123'],
                                                  raises_value_error)
        except AssertionError:
            pass
        else:
            assert_not_reached('AssertionError should have been raised')
Beispiel #11
0
    def test_unicode_diff(self):
        ascii_string = 'abc'
        unicode_string = u'ü and some more'

        def assert_with_unicode_msg():
            assert_equal(unicode_string, ascii_string)

        assertions.assert_raises_and_contains(AssertionError, 'abc',
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'and some more',
                                              assert_with_unicode_msg)
Beispiel #12
0
    def test_unicode_diff2(self):
        unicode_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąźy dōğ.'
        utf8_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąży dōğ.'

        def assert_with_unicode_msg():
            assertions.assert_equal(unicode_string, utf8_string)

        assertions.assert_raises_and_contains(AssertionError, 'łą<ź>y',
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'łą<ż>y',
                                              assert_with_unicode_msg)
 def test_get_value_fails_validation(self):
     expected = [self.name, self.config_key]
     validator = mock.Mock(side_effect=validation.ValidationError)
     _ = proxy.ValueProxy(  # flake8: noqa
             validator,
             self.namespace,
             'something.broken')
     assert_raises_and_contains(
             errors.ConfigurationError,
             expected,
             lambda: self.value_proxy.value)
Beispiel #14
0
    def test_fails_when_wrong_exception_is_raised(self):
        def raises_value_error():
            raise ValueError

        try:
            assertions.assert_raises_and_contains(MyException, 'abc',
                                                  raises_value_error)
        except ValueError:
            pass
        else:
            assert_not_reached('ValueError should have been raised')
Beispiel #15
0
 def test_utf8_diff(self):
     utf8_string1 = u'münchen'.encode('utf8')
     utf8_string2 = u'mënchen'.encode('utf8')
     def assert_with_unicode_msg():
         assert_equal(utf8_string1, utf8_string2)
     for content in (
             r"l: 'm\xc3\xbcnchen'",
             r"r: 'm\xc3\xabnchen'",
             "l: m<ü>nchen",
             "r: m<ë>nchen",
     ):
         assertions.assert_raises_and_contains(AssertionError, content, assert_with_unicode_msg)
Beispiel #16
0
    def test_utf8_diff(self):
        utf8_string1 = u'münchen'.encode('utf8')
        utf8_string2 = u'mënchen'.encode('utf8')

        def assert_with_unicode_msg():
            assert_equal(utf8_string1, utf8_string2)

        for content in (
                r"l: 'm\xc3\xbcnchen'",
                r"r: 'm\xc3\xabnchen'",
                "l: m<ü>nchen",
                "r: m<ë>nchen",
        ):
            assertions.assert_raises_and_contains(AssertionError, content,
                                                  assert_with_unicode_msg)
Beispiel #17
0
    def test_bytes_diff(self):
        byte_string1 = b'm\xeenchen'
        byte_string2 = b'm\xaanchen'

        def assert_with_unicode_msg():
            assert_equal(byte_string1, byte_string2)

        for part in ((r"l: 'm\xeenchen'" if six.PY2 else r"l: b'm\xeenchen'"),
                     (r"r: 'm\xaanchen'" if six.PY2 else r"r: b'm\xaanchen'"),
                     'l: m<î>nchen', 'r: m<ª>nchen'):
            assertions.assert_raises_and_contains(
                AssertionError,
                part,
                assert_with_unicode_msg,
            )
Beispiel #18
0
    def test_str_versus_unicode_diff(self):
        """Real-world example from https://github.com/Yelp/Testify/issues/144#issuecomment-14188539
        A good assert_equal implementation will clearly show that these have completely different character contents.
        """
        unicode_string = u'm\xc3\xbcnchen'
        byte_string = 'm\xc3\xbcnchen'

        def assert_with_unicode_msg():
            assert_equal(unicode_string, byte_string)
        for content in (
                r"l: u'm\xc3\xbcnchen'",
                r"r: 'm\xc3\xbcnchen'",
                "l: m<ü>nchen",
                "r: m<ü>nchen",
        ):
            assertions.assert_raises_and_contains(AssertionError, content, assert_with_unicode_msg)
Beispiel #19
0
 def test_unicode_diff3(self):
     unicode_string = u'münchen'
     utf8_string = unicode_string.encode('utf8')
     def assert_with_unicode_msg():
         assert_equal(unicode_string, utf8_string)
     assertions.assert_raises_and_contains(AssertionError, r"l: u'm\xfcnchen'", assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, r"r: 'm\xc3\xbcnchen'", assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'l: münchen', assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'r: münchen', assert_with_unicode_msg)
Beispiel #20
0
 def test_bytes_diff(self):
     byte_string1 = 'm\xeenchen'
     byte_string2 = 'm\xaanchen'
     def assert_with_unicode_msg():
         assert_equal(byte_string1, byte_string2)
     assertions.assert_raises_and_contains(AssertionError, r"l: 'm\xeenchen'", assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, r"r: 'm\xaanchen'", assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'l: m<î>nchen', assert_with_unicode_msg)
     assertions.assert_raises_and_contains(AssertionError, 'r: m<ª>nchen', assert_with_unicode_msg)
Beispiel #21
0
    def test_callable_is_called_with_all_arguments(self):
        class GoodArguments(Exception):
            pass

        arg1, arg2, kwarg = object(), object(), object()

        def check_arguments(*args, **kwargs):
            assert_equal((arg1, arg2), args)
            assert_equal({'kwarg': kwarg}, kwargs)
            raise GoodArguments('abc')

        assertions.assert_raises_and_contains(GoodArguments,
                                              'abc',
                                              check_arguments,
                                              arg1,
                                              arg2,
                                              kwarg=kwarg)
Beispiel #22
0
    def test_str_versus_unicode_diff(self):
        """Real-world example from https://github.com/Yelp/Testify/issues/144#issuecomment-14188539
        A good assert_equal implementation will clearly show that these have completely different character contents.
        """
        unicode_string = u'm\xc3\xbcnchen'
        byte_string = 'm\xc3\xbcnchen'

        def assert_with_unicode_msg():
            assert_equal(unicode_string, byte_string)

        for content in (
                r"l: u'm\xc3\xbcnchen'",
                r"r: 'm\xc3\xbcnchen'",
                "l: m<ü>nchen",
                "r: m<ü>nchen",
        ):
            assertions.assert_raises_and_contains(AssertionError, content,
                                                  assert_with_unicode_msg)
Beispiel #23
0
    def test_unicode_diff3(self):
        unicode_string = u'münchen'
        utf8_string = unicode_string.encode('utf8')

        def assert_with_unicode_msg():
            assert_equal(unicode_string, utf8_string)

        for part in (
            (r"l: u'm\xfcnchen'" if six.PY2 else r"l: 'münchen'"),
            (r"r: 'm\xc3\xbcnchen'" if six.PY2 else r"r: b'm\xc3\xbcnchen'"),
                'l: münchen',
                'r: münchen',
        ):
            assertions.assert_raises_and_contains(
                AssertionError,
                part,
                assert_with_unicode_msg,
            )
Beispiel #24
0
    def test_unicode_diff3(self):
        unicode_string = u'münchen'
        utf8_string = unicode_string.encode('utf8')

        def assert_with_unicode_msg():
            assert_equal(unicode_string, utf8_string)

        for part in (
            (
                r"l: u'm\xfcnchen'" if six.PY2 else
                r"l: 'münchen'"
            ),
            (
                r"r: 'm\xc3\xbcnchen'" if six.PY2 else
                r"r: b'm\xc3\xbcnchen'"
            ),
            'l: münchen',
            'r: münchen',
        ):
            assertions.assert_raises_and_contains(
                AssertionError, part, assert_with_unicode_msg,
            )
Beispiel #25
0
    def test_bytes_diff(self):
        byte_string1 = b'm\xeenchen'
        byte_string2 = b'm\xaanchen'

        def assert_with_unicode_msg():
            assert_equal(byte_string1, byte_string2)

        for part in (
            (
                r"l: 'm\xeenchen'" if six.PY2 else
                r"l: b'm\xeenchen'"
            ),
            (
                r"r: 'm\xaanchen'" if six.PY2 else
                r"r: b'm\xaanchen'"
            ),
            'l: m<î>nchen',
            'r: m<ª>nchen'
        ):
            assertions.assert_raises_and_contains(
                AssertionError, part, assert_with_unicode_msg,
            )
Beispiel #26
0
    def test_unicode_diff3(self):
        unicode_string = u'münchen'
        utf8_string = unicode_string.encode('utf8')

        def assert_with_unicode_msg():
            assert_equal(unicode_string, utf8_string)

        assertions.assert_raises_and_contains(AssertionError,
                                              r"l: u'm\xfcnchen'",
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError,
                                              r"r: 'm\xc3\xbcnchen'",
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'l: münchen',
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'r: münchen',
                                              assert_with_unicode_msg)
Beispiel #27
0
    def test_bytes_diff(self):
        byte_string1 = 'm\xeenchen'
        byte_string2 = 'm\xaanchen'

        def assert_with_unicode_msg():
            assert_equal(byte_string1, byte_string2)

        assertions.assert_raises_and_contains(AssertionError,
                                              r"l: 'm\xeenchen'",
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError,
                                              r"r: 'm\xaanchen'",
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'l: m<î>nchen',
                                              assert_with_unicode_msg)
        assertions.assert_raises_and_contains(AssertionError, 'r: m<ª>nchen',
                                              assert_with_unicode_msg)
 def test_extract_value_unset(self):
     expected = [self.name, self.config_key]
     assert_raises_and_contains(errors.ConfigurationError,
         expected, lambda: self.value_proxy.value)
 def test_build_list_of_type_float_failed(self):
     validator = validation.build_list_type_validator(
         validation.validate_float)
     assert_raises_and_contains(
         errors.ValidationError, 'invalid float: a', validator, ['0.1', 'a'])
 def test_validate_regex_none(self):
     assert_raises_and_contains(errors.ValidationError, 'None',
         validation.validate_regex, None)
 def test_build_list_of_type_not_a_list(self):
     validator = validation.build_list_type_validator(
         validation.validate_any)
     assert_raises_and_contains(
         errors.ValidationError, 'invalid iterable', validator, None)
Beispiel #32
0
 def test__getattr__unknown_method(self):
     method_name = 'missing_method'
     assert_raises_and_contains(AttributeError,
         method_name,
         getattr, self.client, method_name)
Beispiel #33
0
 def test_passes_when_exception_contains_multiple_strings(self):
     def raises_value_error():
         raise ValueError('abc xyz')
     assertions.assert_raises_and_contains(ValueError, ['ABC', 'XYZ'], raises_value_error)
 def test_validate_regex_failed(self):
     pattern = "((this) regex is broken"
     assert_raises_and_contains(errors.ValidationError, pattern,
                                validation.validate_regex, pattern)
 def test_validate_regex_none(self):
     assert_raises_and_contains(errors.ValidationError, 'None',
                                validation.validate_regex, None)
Beispiel #36
0
    def test_passes_when_exception_contains_multiple_strings(self):
        def raises_value_error():
            raise ValueError('abc xyz')

        assertions.assert_raises_and_contains(ValueError, ['ABC', 'XYZ'],
                                              raises_value_error)
 def test_build_list_of_type_float_failed(self):
     validator = validation.build_list_type_validator(
         validation.validate_float)
     assert_raises_and_contains(errors.ValidationError, 'invalid float: a',
                                validator, ['0.1', 'a'])
 def test_invalid_log_level(self):
     assert_raises_and_contains(
             errors.ValidationError,
             'UNKNOWN',
             validation.validate_log_level,
             'UNKNOWN')
Beispiel #39
0
 def test_passes_when_exception_contains_string_with_non_matching_case(self):
     def raises_value_error():
         raise ValueError('abc')
     assertions.assert_raises_and_contains(ValueError, 'ABC', raises_value_error)
 def test_extract_value_unset(self):
     expected = [self.name, self.config_key]
     assert_raises_and_contains(errors.ConfigurationError, expected,
                                lambda: self.value_proxy.value)
 def test_get_value_fails_validation(self):
     expected = [self.name, self.config_key]
     validator = mock.Mock(side_effect=validation.ValidationError)
     _ = proxy.ValueProxy(validator, self.namespace, 'something.broken')
     assert_raises_and_contains(errors.ConfigurationError, expected,
                                lambda: self.value_proxy.value)
 def test_build_list_of_type_not_a_list(self):
     validator = validation.build_list_type_validator(
         validation.validate_any)
     assert_raises_and_contains(errors.ValidationError, 'invalid iterable',
                                validator, None)