Skip to content

Commit

Permalink
Finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentialOrange committed Mar 31, 2022
1 parent 88fa990 commit 2a4194e
Showing 1 changed file with 69 additions and 35 deletions.
104 changes: 69 additions & 35 deletions test/suites/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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):
Expand Down

0 comments on commit 2a4194e

Please sign in to comment.