55import pathlib
66import re
77import typing
8- import urllib .parse
8+ import base64
9+ import sys
910
11+ from unittest import skipIf
1012from unittest .mock import patch
1113
1214from tests .utils import testutils
@@ -113,9 +115,11 @@ def test_print_to_console_stdout(self):
113115
114116 def check_log_print_to_console_stdout (self ,
115117 host_out : typing .List [str ]):
116- # System logs stdout should not exist in host_out
117- self .assertNotIn ('Secret42' , host_out )
118+ # System logs stdout now exist in host_out
119+ self .assertIn ('Secret42' , host_out )
118120
121+ @skipIf (sys .version_info < (3 , 9 , 0 ),
122+ "Skip the tests for Python 3.8 and below" )
119123 def test_print_to_console_stderr (self ):
120124 r = self .webhost .request ('GET' , 'print_logging?console=true'
121125 '&message=Secret42&is_stderr=true' ,
@@ -125,23 +129,26 @@ def test_print_to_console_stderr(self):
125129
126130 def check_log_print_to_console_stderr (self ,
127131 host_out : typing .List [str ], ):
128- # System logs stderr should not exist in host_out
129- self .assertNotIn ('Secret42' , host_out )
132+ # System logs stderr now exist in host_out
133+ self .assertIn ('Secret42' , host_out )
130134
131135 def test_raw_body_bytes (self ):
132136 parent_dir = pathlib .Path (__file__ ).parent .parent
133137 image_file = parent_dir / 'unittests/resources/functions.png'
134138 with open (image_file , 'rb' ) as image :
135139 img = image .read ()
136- sanitized_image = urllib .parse .quote (img )
137- sanitized_img_len = len (sanitized_image )
140+ encoded_image = base64 .b64encode (img ).decode ('utf-8' )
141+ html_img_tag = \
142+ f'<img src="data:image/png;base64,{ encoded_image } " alt="PNG Image"/>' # noqa
143+ sanitized_img_len = len (html_img_tag )
138144 r = self .webhost .request ('POST' , 'raw_body_bytes' , data = img ,
139145 no_prefix = True )
140146
141147 received_body_len = int (r .headers ['body-len' ])
142148 self .assertEqual (received_body_len , sanitized_img_len )
143149
144- body = urllib .parse .unquote_to_bytes (r .content )
150+ encoded_image_data = encoded_image .split ("," )[0 ]
151+ body = base64 .b64decode (encoded_image_data )
145152 try :
146153 received_img_file = parent_dir / 'received_img.png'
147154 with open (received_img_file , 'wb' ) as received_img :
@@ -217,9 +224,9 @@ def check_log_hijack_current_event_loop(self,
217224 self .assertIn ('parallelly_log_custom at custom_logger' , host_out )
218225 self .assertIn ('callsoon_log' , host_out )
219226
220- # System logs should not exist in host_out
221- self .assertNotIn ('parallelly_log_system at disguised_logger' ,
222- host_out )
227+ # System logs now exist in host_out
228+ self .assertIn ('parallelly_log_system at disguised_logger' ,
229+ host_out )
223230
224231
225232class TestWsgiHttpFunctions (
0 commit comments