# Path: coolamqp/exceptions.py
# class AMQPError(CoolAMQPError):
#     """
#     Base class for errors received from AMQP server
#     """
# 
#     def is_hard_error(self):  # type: () -> bool
#         """Does this error close the connection?"""
#         return self.reply_code in HARD_ERRORS
# 
#     def __str__(self):  # type: () -> str
#         return 'AMQP error %s: %s' % (self.reply_code, self.__get_reply_text())
# 
#     def __get_reply_text(self):  # type: () -> str
#         if isinstance(self.reply_text, memoryview):
#             reply_text = self.reply_text.tobytes().decode('utf8')
#         else:
#             reply_text = self.reply_text
# 
#         if isinstance(reply_text, bytes):
#             reply_text = self.reply_text.decode('utf8')
# 
#         return reply_text
# 
#     def __repr__(self):  # type: () -> str
#         return 'AMQPError(' + repr(self.reply_code) + ', ' + repr(
#             self.__get_reply_text()) + \
#                ', ' + repr(self.class_id) + ', ' + repr(self.method_id) + ')'
# 
#     def __init__(self, *args):
#         """
# 
#         :param args: can be either reply_code, reply_text, class_id, method_id
#                      or a ConnectionClose/ChannelClose.
#         """
#         from coolamqp.framing.definitions import ConnectionClose, ChannelClose
# 
#         if isinstance(args[0], (ConnectionClose, ChannelClose)):
#             self.reply_code = args[0].reply_code
#             self.reply_text = args[0].reply_text
#             self.class_id = args[0].class_id
#             self.method_id = args[0].method_id
#         else:
#             assert len(args) == 4
#             self.reply_code, self.reply_text, self.class_id, self.method_id = args


import unittest
from coolamqp.exceptions import AMQPError
# coding=UTF-8
from __future__ import print_function, absolute_import, division




class TestExcs(unittest.TestCase):
    def test_exist(self):
        e = AMQPError(100, u'wtf', 0, 0)

        self.assertTrue(u'100' in str(e))
        self.assertTrue(u'wtf' in str(e))
        self.assertTrue(repr(e).startswith(u'AMQPError'))

    def test_parses_memoryview_correctly(self):
        e = AMQPError(100, memoryview(u'wtf'.encode('utf8')), 0, 0)
        self.assertIn('wtf', str(e))
        self.assertIn('wtf', repr(e))


# Path: coolamqp/exceptions.py
# class AMQPError(CoolAMQPError):
#     """
#     Base class for errors received from AMQP server
#     """
# 
#     def is_hard_error(self):  # type: () -> bool
#         """Does this error close the connection?"""
#         return self.reply_code in HARD_ERRORS
# 
#     def __str__(self):  # type: () -> str
#         return 'AMQP error %s: %s' % (self.reply_code, self.__get_reply_text())
# 
#     def __get_reply_text(self):  # type: () -> str
#         if isinstance(self.reply_text, memoryview):
#             reply_text = self.reply_text.tobytes().decode('utf8')
#         else:
#             reply_text = self.reply_text
# 
#         if isinstance(reply_text, bytes):
#             reply_text = self.reply_text.decode('utf8')
# 
#         return reply_text
# 
#     def __repr__(self):  # type: () -> str
#         return 'AMQPError(' + repr(self.reply_code) + ', ' + repr(
#             self.__get_reply_text()) + \
#                ', ' + repr(self.class_id) + ', ' + repr(self.method_id) + ')'
# 
#     def __init__(self, *args):
#         """
# 
#         :param args: can be either reply_code, reply_text, class_id, method_id
#                      or a ConnectionClose/ChannelClose.
#         """
#         from coolamqp.framing.definitions import ConnectionClose, ChannelClose
# 
#         if isinstance(args[0], (ConnectionClose, ChannelClose)):
#             self.reply_code = args[0].reply_code
#             self.reply_text = args[0].reply_text
#             self.class_id = args[0].class_id
#             self.method_id = args[0].method_id
#         else:
#             assert len(args) == 4
#             self.reply_code, self.reply_text, self.class_id, self.method_id = args


# Path: tests/test_exceptions.py
import unittest
from coolamqp.exceptions import AMQPError

# coding=UTF-8
from __future__ import print_function, absolute_import, division




class TestExcs(unittest.TestCase):
    def test_exist(self):
        e = AMQPError(100, u'wtf', 0, 0)

        self.assertTrue(u'100' in str(e))
        self.assertTrue(u'wtf' in str(e))
        self.assertTrue(repr(e).startswith(u'AMQPError'))

    def test_parses_memoryview_correctly(self):
        e = AMQPError(100, memoryview(u'wtf'.encode('utf8')), 0, 0)
        self.assertIn('wtf', str(e))
        self.assertIn('wtf', repr(e))


        e = AMQPError(100, u'wtf'.encode('utf8'), 0, 0)