@@ -2363,6 +2363,48 @@ def test_getting_header_defaultint(self):
23632363 header = self .resp .getheader ('No-Such-Header' ,default = 42 )
23642364 self .assertEqual (header , 42 )
23652365
2366+ class ReprTest (TestCase ):
2367+
2368+ def test_http_connection_repr_default_port (self ):
2369+ conn = client .HTTPConnection ('example.com' )
2370+ self .assertEqual (repr (conn ), '<HTTPConnection example.com:80>' )
2371+
2372+ def test_http_connection_repr_explicit_port (self ):
2373+ conn = client .HTTPConnection ('example.com' , 8080 )
2374+ self .assertEqual (repr (conn ), '<HTTPConnection example.com:8080>' )
2375+
2376+ def test_https_connection_repr (self ):
2377+ if not hasattr (client , 'HTTPSConnection' ):
2378+ self .skipTest ('ssl support required' )
2379+ conn = client .HTTPSConnection ('example.com' )
2380+ self .assertEqual (repr (conn ), '<HTTPSConnection example.com:443>' )
2381+
2382+ def test_https_connection_repr_explicit_port (self ):
2383+ if not hasattr (client , 'HTTPSConnection' ):
2384+ self .skipTest ('ssl support required' )
2385+ conn = client .HTTPSConnection ('example.com' , 8443 )
2386+ self .assertEqual (repr (conn ), '<HTTPSConnection example.com:8443>' )
2387+
2388+ def test_http_response_repr_before_read (self ):
2389+ sock = FakeSocket (b'HTTP/1.1 200 OK\r \n \r \n ' )
2390+ resp = client .HTTPResponse (sock )
2391+ self .assertEqual (repr (resp ), '<HTTPResponse>' )
2392+
2393+ def test_http_response_repr_after_read (self ):
2394+ body = b'HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n '
2395+ sock = FakeSocket (body )
2396+ resp = client .HTTPResponse (sock )
2397+ resp .begin ()
2398+ self .assertEqual (repr (resp ), '<HTTPResponse [200 OK]>' )
2399+
2400+ def test_http_response_repr_not_found (self ):
2401+ body = b'HTTP/1.1 404 Not Found\r \n Content-Length: 0\r \n \r \n '
2402+ sock = FakeSocket (body )
2403+ resp = client .HTTPResponse (sock )
2404+ resp .begin ()
2405+ self .assertEqual (repr (resp ), '<HTTPResponse [404 Not Found]>' )
2406+
2407+
23662408class TunnelTests (TestCase ):
23672409 def setUp (self ):
23682410 response_text = (
0 commit comments