3333import os
3434import re
3535
36+ from io import TextIOWrapper
37+
3638import pytest
3739
40+ def build_command_input (getinfo_metadata , execute_metadata , execute_body ):
41+ header = ('chunked 1.0,{},0\n {}' .format (len (six .ensure_binary (getinfo_metadata )), getinfo_metadata ) +
42+ 'chunked 1.0,{},{}\n {}{}' .format (len (six .ensure_binary (execute_metadata )), len (six .ensure_binary (execute_body )), execute_metadata , execute_body ))
43+
44+ ifile = BytesIO (six .ensure_binary (header ))
45+
46+ if not six .PY2 :
47+ ifile = TextIOWrapper (ifile )
48+
49+ return ifile
50+
3851@Configuration ()
3952class TestCommand (SearchCommand ):
4053
@@ -428,11 +441,9 @@ def test_process_scpv2(self):
428441 show_configuration = ('true' if show_configuration is True else 'false' ))
429442
430443 execute_metadata = '{"action":"execute","finished":true}'
431- execute_body = 'test\r \n data\r \n '
444+ execute_body = 'test\r \n data\r \n 测试 \r \ n '
432445
433- ifile = StringIO (
434- 'chunked 1.0,{},0\n {}' .format (len (getinfo_metadata ), getinfo_metadata ) +
435- 'chunked 1.0,{},{}\n {}{}' .format (len (execute_metadata ), len (execute_body ), execute_metadata , execute_body ))
446+ ifile = build_command_input (getinfo_metadata , execute_metadata , execute_body )
436447
437448 command = TestCommand ()
438449 result = BytesIO ()
@@ -455,12 +466,17 @@ def test_process_scpv2(self):
455466 self .assertEqual (command .required_option_1 , 'value_1' )
456467 self .assertEqual (command .required_option_2 , 'value_2' )
457468
458- self . assertEqual (
469+ expected = (
459470 'chunked 1.0,68,0\n '
460471 '{"inspector":{"messages":[["INFO","test command configuration: "]]}}\n '
461- 'chunked 1.0,17,23 \n '
472+ 'chunked 1.0,17,32 \n '
462473 '{"finished":true}test,__mv_test\r \n '
463- 'data,\r \n ' ,
474+ 'data,\r \n '
475+ '测试,\r \n '
476+ )
477+
478+ self .assertEqual (
479+ expected ,
464480 result .getvalue ().decode ('utf-8' ))
465481
466482 self .assertEqual (command .protocol_version , 2 )
@@ -620,11 +636,9 @@ def test_process_scpv2(self):
620636 show_configuration = show_configuration )
621637
622638 execute_metadata = '{"action":"execute","finished":true}'
623- execute_body = 'test\r \n data\r \n '
639+ execute_body = 'test\r \n data\r \n 测试 \r \ n '
624640
625- ifile = StringIO (
626- 'chunked 1.0,{},0\n {}' .format (len (getinfo_metadata ), getinfo_metadata ) +
627- 'chunked 1.0,{},{}\n {}{}' .format (len (execute_metadata ), len (execute_body ), execute_metadata , execute_body ))
641+ ifile = build_command_input (getinfo_metadata , execute_metadata , execute_body )
628642
629643 command = TestCommand ()
630644 result = BytesIO ()
@@ -666,11 +680,9 @@ def test_process_scpv2(self):
666680 show_configuration = ('true' if show_configuration is True else 'false' ))
667681
668682 execute_metadata = '{"action":"execute","finished":true}'
669- execute_body = 'action\r \n raise_exception\r \n '
683+ execute_body = 'action\r \n raise_exception\r \n 测试 \r \ n '
670684
671- ifile = StringIO (
672- 'chunked 1.0,{},0\n {}' .format (len (getinfo_metadata ), getinfo_metadata ) +
673- 'chunked 1.0,{},{}\n {}{}' .format (len (execute_metadata ), len (execute_body ), execute_metadata , execute_body ))
685+ ifile = build_command_input (getinfo_metadata , execute_metadata , execute_body )
674686
675687 command = TestCommand ()
676688 result = BytesIO ()
0 commit comments