Ejemplo n.º 1
0
    def test_text__with_assert_failed_and_unicode_message(self, message):
        with pytest.raises(AssertionError) as e:
            assert False, message

        # -- FOR: pytest < 5.0
        # expected = u"AssertionError: %s" % message
        text2 = text(e.value)
        assert u"AssertionError" in text(e)
        assert message in text2, "OOPS: text=%r" % text2
Ejemplo n.º 2
0
    def store_exception_context(self, exception):
        self.step.exception = exception
        self.step.exe_traceback = sys.exc_info()[2]

        self._insert_png_screenshot_to_allure_report(
            text(exception)
        )
Ejemplo n.º 3
0
    def test_text__with_assert_failed_and_unicode_message(self, message):
        with pytest.raises(AssertionError) as e:
            assert False, message

        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 4
0
    def test_text__with_bytes_value_and_encoding(self, text_value, encoding):
        bytes_value = text_value.encode(encoding)
        assert isinstance(bytes_value, bytes)

        actual = text(bytes_value, encoding)
        assert isinstance(actual, six.text_type)
        assert actual == text_value
Ejemplo n.º 5
0
    def test_text__with_assert_failed_and_unicode_message(self, message):
        with pytest.raises(AssertionError) as e:
            assert False, message

        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 6
0
 def test_issue__with_default_encoding(self):
     """Test ensures that problem is fixed with default encoding"""
     text2 = text(self.traceback_bytes)
     assert isinstance(self.traceback_bytes, bytes)
     assert isinstance(text2, six.text_type)
     for file_line_text in self.traceback_file_line_texts:
         assert file_line_text in text2
Ejemplo n.º 7
0
    def test_text__with_bytes_value_and_encoding(self, text_value, encoding):
        bytes_value = text_value.encode(encoding)
        assert isinstance(bytes_value, bytes)

        actual = text(bytes_value, encoding)
        assert isinstance(actual, six.text_type)
        assert actual == text_value
Ejemplo n.º 8
0
    def test_text__with_raised_exception_and_unicode_message(
            self, exception_class, message):
        with pytest.raises(exception_class) as e:
            raise exception_class(message)

        text2 = text(e)
        expected = u"%s: %s" % (exception_class.__name__, message)
        assert isinstance(text2, six.text_type)
        assert text2.endswith(expected)
