From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 052494765E0 for ; Tue, 22 Dec 2020 11:19:02 +0300 (MSK) References: <7ad65976-902f-8936-cb85-4232ff7ffce3@tarantool.org> <45fa75d8-129b-3170-eda2-5d170e225748@tarantool.org> <09d776ce-85fc-d5a5-f85a-2bf86f2d73fc@tarantool.org> From: Sergey Bronnikov Message-ID: Date: Tue, 22 Dec 2020 11:19:01 +0300 MIME-Version: 1.0 In-Reply-To: <09d776ce-85fc-d5a5-f85a-2bf86f2d73fc@tarantool.org> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [Tarantool-patches] [PATCH 3/4] test: make convert to hex compatible with Python 3.x List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Leonid Vasiliev , tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, imun@tarantool.org Cc: alexander.turenko@tarantool.org Hi, On 17.12.2020 21:26, Leonid Vasiliev wrote: > Hi! > > On 16.12.2020 17:04, Sergey Bronnikov wrote: >> Hello, >> >> >> On 15.12.2020 14:55, Leonid Vasiliev wrote: >>> Hi! Thank you for the patch. >>> >>> On 11.12.2020 11:42, Sergey Bronnikov via Tarantool-patches wrote: >>>> From: Sergey Bronnikov >>>> >>>> Part of #5538 >>>> --- >>>>   test/box-py/iproto.test.py | 6 +++++- >>>>   1 file changed, 5 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/test/box-py/iproto.test.py b/test/box-py/iproto.test.py >>>> index 25ead43c4..72400923c 100644 >>>> --- a/test/box-py/iproto.test.py >>>> +++ b/test/box-py/iproto.test.pyHi >>>> @@ -191,7 +191,11 @@ for test in TESTS: >>>>       print("STR", size) >>>>       print("--") >>>>       for fmt in it: >>>> -        print("0x" + fmt.encode("hex"), "=>", end=" ") >>>> +        try: >>>> +            # Python 3 >>>> +            print("0x" + "hex".encode("utf-8").hex(), "=>", end=" ") >>> >>> Maybe fmt.encode("utf-8").hex()? >> >> I would be glad to use it in Python 3, but fmt module was removed there. > > Sorry, but I don't understand which module "fmt" you mean. I don't see > any `import fmt...` here. AFAIU `fmt` in this context is a string from > one of the tuples from the list `TESTS`. > > So, I copy this hunk: > ``` > from __future__ import print_function > > TESTS = [ >     (1,     "\xa1", "\xd9\x01", "\xda\x00\x01", "\xdb\x00\x00\x00\x01"), >     (31,    "\xbf", "\xd9\x1f", "\xda\x00\x1f", "\xdb\x00\x00\x00\x1f"), >     (32,    "\xd9\x20", "\xda\x00\x20", "\xdb\x00\x00\x00\x20"), >     (255,   "\xd9\xff", "\xda\x00\xff", "\xdb\x00\x00\x00\xff"), >     (256,   "\xda\x01\x00", "\xdb\x00\x00\x01\x00"), >     (65535, "\xda\xff\xff", "\xdb\x00\x00\xff\xff"), >     (65536, "\xdb\x00\x01\x00\x00"), > ] > > for test in TESTS: >     it = iter(test) >     size = next(it) >     print("STR", size) >     print("--") >     for fmt in it: >         try: >             # Python 3 >             print("0x" + "hex".encode("utf-8").hex(), "=>", end=" ") >         except AttributeError: >             print("0x" + fmt.encode("hex"), "=>", end=" ") >         print() >     print() > ``` > > and run it on python2 and python3. > Results doesn't look identically. > > Python2: > ``` > ┌─[leonid@vasya-L460]─[~/work/mail/tarantool/tmp] > └──╼ python2 test.py > STR 1 > -- > 0xa1 => > 0xd901 => > 0xda0001 => > 0xdb00000001 => > > STR 31 > -- > 0xbf => > 0xd91f => > 0xda001f => > 0xdb0000001f => > > STR 32 > -- > 0xd920 => > 0xda0020 => > 0xdb00000020 => > > STR 255 > -- > 0xd9ff => > 0xda00ff => > 0xdb000000ff => > > STR 256 > -- > 0xda0100 => > 0xdb00000100 => > > STR 65535 > -- > 0xdaffff => > 0xdb0000ffff => > > STR 65536 > -- > 0xdb00010000 => > > ``` > > Python3: > ``` > ┌─[leonid@vasya-L460]─[~/work/mail/tarantool/tmp] > └──╼ python3 test.py > STR 1 > -- > 0x686578 => > 0x686578 => > 0x686578 => > 0x686578 => > > STR 31 > -- > 0x686578 => > 0x686578 => > 0x686578 => > 0x686578 => > > STR 32 > -- > 0x686578 => > 0x686578 => > 0x686578 => > > STR 255 > -- > 0x686578 => > 0x686578 => > 0x686578 => > > STR 256 > -- > 0x686578 => > 0x686578 => > > STR 65535 > -- > 0x686578 => > 0x686578 => > > STR 65536 > -- > 0x686578 => > > ``` > > Am I doing something wrong or a bug in the patch? Yep, patch was incorrect. I have removed it and added new one to the branch and send to this thread [1]. Could you please take a look? 1. https://lists.tarantool.org/pipermail/tarantool-patches/2020-December/021528.html > >> >> >>> Please, add a comment that describing the difference between python2 >>> and >>> python3 in this print. >>> >> Added comment to a commit message and force-pushed. >>>> +        except AttributeError: >>>> +            print("0x" + fmt.encode("hex"), "=>", end=" ") >>>>           field = "*" * size >>>>           c._send_request(RawInsert(c, space_id, "\x91" + fmt + >>>> field)) >>>>           tuple = space.select(field)[0] >>>>