|  | 
| 3 | 3 | from test.support import os_helper | 
| 4 | 4 | from test.support import requires_subprocess | 
| 5 | 5 | from test.support import warnings_helper | 
|  | 6 | +from test.support.testcase import ExtraAssertions | 
| 6 | 7 | from test import test_urllib | 
| 7 | 8 | from unittest import mock | 
| 8 | 9 | 
 | 
| @@ -724,7 +725,7 @@ def sanepathname2url(path): | 
| 724 | 725 |     return urlpath | 
| 725 | 726 | 
 | 
| 726 | 727 | 
 | 
| 727 |  | -class HandlerTests(unittest.TestCase): | 
|  | 728 | +class HandlerTests(unittest.TestCase, ExtraAssertions): | 
| 728 | 729 | 
 | 
| 729 | 730 |     def test_ftp(self): | 
| 730 | 731 |         class MockFTPWrapper: | 
| @@ -1179,15 +1180,15 @@ def test_errors(self): | 
| 1179 | 1180 |         r = MockResponse(200, "OK", {}, "", url) | 
| 1180 | 1181 |         newr = h.http_response(req, r) | 
| 1181 | 1182 |         self.assertIs(r, newr) | 
| 1182 |  | -        self.assertFalse(hasattr(o, "proto"))  # o.error not called | 
|  | 1183 | +        self.assertNotHasAttr(o, "proto")  # o.error not called | 
| 1183 | 1184 |         r = MockResponse(202, "Accepted", {}, "", url) | 
| 1184 | 1185 |         newr = h.http_response(req, r) | 
| 1185 | 1186 |         self.assertIs(r, newr) | 
| 1186 |  | -        self.assertFalse(hasattr(o, "proto"))  # o.error not called | 
|  | 1187 | +        self.assertNotHasAttr(o, "proto")  # o.error not called | 
| 1187 | 1188 |         r = MockResponse(206, "Partial content", {}, "", url) | 
| 1188 | 1189 |         newr = h.http_response(req, r) | 
| 1189 | 1190 |         self.assertIs(r, newr) | 
| 1190 |  | -        self.assertFalse(hasattr(o, "proto"))  # o.error not called | 
|  | 1191 | +        self.assertNotHasAttr(o, "proto")  # o.error not called | 
| 1191 | 1192 |         # anything else calls o.error (and MockOpener returns None, here) | 
| 1192 | 1193 |         r = MockResponse(502, "Bad gateway", {}, "", url) | 
| 1193 | 1194 |         self.assertIsNone(h.http_response(req, r)) | 
| @@ -1402,7 +1403,7 @@ def http_open(self, req): | 
| 1402 | 1403 |                 response = opener.open('http://example.com/') | 
| 1403 | 1404 |                 expected = b'GET ' + result + b' ' | 
| 1404 | 1405 |                 request = handler.last_buf | 
| 1405 |  | -                self.assertTrue(request.startswith(expected), repr(request)) | 
|  | 1406 | +                self.assertStartsWith(request, expected) | 
| 1406 | 1407 | 
 | 
| 1407 | 1408 |     def test_redirect_head_request(self): | 
| 1408 | 1409 |         from_url = "http://example.com/a.html" | 
| @@ -1833,7 +1834,7 @@ def test_invalid_closed(self): | 
| 1833 | 1834 |         self.assertTrue(conn.fakesock.closed, "Connection not closed") | 
| 1834 | 1835 | 
 | 
| 1835 | 1836 | 
 | 
| 1836 |  | -class MiscTests(unittest.TestCase): | 
|  | 1837 | +class MiscTests(unittest.TestCase, ExtraAssertions): | 
| 1837 | 1838 | 
 | 
| 1838 | 1839 |     def opener_has_handler(self, opener, handler_class): | 
| 1839 | 1840 |         self.assertTrue(any(h.__class__ == handler_class | 
| @@ -1892,9 +1893,9 @@ def test_HTTPError_interface(self): | 
| 1892 | 1893 |         url = code = fp = None | 
| 1893 | 1894 |         hdrs = 'Content-Length: 42' | 
| 1894 | 1895 |         err = urllib.error.HTTPError(url, code, msg, hdrs, fp) | 
| 1895 |  | -        self.assertTrue(hasattr(err, 'reason')) | 
|  | 1896 | +        self.assertHasAttr(err, 'reason') | 
| 1896 | 1897 |         self.assertEqual(err.reason, 'something bad happened') | 
| 1897 |  | -        self.assertTrue(hasattr(err, 'headers')) | 
|  | 1898 | +        self.assertHasAttr(err, 'headers') | 
| 1898 | 1899 |         self.assertEqual(err.headers, 'Content-Length: 42') | 
| 1899 | 1900 |         expected_errmsg = 'HTTP Error %s: %s' % (err.code, err.msg) | 
| 1900 | 1901 |         self.assertEqual(str(err), expected_errmsg) | 
|  | 
0 commit comments