@@ -113,34 +113,51 @@ def setUp(self):
113113 # str -> mp_str (string) -> str
114114 # bytes -> mp_bin (varbinary) -> bytes
115115 def test_01_01_str_encode_for_encoding_utf8_behavior (self ):
116- self .assertNotRaises (
117- self .con_encoding_utf8 .insert ,
118- 'space_str' , [ 'test_01_01' ])
116+ data = 'test_01_01'
117+ space = 'space_str'
118+
119+ self .assertNotRaises (self .con_encoding_utf8 .insert , space , [data ])
120+
121+ resp = self .con_encoding_utf8 .select (space , [data ])
122+ self .assertSequenceEqual (resp , [[data ]])
119123
120124 def test_01_02_string_decode_for_encoding_utf8_behavior (self ):
121- self .srv .admin (r"box.space['space_str']:insert{'test_01_02'}" )
125+ data = 'test_01_02'
126+ space = 'space_str'
122127
123- resp = self .con_encoding_utf8 .eval ("return box.space.space_str:get('test_01_02')" )
124- self .assertSequenceEqual (resp , [['test_01_02' ]])
128+ self .srv .admin ("box.space['%s']:insert{'%s'}" % (space , data ))
129+
130+ resp = self .con_encoding_utf8 .eval ("return box.space['%s']:get('%s')" % (space , data ))
131+ self .assertSequenceEqual (resp , [[data ]])
125132
126133 @skip_or_run_mp_bin_test
127134 @skip_or_run_varbinary_test
128135 def test_01_03_bytes_encode_for_encoding_utf8_behavior (self ):
129- self .assertNotRaises (
130- self .con_encoding_utf8 .insert ,
131- 'space_varbin' , [ 103 , bytes (bytearray .fromhex ('DEADBEAF0103' )) ])
136+ data_id = 103
137+ data = bytes (bytearray .fromhex ('DEADBEAF0103' ))
138+ space = 'space_varbin'
139+
140+ self .assertNotRaises (self .con_encoding_utf8 .insert , space , [data_id , data ])
141+
142+ resp = self .con_encoding_utf8 .select (space , [ data ], index = 'varbin' )
143+ self .assertSequenceEqual (resp , [[data_id , data ]])
132144
133145 @skip_or_run_mp_bin_test
134146 @skip_or_run_varbinary_test
135147 def test_01_04_varbinary_decode_for_encoding_utf8_behavior (self ):
136- self .con_encoding_utf8 .execute (r"""
137- INSERT INTO "space_varbin" VALUES (104, x'DEADBEAF0104');
138- """ )
148+ data_id = 104
149+ data_hex = 'DEADBEAF0104'
150+ data = bytes (bytearray .fromhex (data_hex ))
151+ space = 'space_varbin'
139152
140- resp = self .con_encoding_utf8 .execute (r"""
141- SELECT * FROM "space_varbin" WHERE "varbin" == x'DEADBEAF0104';
142- """ )
143- self .assertSequenceEqual (resp , [[104 , bytes (bytearray .fromhex ('DEADBEAF0104' ))]])
153+ self .con_encoding_utf8 .execute ("""
154+ INSERT INTO "%s" VALUES (%d, x'%s');
155+ """ % (space , data_id , data_hex ))
156+
157+ resp = self .con_encoding_utf8 .execute ("""
158+ SELECT * FROM "%s" WHERE "varbin" == x'%s';
159+ """ % (space , data_hex ))
160+ self .assertSequenceEqual (resp , [[data_id , data ]])
144161
145162 # encoding = None
146163 #
@@ -149,32 +166,49 @@ def test_01_04_varbinary_decode_for_encoding_utf8_behavior(self):
149166 # str -> mp_str (string)
150167 # mp_bin (string) -> bytes
151168 def test_02_01_str_encode_for_encoding_none_behavior (self ):
152- self .assertNotRaises (
153- self .con_encoding_none .insert ,
154- 'space_str' , [ 'test_02_01' ])
169+ data = 'test_02_01'
170+ space = 'space_str'
171+
172+ self .assertNotRaises (self .con_encoding_none .insert , space , [data ])
173+
174+ resp = self .con_encoding_utf8 .select (space , [data ])
175+ self .assertSequenceEqual (resp , [[data ]])
155176
156177 def test_02_02_string_decode_for_encoding_none_behavior (self ):
157- self .srv .admin (r"box.space['space_str']:insert{'test_02_02'}" )
178+ data = 'test_02_02'
179+ data_decoded = b'test_02_02'
180+ space = 'space_str'
181+
182+ self .srv .admin ("box.space['%s']:insert{'%s'}" % (space , data ))
183+
184+ resp = self .con_encoding_none .eval ("return box.space['%s']:get('%s')" % (space , data ))
185+ self .assertSequenceEqual (resp , [[data_decoded ]])
158186
159- resp = self .con_encoding_none .eval ("return box.space.space_str:get('test_02_02')" )
160- self .assertSequenceEqual (resp , [[b'test_02_02' ]])
187+ def test_02_03_bytes_encode_for_encoding_none_behavior (self ):
188+ data = b'test_02_03'
189+ space = 'space_str'
161190
162- def test_02_03_bytes_encode_for_encoding_utf8_behavior (self ):
163- self . assertNotRaises (
164- self .con_encoding_none .insert ,
165- 'space_str' , [ b'test_02_03' ])
191+ self . assertNotRaises (self . con_encoding_none . insert , space , [ data ])
192+
193+ resp = self .con_encoding_none .select ( space , [ data ])
194+ self . assertSequenceEqual ( resp , [[ data ] ])
166195
167196 @skip_or_run_mp_bin_test
168197 @skip_or_run_varbinary_test
169- def test_02_04_varbinary_decode_for_encoding_utf8_behavior (self ):
170- self .con_encoding_none .execute (r"""
171- INSERT INTO "space_varbin" VALUES (204, x'DEADBEAF0204');
172- """ )
173-
174- resp = self .con_encoding_none .execute (r"""
175- SELECT * FROM "space_varbin" WHERE "varbin" == x'DEADBEAF0204';
176- """ )
177- self .assertSequenceEqual (resp , [[204 , bytes (bytearray .fromhex ('DEADBEAF0204' ))]])
198+ def test_02_04_varbinary_decode_for_encoding_none_behavior (self ):
199+ data_id = 204
200+ data_hex = 'DEADBEAF0204'
201+ data = bytes (bytearray .fromhex (data_hex ))
202+ space = 'space_varbin'
203+
204+ self .con_encoding_none .execute ("""
205+ INSERT INTO "%s" VALUES (%d, x'%s');
206+ """ % (space , data_id , data_hex ))
207+
208+ resp = self .con_encoding_none .execute ("""
209+ SELECT * FROM "%s" WHERE "varbin" == x'%s';
210+ """ % (space , data_hex ))
211+ self .assertSequenceEqual (resp , [[data_id , data ]])
178212
179213 @classmethod
180214 def tearDownClass (self ):
0 commit comments