]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Simplify bytes to hex string conversion (#1049)
authorTaneli Hukkinen <hukkinj1@users.noreply.github.com>
Sun, 5 Jul 2020 10:16:55 +0000 (13:16 +0300)
committerGitHub <noreply@github.com>
Sun, 5 Jul 2020 10:16:55 +0000 (12:16 +0200)
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
tests/test_multipart.py

index 2fc24123412be2e51b8e40ca8884d1bc1577cabd..fbabc7c483001e3fbdc8d0ecb1c854ece4b899d4 100644 (file)
@@ -1,4 +1,3 @@
-import binascii
 import cgi
 import io
 import os
@@ -115,7 +114,7 @@ def test_multipart_encode(tmp_path: typing.Any) -> None:
     files = {"file": ("name.txt", open(path, "rb"))}
 
     with mock.patch("os.urandom", return_value=os.urandom(16)):
-        boundary = binascii.hexlify(os.urandom(16)).decode("ascii")
+        boundary = os.urandom(16).hex()
 
         stream = encode(data=data, files=files)
         assert stream.can_replay()
@@ -141,7 +140,7 @@ def test_multipart_encode(tmp_path: typing.Any) -> None:
 def test_multipart_encode_files_allows_filenames_as_none() -> None:
     files = {"file": (None, io.BytesIO(b"<file content>"))}
     with mock.patch("os.urandom", return_value=os.urandom(16)):
-        boundary = binascii.hexlify(os.urandom(16)).decode("ascii")
+        boundary = os.urandom(16).hex()
 
         stream = encode(data={}, files=files)
         assert stream.can_replay()
@@ -167,7 +166,7 @@ def test_multipart_encode_files_guesses_correct_content_type(
 ) -> None:
     files = {"file": (file_name, io.BytesIO(b"<file content>"))}
     with mock.patch("os.urandom", return_value=os.urandom(16)):
-        boundary = binascii.hexlify(os.urandom(16)).decode("ascii")
+        boundary = os.urandom(16).hex()
 
         stream = encode(data={}, files=files)
         assert stream.can_replay()
@@ -190,7 +189,7 @@ def test_multipart_encode_files_allows_bytes_or_str_content(
 ) -> None:
     files = {"file": ("test.txt", value, "text/plain")}
     with mock.patch("os.urandom", return_value=os.urandom(16)):
-        boundary = binascii.hexlify(os.urandom(16)).decode("ascii")
+        boundary = os.urandom(16).hex()
 
         stream = encode(data={}, files=files)
         assert stream.can_replay()