Ejemplo n.º 9
0
    def test_text__with_assert_failed_and_bytes_message(self, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        with pytest.raises(AssertionError) as e:
            assert False, bytes_message

        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 10
0
    def test_text__with_assert_failed_and_bytes_message(self, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        with pytest.raises(AssertionError) as e:
            assert False, bytes_message

        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 11
0
    def test_text__with_raised_exception_and_unicode_message(self,
                                                             exception_class,
                                                             message):
        with pytest.raises(exception_class) as e:
            raise exception_class(message)

        text2 = text(e)
        expected = u"%s: %s" % (exception_class.__name__, message)
        assert isinstance(text2, six.text_type)
        assert text2.endswith(expected)
Ejemplo n.º 12
0
def test_issue(encoding):
    expected = u"Всё очень плохо"
    try:
        foo()
    except Exception as e:
        text2 = traceback.format_exc()

    text3 = text(text2, encoding)
    print(u"EXCEPTION-TEXT: %s" % text3)
    print(u"text2: "+ text2)
    assert_that(text3, contains_string(u"AssertionError: Всё очень плохо"))
Ejemplo n.º 13
0
def test_issue(encoding):
    expected = u"Всё очень плохо"
    try:
        foo()
    except Exception as e:
        text2 = traceback.format_exc()

    text3 = text(text2, encoding)
    print(u"EXCEPTION-TEXT: %s" % text3)
    print(u"text2: " + text2)
    assert_that(text3, contains_string(u"AssertionError: Всё очень плохо"))
Ejemplo n.º 14
0
    def test__problem_exists_with_problematic_encoding(self):
        """Test ensures that problem exists with encoding=unicode-escape"""
        # -- NOTE: Explicit use of problematic encoding
        problematic_encoding = "unicode-escape"
        text2 = text(self.traceback_bytes, problematic_encoding)
        print("TEXT: " + text2)
        assert isinstance(self.traceback_bytes, bytes)
        assert isinstance(text2, six.text_type)

        # -- VERIFY BAD-OUTCOME: With problematic encoding
        file_line_text = self.traceback_file_line_texts[0]
        assert file_line_text not in text2
Ejemplo n.º 15
0
    def test_text__with_raised_exception_and_unicode_message(
            self, exception_class, message):
        with pytest.raises(exception_class) as e:
            raise exception_class(message)

        # -- FOR: pytest < 5.0
        # expected = u"AssertionError: %s" % message
        text2 = text(e.value)
        expected = u"%s: %s" % (exception_class.__name__, message)
        assert isinstance(text2, six.text_type)
        assert exception_class.__name__ in str(e)
        assert message in text2, "OOPS: text=%r" % text2
Ejemplo n.º 16
0
    def test_text__with_raised_exception_and_bytes_message(
            self, exception_class, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        with pytest.raises(exception_class) as e:
            raise exception_class(bytes_message)

        text2 = text(e)
        unicode_message = bytes_message.decode(self.ENCODING)
        expected = u"%s: %s" % (exception_class.__name__, unicode_message)
        assert isinstance(text2, six.text_type)
        assert text2.endswith(expected)
        # -- DIAGNOSTICS:
        print(u"text2: " + text2)
        print(u"expected: " + expected)
Ejemplo n.º 17
0
    def test_text__with_raised_exception_and_bytes_message(self, exception_class,
                                                           message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        with pytest.raises(exception_class) as e:
            raise exception_class(bytes_message)

        text2 = text(e)
        unicode_message = bytes_message.decode(self.ENCODING)
        expected = u"%s: %s" % (exception_class.__name__, unicode_message)
        assert isinstance(text2, six.text_type)
        assert text2.endswith(expected)
        # -- DIAGNOSTICS:
        print(u"text2: "+ text2)
        print(u"expected: " + expected)
Ejemplo n.º 18
0
    def test_text__with_object_convertable_to_py2string_only(self, text_value):
        class ConvertableToPy2String(object):
            """Lacks feature: convertable-to-unicode (only: to-string)"""
            def __init__(self, message=""):
                self.message = message or ""
                if self.message and isinstance(self.message, six.text_type):
                    self.message = self.message.encode("UTF-8")

            def __str__(self):
                # assert isinstance(self.message, str)
                return self.message

        obj = ConvertableToPy2String(text_value.encode("UTF-8"))
        actual = text(obj)
        print(u"actual: %s" % actual)
        print(u"text_value: %s" % text_value)
        assert actual == text_value
Ejemplo n.º 19
0
    def test_text__with_object_convertable_to_py2string_only(self, text_value):
        class ConvertableToPy2String(object):
            """Lacks feature: convertable-to-unicode (only: to-string)"""
            def __init__(self, message=""):
                self.message = message or ""
                if self.message and isinstance(self.message, six.text_type):
                    self.message = self.message.encode("UTF-8")

            def __str__(self):
                # assert isinstance(self.message, str)
                return self.message

        obj = ConvertableToPy2String(text_value.encode("UTF-8"))
        actual = text(obj)
        print(u"actual: %s" % actual)
        print(u"text_value: %s" % text_value)
        assert actual == text_value
Ejemplo n.º 20
0
    def test_text__with_assert_failed_and_bytes_message(self, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        decode_error_occured = False
        with pytest.raises(AssertionError) as e:
            try:
                assert False, bytes_message
            except UnicodeDecodeError as uni_error:
                # -- SINCE: Python 2.7.15
                decode_error_occured = True
                expected_decode_error = "'ascii' codec can't decode byte 0xc3 in position 0"
                assert expected_decode_error in str(uni_error)
                assert False, bytes_message.decode(self.ENCODING)

        print("decode_error_occured(ascii)=%s" % decode_error_occured)
        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 21
0
    def test_text__with_assert_failed_and_bytes_message(self, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        decode_error_occured = False
        with pytest.raises(AssertionError) as e:
            try:
                assert False, bytes_message
            except UnicodeDecodeError as uni_error:
                # -- SINCE: Python 2.7.15
                decode_error_occured = True
                expected_decode_error = "'ascii' codec can't decode byte 0xc3 in position 0"
                assert expected_decode_error in str(uni_error)
                assert False, bytes_message.decode(self.ENCODING)

        print("decode_error_occured(ascii)=%s" % decode_error_occured)
        text2 = text(e)
        expected = u"AssertionError: %s" % message
        assert text2.endswith(expected)
Ejemplo n.º 22
0
    def test_text__with_raised_exception_and_bytes_message(
            self, exception_class, message):
        # -- ONLY PYTHON2: Use case makes no sense for Python 3.
        bytes_message = message.encode(self.ENCODING)
        with pytest.raises(exception_class) as e:
            raise exception_class(bytes_message)

        # -- REQUIRES: pytest < 5.0
        # HINT: pytest >= 5.0 needs: text(e.value)
        # NEW:  text2 = text(e.value)   # Causes problems w/ decoding and comparison.
        assert isinstance(e.value, Exception)
        text2 = text(e)
        unicode_message = bytes_message.decode(self.ENCODING)
        expected = u"%s: %s" % (exception_class.__name__, unicode_message)
        assert isinstance(text2, six.text_type)
        assert unicode_message in text2
        assert text2.endswith(expected)
        # -- DIAGNOSTICS:
        print(u"text2: " + text2)
        print(u"expected: " + expected)
Ejemplo n.º 23
0
def test_issue(encoding):
    """
    with encoding=UTF-8:
        File "/Users/jens/se/behave_main.unicode/tests/issues/test_issue0453.py", line 31, in problematic_step_impl
            raise Exception(u"по русски")
        Exception: \u043f\u043e \u0440\u0443\u0441\u0441\u043a\u0438

    with encoding=unicode_escape:
        File "/Users/jens/se/behave_main.unicode/tests/issues/test_issue0453.py", line 31, in problematic_step_impl
            raise Exception(u"по русски")
        Exception: по русски
    """
    context = None
    text2 = ""
    expected_text = u"по русски"
    try:
        problematic_step_impl(context)
    except Exception:
        text2 =  traceback.format_exc()

    text3 = text(text2, encoding)
    print(u"EXCEPTION-TEXT: %s" % text3)
    assert_that(text3, contains_string(u'raise Exception(u"по русски"'))
    assert_that(text3, contains_string(u"Exception: по русски"))
Ejemplo n.º 24
0
def test_issue(encoding):
    """
    with encoding=UTF-8:
        File "/Users/jens/se/behave_main.unicode/tests/issues/test_issue0453.py", line 31, in problematic_step_impl
            raise Exception(u"по русски")
        Exception: \u043f\u043e \u0440\u0443\u0441\u0441\u043a\u0438

    with encoding=unicode_escape:
        File "/Users/jens/se/behave_main.unicode/tests/issues/test_issue0453.py", line 31, in problematic_step_impl
            raise Exception(u"по русски")
        Exception: по русски
    """
    context = None
    text2 = ""
    expected_text = u"по русски"
    try:
        problematic_step_impl(context)
    except Exception:
        text2 = traceback.format_exc()

    text3 = text(text2, encoding)
    print(u"EXCEPTION-TEXT: %s" % text3)
    assert_that(text3, contains_string(u'raise Exception(u"по русски"'))
    assert_that(text3, contains_string(u"Exception: по русски"))
Ejemplo n.º 25
0
 def test_text__with_bytes_value(self, bytes_value, expected_text):
     actual_text = text(bytes_value)
     assert actual_text == expected_text
Ejemplo n.º 26
0
 def test_text__with_object_convertable_to_string(self, text_value):
     obj = ConvertableToString(text_value)
     actual_text = text(obj)
     assert actual_text == text_value
     assert isinstance(actual_text, six.text_type)
Ejemplo n.º 27
0
def make_row(*data, **kwargs):
    line = kwargs.pop("line", None)
    data2 = dict(data, **kwargs)
    headings = list(data2.keys())
    cells = [text(value) for value in data2.values()]
    return Row(headings, cells, line=line)
Ejemplo n.º 28
0
 def test_make_step_for_row__without_placeholders_remains_unchanged(self):
     step_text = u'Given a step without placeholders'
     expected_text = text(step_text)
     params = dict(firstname="Alice", lastname="Beauville")
     self.assert_make_step_for_row(step_text, expected_text, params)
Ejemplo n.º 29
0
 def test_text__with_bytes_value(self, bytes_value, expected_text):
     actual_text = text(bytes_value)
     assert actual_text == expected_text
Ejemplo n.º 30
0
 def test_text__with_unicode_value(self, value):
     value_id = id(value)
     actual_text = text(value)
     assert actual_text == value
     assert id(actual_text) == value_id  # PARANOID check w/ unicode copy.
Ejemplo n.º 31
0
 def test_text__with_unicode_value(self, value):
     value_id = id(value)
     actual_text = text(value)
     assert actual_text == value
     assert id(actual_text) == value_id  # PARANOID check w/ unicode copy.
Ejemplo n.º 32
0
 def test_text__with_object_convertable_to_string(self, text_value):
     obj = ConvertableToString(text_value)
     actual_text = text(obj)
     assert actual_text == text_value
     assert isinstance(actual_text, six.text_type)