Пример #1
0
    def test_decode_with_list(self):
        data = iter('\xa1\x03\x04\x00\x01\x03\x02' +
                    '\t127.0.0.1,l\t127.0.0.1+\xd6\x04ahoj')
        expected = hotrod.GetResponse(header=hotrod.ResponseHeader(
            id=3,
            tcm=1,
            tc=hotrod.TopologyChangeHeader(id=3,
                                           n=2,
                                           hosts=[
                                               hotrod.Host(ip='127.0.0.1',
                                                           port=11372),
                                               hotrod.Host(ip='127.0.0.1',
                                                           port=11222)
                                           ])),
                                      value=b'ahoj')
        actual = codec.Decoder().decode(data)

        assert expected.header.magic == actual.header.magic
        assert expected.header.id == actual.header.id
        assert expected.header.op == actual.header.op
        assert expected.header.status == actual.header.status
        assert expected.header.tcm == actual.header.tcm
        assert expected.value == actual.value

        assert expected.header.tc.id == actual.header.tc.id
        assert expected.header.tc.n == actual.header.tc.n
        assert expected.header.tc.hosts[0].ip == actual.header.tc.hosts[0].ip
        assert expected.header.tc.hosts[0].port \
            == actual.header.tc.hosts[0].port
        assert expected.header.tc.hosts[1].ip == actual.header.tc.hosts[1].ip
        assert expected.header.tc.hosts[1].port \
            == actual.header.tc.hosts[1].port
Пример #2
0
    def test_decode(self):
        data = iter('\xa1\x03\x04\x00\x00\x04ahoj')
        expected = hotrod.GetResponse(header=hotrod.ResponseHeader(id=3),
                                      value=b'ahoj')
        actual = codec.Decoder().decode(data)

        assert expected.header.magic == actual.header.magic
        assert expected.header.id == actual.header.id
        assert expected.header.op == actual.header.op
        assert expected.header.status == actual.header.status
        assert expected.header.tcm == actual.header.tcm
        assert expected.value == actual.value
Пример #3
0
 def test_decode_empty_byte(self):
     with pytest.raises(error.DecodeError):
         codec.Decoder(iter([''])).byte()
Пример #4
0
    def test_decode_utf8_string(self):
        string = iter('\x06\xc5\x99ahoj')
        expected = u'řahoj'
        actual = codec.Decoder(string).string()

        assert expected == actual
Пример #5
0
    def test_decode_long(self):
        l = iter('\x00\x04\x00\x00\x00\x00\x00\x00')
        expected = 1125899906842624
        actual = codec.Decoder(l).long()

        assert expected == actual
Пример #6
0
 def test_decode_uvarlong_fail_too_long(self):
     with pytest.raises(error.DecodeError):
         uvarlong = iter('\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01')
         codec.Decoder(uvarlong).uvarlong()
Пример #7
0
    def test_decode_string(self):
        string = iter('\x04ahoj')
        expected = 'ahoj'
        actual = codec.Decoder(string).string()

        assert expected == actual
Пример #8
0
    def test_decode_uvarint(self):
        uvarint = iter('\xe8\x07')
        expected = 1000
        actual = codec.Decoder(uvarint).uvarint()

        assert expected == actual
Пример #9
0
    def test_decode_uvarlong(self):
        uvarlong = iter('\x80\x80\x80\x80\x10')
        expected = 2**32
        actual = codec.Decoder(uvarlong).uvarlong()

        assert expected == actual
Пример #10
0
    def test_decode_ushort(self):
        short = iter('\x2b\xcb')
        expected = 11211
        actual = codec.Decoder(short).ushort()

        assert expected == actual
Пример #11
0
    def test_decode_splitbyte(self):
        byte2 = iter('\x76')
        expected = [0x07, 0x06]
        actual = codec.Decoder(byte2).splitbyte()

        assert expected == actual
Пример #12
0
    def test_decode_varbytes(self):
        bytes_ = iter('\x05ahoj\x76')
        expected = b'ahoj\x76'
        actual = codec.Decoder(bytes_).varbytes()

        assert expected == actual
Пример #13
0
    def test_decode_bytes(self):
        bytes_ = iter('ahoj\x76')
        expected = b'ahoj\x76'
        actual = codec.Decoder(bytes_).bytes(5)

        assert expected == actual
Пример #14
0
    def test_decode_byte(self):
        byte = iter('\x33')
        expected = 0x33
        actual = codec.Decoder(byte).byte()

        assert expected == actual