From 2a4194ede7ec56bda813c0e337d9195da8fe4d0c Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Thu, 31 Mar 2022 19:27:01 +0300 Subject: [PATCH] Finish tests --- test/suites/test_encoding.py | 104 +++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 35 deletions(-) diff --git a/test/suites/test_encoding.py b/test/suites/test_encoding.py index 68abc413..12e15ed1 100644 --- a/test/suites/test_encoding.py +++ b/test/suites/test_encoding.py @@ -113,34 +113,51 @@ def setUp(self): # str -> mp_str (string) -> str # bytes -> mp_bin (varbinary) -> bytes def test_01_01_str_encode_for_encoding_utf8_behavior(self): - self.assertNotRaises( - self.con_encoding_utf8.insert, - 'space_str', [ 'test_01_01' ]) + data = 'test_01_01' + space = 'space_str' + + self.assertNotRaises(self.con_encoding_utf8.insert, space, [data]) + + resp = self.con_encoding_utf8.select(space, [data]) + self.assertSequenceEqual(resp, [[data]]) def test_01_02_string_decode_for_encoding_utf8_behavior(self): - self.srv.admin(r"box.space['space_str']:insert{'test_01_02'}") + data = 'test_01_02' + space = 'space_str' - resp = self.con_encoding_utf8.eval("return box.space.space_str:get('test_01_02')") - self.assertSequenceEqual(resp, [['test_01_02']]) + self.srv.admin("box.space['%s']:insert{'%s'}" % (space, data)) + + resp = self.con_encoding_utf8.eval("return box.space['%s']:get('%s')" % (space, data)) + self.assertSequenceEqual(resp, [[data]]) @skip_or_run_mp_bin_test @skip_or_run_varbinary_test def test_01_03_bytes_encode_for_encoding_utf8_behavior(self): - self.assertNotRaises( - self.con_encoding_utf8.insert, - 'space_varbin', [ 103, bytes(bytearray.fromhex('DEADBEAF0103')) ]) + data_id = 103 + data = bytes(bytearray.fromhex('DEADBEAF0103')) + space = 'space_varbin' + + self.assertNotRaises(self.con_encoding_utf8.insert, space, [data_id, data]) + + resp = self.con_encoding_utf8.select(space, [ data ], index='varbin') + self.assertSequenceEqual(resp, [[data_id, data]]) @skip_or_run_mp_bin_test @skip_or_run_varbinary_test def test_01_04_varbinary_decode_for_encoding_utf8_behavior(self): - self.con_encoding_utf8.execute(r""" - INSERT INTO "space_varbin" VALUES (104, x'DEADBEAF0104'); - """) + data_id = 104 + data_hex = 'DEADBEAF0104' + data = bytes(bytearray.fromhex(data_hex)) + space = 'space_varbin' - resp = self.con_encoding_utf8.execute(r""" - SELECT * FROM "space_varbin" WHERE "varbin" == x'DEADBEAF0104'; - """) - self.assertSequenceEqual(resp, [[104, bytes(bytearray.fromhex('DEADBEAF0104'))]]) + self.con_encoding_utf8.execute(""" + INSERT INTO "%s" VALUES (%d, x'%s'); + """ % (space, data_id, data_hex)) + + resp = self.con_encoding_utf8.execute(""" + SELECT * FROM "%s" WHERE "varbin" == x'%s'; + """ % (space, data_hex)) + self.assertSequenceEqual(resp, [[data_id, data]]) # encoding = None # @@ -149,32 +166,49 @@ def test_01_04_varbinary_decode_for_encoding_utf8_behavior(self): # str -> mp_str (string) # mp_bin (string) -> bytes def test_02_01_str_encode_for_encoding_none_behavior(self): - self.assertNotRaises( - self.con_encoding_none.insert, - 'space_str', [ 'test_02_01' ]) + data = 'test_02_01' + space = 'space_str' + + self.assertNotRaises(self.con_encoding_none.insert, space, [data]) + + resp = self.con_encoding_utf8.select(space, [data]) + self.assertSequenceEqual(resp, [[data]]) def test_02_02_string_decode_for_encoding_none_behavior(self): - self.srv.admin(r"box.space['space_str']:insert{'test_02_02'}") + data = 'test_02_02' + data_decoded = b'test_02_02' + space = 'space_str' + + self.srv.admin("box.space['%s']:insert{'%s'}" % (space, data)) + + resp = self.con_encoding_none.eval("return box.space['%s']:get('%s')" % (space, data)) + self.assertSequenceEqual(resp, [[data_decoded]]) - resp = self.con_encoding_none.eval("return box.space.space_str:get('test_02_02')") - self.assertSequenceEqual(resp, [[b'test_02_02']]) + def test_02_03_bytes_encode_for_encoding_none_behavior(self): + data = b'test_02_03' + space = 'space_str' - def test_02_03_bytes_encode_for_encoding_utf8_behavior(self): - self.assertNotRaises( - self.con_encoding_none.insert, - 'space_str', [ b'test_02_03' ]) + self.assertNotRaises(self.con_encoding_none.insert, space, [data]) + + resp = self.con_encoding_none.select(space, [data]) + self.assertSequenceEqual(resp, [[data]]) @skip_or_run_mp_bin_test @skip_or_run_varbinary_test - def test_02_04_varbinary_decode_for_encoding_utf8_behavior(self): - self.con_encoding_none.execute(r""" - INSERT INTO "space_varbin" VALUES (204, x'DEADBEAF0204'); - """) - - resp = self.con_encoding_none.execute(r""" - SELECT * FROM "space_varbin" WHERE "varbin" == x'DEADBEAF0204'; - """) - self.assertSequenceEqual(resp, [[204, bytes(bytearray.fromhex('DEADBEAF0204'))]]) + def test_02_04_varbinary_decode_for_encoding_none_behavior(self): + data_id = 204 + data_hex = 'DEADBEAF0204' + data = bytes(bytearray.fromhex(data_hex)) + space = 'space_varbin' + + self.con_encoding_none.execute(""" + INSERT INTO "%s" VALUES (%d, x'%s'); + """ % (space, data_id, data_hex)) + + resp = self.con_encoding_none.execute(""" + SELECT * FROM "%s" WHERE "varbin" == x'%s'; + """ % (space, data_hex)) + self.assertSequenceEqual(resp, [[data_id, data]]) @classmethod def tearDownClass(self):