def testPackifyUnpackify(self):
        console.terse("{0}\n".format(self.testPackifyUnpackify.__doc__))

        fmt = u'3 2 1 1'
        fields = [6, 2, True, False]
        size = 1
        packed = byting.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([212]))
        self.assertEqual(byting.binize(byting.unbytify(packed), size*8), '11010100')

        packed = byting.packify(fmt=fmt, fields=fields)
        self.assertEqual(packed, bytearray([212]))
        self.assertEqual(byting.binize(byting.unbytify(packed), size*8), '11010100')

        fmt = u''
        fields = []
        size = 0
        packed = byting.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([]))

        packed = byting.packify(fmt=fmt, fields=fields)
        self.assertEqual(packed, bytearray([]))

        fmt = u'3 1'
        fields = [5, True]
        size = 1
        packed = byting.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xb0]))
        self.assertEqual(byting.binize(byting.unbytify(packed), size*8), '10110000')

        fmt = u'8 6 7 3'
        fields = [0xA5, 0x38, 0x08, 0x01]
        size = 3
        packed = byting.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xa5, 0xe0, 0x41]))
        self.assertEqual(byting.binize(byting.unbytify(packed), size*8), '101001011110000001000001')
        # 0xa5e040
        packed = byting.packify(fmt=fmt, fields=fields)
        self.assertEqual(packed, bytearray([0xa5, 0xe0, 0x41]))
        self.assertEqual(byting.binize(byting.unbytify(packed), size*8), '101001011110000001000001')

        fmt = u'3 2 1 1'
        packed = bytearray([212])
        fields = byting.unpackify(fmt=fmt, b=packed, boolean=True)
        self.assertEqual(fields, (6, 2, True, False, False))
        fields = byting.unpackify(fmt=fmt, b=packed, boolean=False)
        self.assertEqual(fields, (6, 2, 1, 0, 0))

        fmt = u''
        packed = bytearray([])
        fields = byting.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, tuple())

        fmt = u'3 1'
        packed = bytearray([0xb0])
        fields = byting.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (5, 1, 0))

        fmt = u'4 3 1'
        packed = [0x0b]  # converts to bytearray in parameter
        fields = byting.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0, 5, 1))

        fmt = u'8 6 7 3'
        packed = bytearray([0xa5, 0xe0, 0x41])
        fields = byting.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0xA5, 0x38, 0x08, 0x01))

        fmt = u'8 6 7 3'
        packed = bytearray([0xa5, 0xe0, 0x41, 0xff, 0xff])
        fields = byting.unpackify(fmt=fmt, b=packed, size=3)
        self.assertEqual(fields, (0xA5, 0x38, 0x08, 0x01))
Set the value of the 'to' attribute.
dataset/ETHPy150Open ioflo/ioflo/ioflo/aid/test/test_byting.py/BasicTestCase.testPackifyUnpackify--crossover with--dataset/ETHPy150Open CouchPotato/CouchPotatoServer/libs/xmpp/protocol.py/Protocol.setTo