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/test_util.py | |
parent | 83ddac1622426f5847bc2cee95f66ec0cf367604 (diff) | |
download | urllib3-5a1562cc5e7048ba9d7efd3be9b89f42bb6986bc.tar.gz |
Remove six (#2078)
Diffstat (limited to 'test/test_util.py')
-rw-r--r-- | test/test_util.py | 34 |
1 files changed, 34 insertions, 0 deletions
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.""" |