@@ -304,3 +304,54 @@ class NonPythonicallyNamedType(
304304 obj = cache .get (key )
305305 assert obj .type_name == type_name , 'Complex type name mismatch'
306306 assert obj .field == data , 'Complex object data failure'
307+
308+
309+ def test_complex_object_hash (client ):
310+ """
311+ Test that Python client correctly calculates hash of the binary
312+ object that contains negative bytes.
313+ """
314+ class Internal (
315+ metaclass = GenericObjectMeta ,
316+ type_name = 'Internal' ,
317+ schema = OrderedDict ([
318+ ('id' , IntObject ),
319+ ('str' , String ),
320+ ])
321+ ):
322+ pass
323+
324+ class TestObject (
325+ metaclass = GenericObjectMeta ,
326+ type_name = 'TestObject' ,
327+ schema = OrderedDict ([
328+ ('id' , IntObject ),
329+ ('str' , String ),
330+ ('internal' , BinaryObject ),
331+ ])
332+ ):
333+ pass
334+
335+ obj_ascii = TestObject ()
336+ obj_ascii .id = 1
337+ obj_ascii .str = 'test_string'
338+
339+ obj_ascii .internal = Internal ()
340+ obj_ascii .internal .id = 2
341+ obj_ascii .internal .str = 'lorem ipsum'
342+
343+ hash_ascii = BinaryObject .hashcode (obj_ascii , client = client )
344+
345+ assert hash_ascii == - 1314567146 , 'Invalid hashcode value for object with ASCII strings'
346+
347+ obj_utf8 = TestObject ()
348+ obj_utf8 .id = 1
349+ obj_utf8 .str = 'юникод'
350+
351+ obj_utf8 .internal = Internal ()
352+ obj_utf8 .internal .id = 2
353+ obj_utf8 .internal .str = 'ユニコード'
354+
355+ hash_utf8 = BinaryObject .hashcode (obj_utf8 , client = client )
356+
357+ assert hash_utf8 == - 1945378474 , 'Invalid hashcode value for object with UTF-8 strings'
0 commit comments