File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,24 @@ def hook(event, args):
341
341
gc .get_referents (y )
342
342
343
343
344
+ def test_http_client ():
345
+ import http .client
346
+
347
+ def hook (event , args ):
348
+ if event .startswith ("http.client." ):
349
+ print (event , * args [1 :])
350
+
351
+ sys .addaudithook (hook )
352
+
353
+ conn = http .client .HTTPConnection ('www.python.org' )
354
+ try :
355
+ conn .request ('GET' , '/' )
356
+ except OSError :
357
+ print ('http.client.send' , '[cannot send]' )
358
+ finally :
359
+ conn .close ()
360
+
361
+
344
362
if __name__ == "__main__" :
345
363
from test .support import suppress_msvcrt_asserts
346
364
Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ def test_gc(self):
130
130
["gc.get_objects" , "gc.get_referrers" , "gc.get_referents" ]
131
131
)
132
132
133
+ def test_http (self ):
134
+ support .import_module ("http.client" )
135
+ returncode , events , stderr = self .run_python ("test_http_client" )
136
+ if returncode :
137
+ self .fail (stderr )
138
+
139
+ if support .verbose :
140
+ print (* events , sep = '\n ' )
141
+ self .assertEqual (events [0 ][0 ], "http.client.connect" )
142
+ self .assertEqual (events [0 ][2 ], "www.python.org 80" )
143
+ self .assertEqual (events [1 ][0 ], "http.client.send" )
144
+ if events [1 ][2 ] != '[cannot send]' :
145
+ self .assertIn ('HTTP' , events [1 ][2 ])
146
+
133
147
134
148
if __name__ == "__main__" :
135
149
unittest .main ()
You can’t perform that action at this time.
0 commit comments