diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2020-11-23 19:32:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 22:32:23 +0400 |
| commit | 5a1562cc5e7048ba9d7efd3be9b89f42bb6986bc (patch) | |
| tree | 2a0dba913ad1d52f214fd9195aacaead7c8ea7fc /test | |
| parent | 83ddac1622426f5847bc2cee95f66ec0cf367604 (diff) | |
| download | urllib3-5a1562cc5e7048ba9d7efd3be9b89f42bb6986bc.tar.gz | |
Remove six (#2078)
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_filepost.py | 26 | ||||
| -rw-r--r-- | test/test_response.py | 3 | ||||
| -rw-r--r-- | test/test_util.py | 34 | ||||
| -rw-r--r-- | test/with_dummyserver/test_connectionpool.py | 3 | ||||
| -rw-r--r-- | test/with_dummyserver/test_https.py | 5 |
5 files changed, 49 insertions, 22 deletions
diff --git a/test/test_filepost.py b/test/test_filepost.py index 7c7e2bac..85f729af 100644 --- a/test/test_filepost.py +++ b/test/test_filepost.py @@ -2,9 +2,9 @@ import pytest from urllib3.fields import RequestField from urllib3.filepost import encode_multipart_formdata, iter_fields -from urllib3.packages.six import b BOUNDARY = "!! test boundary !!" +BOUNDARY_BYTES = BOUNDARY.encode() class TestIterfields: @@ -27,7 +27,7 @@ class TestMultipartEncoding: ) def test_input_datastructures(self, fields): encoded, _ = encode_multipart_formdata(fields, boundary=BOUNDARY) - assert encoded.count(b(BOUNDARY)) == 3 + assert encoded.count(BOUNDARY_BYTES) == 3 @pytest.mark.parametrize( "fields", @@ -40,15 +40,15 @@ class TestMultipartEncoding: def test_field_encoding(self, fields): encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY) expected = ( - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b'Content-Disposition: form-data; name="k"\r\n' b"\r\n" b"v\r\n" - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b'Content-Disposition: form-data; name="k2"\r\n' b"\r\n" b"v2\r\n" - b"--" + b(BOUNDARY) + b"--\r\n" + b"--" + BOUNDARY_BYTES + b"--\r\n" ) assert encoded == expected @@ -60,12 +60,12 @@ class TestMultipartEncoding: encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY) expected = ( - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b'Content-Disposition: form-data; name="k"; filename="somename"\r\n' b"Content-Type: application/octet-stream\r\n" b"\r\n" b"v\r\n" - b"--" + b(BOUNDARY) + b"--\r\n" + b"--" + BOUNDARY_BYTES + b"--\r\n" ) assert encoded == expected @@ -77,12 +77,12 @@ class TestMultipartEncoding: encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY) expected = ( - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b'Content-Disposition: form-data; name="k"; filename="somefile.txt"\r\n' b"Content-Type: text/plain\r\n" b"\r\n" b"v\r\n" - b"--" + b(BOUNDARY) + b"--\r\n" + b"--" + BOUNDARY_BYTES + b"--\r\n" ) assert encoded == expected @@ -94,12 +94,12 @@ class TestMultipartEncoding: encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY) expected = ( - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b'Content-Disposition: form-data; name="k"; filename="somefile.txt"\r\n' b"Content-Type: image/jpeg\r\n" b"\r\n" b"v\r\n" - b"--" + b(BOUNDARY) + b"--\r\n" + b"--" + BOUNDARY_BYTES + b"--\r\n" ) assert encoded == expected @@ -118,11 +118,11 @@ class TestMultipartEncoding: encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY) expected = ( - b"--" + b(BOUNDARY) + b"\r\n" + b"--" + BOUNDARY_BYTES + b"\r\n" b"Content-Type: image/jpeg\r\n" b"\r\n" b"v\r\n" - b"--" + b(BOUNDARY) + b"--\r\n" + b"--" + BOUNDARY_BYTES + b"--\r\n" ) assert encoded == expected diff --git a/test/test_response.py b/test/test_response.py index 8f528ccf..42971915 100644 --- a/test/test_response.py +++ b/test/test_response.py @@ -10,7 +10,6 @@ from test import onlyBrotlipy from unittest import mock import pytest -import six from urllib3.exceptions import ( DecodeError, @@ -801,7 +800,7 @@ class TestResponse: orig_ex = ctx.value.args[1] assert isinstance(orig_ex, InvalidChunkLength) - assert orig_ex.length == six.b(fp.BAD_LENGTH_LINE) + assert orig_ex.length == fp.BAD_LENGTH_LINE.encode() def test_chunked_response_without_crlf_on_end(self): stream = [b"foo", b"bar", b"baz"] diff --git a/test/test_util.py b/test/test_util.py index 56d93bb1..8fe6bd7f 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -32,6 +32,7 @@ from urllib3.util.ssl_ import ( ) from urllib3.util.timeout import Timeout from urllib3.util.url import Url, get_host, parse_url, split_first +from urllib3.util.util import to_bytes, to_str from . import clear_warnings @@ -776,6 +777,39 @@ class TestUtil: socket.return_value = Mock() create_connection((host, 80)) + @pytest.mark.parametrize( + "input,params,expected", + ( + ("test", {}, "test"), # str input + (b"test", {}, "test"), # bytes input + (b"test", {"encoding": "utf-8"}, "test"), # bytes input with utf-8 + (b"test", {"encoding": "ascii"}, "test"), # bytes input with ascii + ), + ) + def test_to_str(self, input, params, expected): + assert to_str(input, **params) == expected + + def test_to_str_error(self): + with pytest.raises(TypeError, match="not expecting type int"): + to_str(1) + + @pytest.mark.parametrize( + "input,params,expected", + ( + (b"test", {}, b"test"), # str input + ("test", {}, b"test"), # bytes input + ("é", {}, b"\xc3\xa9"), # bytes input + ("test", {"encoding": "utf-8"}, b"test"), # bytes input with utf-8 + ("test", {"encoding": "ascii"}, b"test"), # bytes input with ascii + ), + ) + def test_to_bytes(self, input, params, expected): + assert to_bytes(input, **params) == expected + + def test_to_bytes_error(self): + with pytest.raises(TypeError, match="not expecting type int"): + to_bytes(1) + class TestUtilSSL: """Test utils that use an SSL backend.""" diff --git a/test/with_dummyserver/test_connectionpool.py b/test/with_dummyserver/test_connectionpool.py index 9f3a8938..4a1dc470 100644 --- a/test/with_dummyserver/test_connectionpool.py +++ b/test/with_dummyserver/test_connectionpool.py @@ -26,7 +26,6 @@ from urllib3.exceptions import ( ReadTimeoutError, UnrewindableBodyError, ) -from urllib3.packages.six import b from urllib3.util import SKIP_HEADER, SKIPPABLE_HEADERS from urllib3.util.retry import RequestHistory, Retry from urllib3.util.timeout import Timeout @@ -700,7 +699,7 @@ class TestConnectionPool(HTTPDummyServerTestCase): self.host, self.port, source_address=addr, retries=False ) as pool: r = pool.request("GET", "/source_address") - assert r.data == b(addr[0]) + assert r.data == addr[0].encode() def test_source_address_error(self): for addr in INVALID_SOURCE_ADDRESSES: diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index ff0e369b..4306c2ef 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -40,7 +40,6 @@ from urllib3.exceptions import ( SSLError, SystemTimeWarning, ) -from urllib3.packages import six from urllib3.util.timeout import Timeout from .. import has_alpn @@ -48,10 +47,6 @@ from .. import has_alpn # Retry failed tests pytestmark = pytest.mark.flaky -ResourceWarning = getattr( - six.moves.builtins, "ResourceWarning", type("ResourceWarning", (), {}) -) - log = logging.getLogger("urllib3.connectionpool") log.setLevel(logging.NOTSET) |
