@@ -282,4 +282,60 @@ def test_migrate_only_classes():
282282 # Act
283283 _Utils .migrate ()
284284 # Assert
285- assert True # if no exception is raised, the test is ok
285+ assert True # if no exception is raised, the test is ok
286+
287+ def test_string_to_stream ():
288+ string = 'test'
289+ result = _Utils .string_to_stream (string )
290+ expect = 'test'
291+
292+ assert result .Read () == expect
293+
294+ def test_stream_to_string ():
295+ stream = iris .cls ('%Stream.GlobalCharacter' )._New ()
296+ stream .Write ('test' )
297+ result = _Utils .stream_to_string (stream )
298+ expect = 'test'
299+
300+ assert result == expect
301+
302+ def test_stream_to_string_empty ():
303+ stream = iris .cls ('%Stream.GlobalCharacter' )._New ()
304+ result = _Utils .stream_to_string (stream )
305+ expect = ''
306+
307+ assert result == expect
308+
309+ def test_stream_to_string_huge ():
310+ stream = iris .cls ('%Stream.GlobalCharacter' )._New ()
311+ for i in range (1000 ):
312+ stream .Write ('test' * 1000 )
313+ result = _Utils .stream_to_string (stream )
314+ expect = 'test' * 1000000
315+
316+ assert result == expect
317+
318+ class TestIOPMessage :
319+
320+ def test_set_json_string (self ):
321+ msg = iris .cls ('IOP.Message' )._New ()
322+ msg .json = '{"test": "test"}'
323+
324+ assert msg .json == '{"test": "test"}'
325+ assert msg .type == 'String'
326+
327+ def test_set_json_huge_string (self ):
328+ msg = iris .cls ('IOP.Message' )._New ()
329+ msg .json = '{"test": "test"}' * 100000
330+
331+ assert _Utils .stream_to_string (msg .json ) == '{"test": "test"}' * 100000
332+ assert msg .type == 'Stream'
333+
334+ def test_set_json_stream (self ):
335+ msg = iris .cls ('IOP.Message' )._New ()
336+ stream = iris .cls ('%Stream.GlobalCharacter' )._New ()
337+ stream .Write ('{"test": "test"}' )
338+ msg .json = stream
339+
340+ assert msg .json .Read () == '{"test": "test"}'
341+ assert msg .type == 'Stream'
0 commit comments