# Path: hbmqtt/adapters.py
# class BufferReader(ReaderAdapter):
#     """
#     Byte Buffer reader adapter
#     This adapter simply adapt reading a byte buffer.
#     """
#     def __init__(self, buffer: bytes):
#         self._stream = io.BytesIO(buffer)
# 
#     @asyncio.coroutine
#     def read(self, n=-1) -> bytes:
#         return self._stream.read(n)


import asyncio
import unittest
from hbmqtt.mqtt.unsubscribe import UnsubscribePacket, UnubscribePayload
from hbmqtt.mqtt.packet import PacketIdVariableHeader
from hbmqtt.adapters import BufferReader
# Copyright (c) 2015 Nicolas JOUANIN
#
# See the file license.txt for copying permission.



class UnsubscribePacketTest(unittest.TestCase):
    def setUp(self):
        self.loop = asyncio.new_event_loop()

    def test_from_stream(self):
        data = b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d'
        stream = BufferReader(data)

# Path: hbmqtt/adapters.py
# class BufferReader(ReaderAdapter):
#     """
#     Byte Buffer reader adapter
#     This adapter simply adapt reading a byte buffer.
#     """
#     def __init__(self, buffer: bytes):
#         self._stream = io.BytesIO(buffer)
# 
#     @asyncio.coroutine
#     def read(self, n=-1) -> bytes:
#         return self._stream.read(n)


# Path: tests/mqtt/test_unsubscribe.py
import asyncio
import unittest
from hbmqtt.mqtt.unsubscribe import UnsubscribePacket, UnubscribePayload
from hbmqtt.mqtt.packet import PacketIdVariableHeader
from hbmqtt.adapters import BufferReader

# Copyright (c) 2015 Nicolas JOUANIN
#
# See the file license.txt for copying permission.



class UnsubscribePacketTest(unittest.TestCase):
    def setUp(self):
        self.loop = asyncio.new_event_loop()

    def test_from_stream(self):
        data = b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d'
        stream = BufferReader(data)

        message = self.loop.run_until_complete(UnsubscribePacket.from_stream(stream))