test_utils.py
This file
Path
tests/test_utils.py
926 lines · 27.6 KiB · Python
Last changed by
Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
History of this fileTake it
The walk stopped after 200 commits: lines older than 737dd0c point at it.
Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 1–2why, one step back1import copy2import filecmpAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 3why, one step back3import osCatch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 4why, one step back4import tarfileUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 5–6why, one step back5import zipfile6from collections import dequeAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 7why, one step back7from io import BytesIORemove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 8why, one step back8from unittest import mockUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 9–10why, one step back910import pytestAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 11why, one step back11Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 12why, one step back12from requests import compatAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 13why, one step back13from requests._internal_utils import unicode_is_asciiUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 14–16why, one step back14from requests.cookies import RequestsCookieJar15from requests.structures import CaseInsensitiveDict16from requests.utils import (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 17–44why, one step back17 _parse_content_type_header,18 add_dict_to_cookiejar,19 address_in_network,20 dotted_netmask,21 extract_zipped_paths,22 get_auth_from_url,23 get_encoding_from_headers,24 get_encodings_from_content,25 get_environ_proxies,26 guess_filename,27 guess_json_utf,28 is_ipv4_address,29 is_valid_cidr,30 iter_slices,31 parse_dict_header,32 parse_header_links,33 prepend_scheme_if_needed,34 requote_uri,35 select_proxy,36 set_environ,37 should_bypass_proxies,38 super_len,39 to_key_val_list,40 to_native_string,41 unquote_header_value,42 unquote_unreserved,43 urldefragauth,44)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 45–50why, one step back4546from .compat import StringIO, cStringIO474849class TestSuperLen:50 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 51–59why, one step back51 "stream, value",52 (53 (StringIO.StringIO, "Test"),54 (BytesIO, b"Test"),55 pytest.param(56 cStringIO, "Test", marks=pytest.mark.skipif("cStringIO is None")57 ),58 ),59 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 60–67why, one step back60 def test_io_streams(self, stream, value):61 """Ensures that we properly deal with different kinds of IO streams."""62 assert super_len(stream()) == 063 assert super_len(stream(value)) == 46465 def test_super_len_correctly_calculates_len_of_partially_read_file(self):66 """Ensure that we handle partially consumed file like objects."""67 s = StringIO.StringIO()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 68why, one step back68 s.write("foobarbogus")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 69–70why, one step back69 assert super_len(s) == 070Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 71why, one step back71 @pytest.mark.parametrize("error", [IOError, OSError])Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 72–73why, one step back72 def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):73 """If tell() raises errors, assume the cursor is at position zero."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 74–75why, one step back7475 class BoomFile:Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 76–83why, one step back76 def __len__(self):77 return 57879 def tell(self):80 raise error()8182 assert super_len(BoomFile()) == 083Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 84why, one step back84 @pytest.mark.parametrize("error", [IOError, OSError])Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 85–86why, one step back85 def test_super_len_tell_ioerror(self, error):86 """Ensure that if tell gives an IOError super_len doesn't fail"""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 87–88why, one step back8788 class NoLenBoomFile:Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 89–97why, one step back89 def tell(self):90 raise error()9192 def seek(self, offset, whence):93 pass9495 assert super_len(NoLenBoomFile()) == 09697 def test_string(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 98why, one step back98 assert super_len("Test") == 4Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 99–100why, one step back99100 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 101–106why, one step back101 "mode, warnings_num",102 (103 ("r", 1),104 ("rb", 0),105 ),106 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 107why, one step back107 def test_file(self, tmpdir, mode, warnings_num, recwarn):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 108–109why, one step back108 file_obj = tmpdir.join("test.txt")109 file_obj.write("Test")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 110–112why, one step back110 with file_obj.open(mode) as fd:111 assert super_len(fd) == 4112 assert len(recwarn) == warnings_numCatch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 113–114why, one step back113114 def test_tarfile_member(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 115–116why, one step back115 file_obj = tmpdir.join("test.txt")116 file_obj.write("Test")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 117why, one step back117Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 118–120why, one step back118 tar_obj = str(tmpdir.join("test.tar"))119 with tarfile.open(tar_obj, "w") as tar:120 tar.add(str(file_obj), arcname="test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 121–122why, one step back121122 with tarfile.open(tar_obj) as tar:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 123why, one step back123 member = tar.extractfile("test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 124why, one step back124 assert super_len(member) == 4Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 125–126why, one step back125126 def test_super_len_with__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 127why, one step back127 foo = [1, 2, 3, 4]Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 128–131why, one step back128 len_foo = super_len(foo)129 assert len_foo == 4130131 def test_super_len_with_no__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 132why, one step back132 class LenFile:Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 133–138why, one step back133 def __init__(self):134 self.len = 5135136 assert super_len(LenFile()) == 5137138 def test_super_len_with_tell(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 139why, one step back139 foo = StringIO.StringIO("12345")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 140–144why, one step back140 assert super_len(foo) == 5141 foo.read(2)142 assert super_len(foo) == 3143144 def test_super_len_with_fileno(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 145why, one step back145 with open(__file__, "rb") as f:Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 146–156why, one step back146 length = super_len(f)147 file_data = f.read()148 assert length == len(file_data)149150 def test_super_len_with_no_matches(self):151 """Ensure that objects without any length methods default to 0"""152 assert super_len(object()) == 0153154155class TestToKeyValList:156 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 157–164why, one step back157 "value, expected",158 (159 ([("key", "val")], [("key", "val")]),160 ((("key", "val"),), [("key", "val")]),161 ({"key": "val"}, [("key", "val")]),162 (None, None),163 ),164 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 165–169why, one step back165 def test_valid(self, value, expected):166 assert to_key_val_list(value) == expected167168 def test_invalid(self):169 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 170why, one step back170 to_key_val_list("string")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 171–174why, one step back171172173class TestUnquoteHeaderValue:174 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 175–176why, one step back175 "value, expected",176 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 177why, one step back177 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 178–183why, one step back178 ("Test", "Test"),179 ('"Test"', "Test"),180 ('"Test\\\\"', "Test\\"),181 ('"\\\\Comp\\Res"', "\\Comp\\Res"),182 ),183 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 184–187why, one step back184 def test_valid(self, value, expected):185 assert unquote_header_value(value) == expected186187 def test_is_filename(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 188why, one step back188 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 189–195why, one step back189190191class TestGetEnvironProxies:192 """Ensures that IP addresses are correctly matches with ranges193 in no_proxy variable.194 """195Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 196why, one step back196 @pytest.fixture(autouse=True, params=["no_proxy", "NO_PROXY"])Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 197why, one step back197 def no_proxy(self, request, monkeypatch):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 198–200why, one step back198 monkeypatch.setenv(199 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"200 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 201–202why, one step back201202 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 203–211why, one step back203 "url",204 (205 "http://192.168.0.1:5000/",206 "http://192.168.0.1/",207 "http://172.16.1.1/",208 "http://172.16.1.1:5000/",209 "http://localhost.localdomain:5000/v1.0/",210 ),211 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 212–215why, one step back212 def test_bypass(self, url):213 assert get_environ_proxies(url, no_proxy=None) == {}214215 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 216–222why, one step back216 "url",217 (218 "http://192.168.1.1:5000/",219 "http://192.168.1.1/",220 "http://www.requests.com/",221 ),222 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 223–226why, one step back223 def test_not_bypass(self, url):224 assert get_environ_proxies(url, no_proxy=None) != {}225226 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 227–233why, one step back227 "url",228 (229 "http://192.168.1.1:5000/",230 "http://192.168.1.1/",231 "http://www.requests.com/",232 ),233 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 234why, one step back234 def test_bypass_no_proxy_keyword(self, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 235why, one step back235 no_proxy = "192.168.1.1,requests.com"Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 236–238why, one step back236 assert get_environ_proxies(url, no_proxy=no_proxy) == {}237238 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 239–247why, one step back239 "url",240 (241 "http://192.168.0.1:5000/",242 "http://192.168.0.1/",243 "http://172.16.1.1/",244 "http://172.16.1.1:5000/",245 "http://localhost.localdomain:5000/v1.0/",246 ),247 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 248–250why, one step back248 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):249 # This is testing that the 'no_proxy' argument overrides the250 # environment variable 'no_proxy'Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 251–252why, one step back251 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")252 no_proxy = "192.168.1.1,requests.com"Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 253–257why, one step back253 assert get_environ_proxies(url, no_proxy=no_proxy) != {}254255256class TestIsIPv4Address:257 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 258why, one step back258 assert is_ipv4_address("8.8.8.8")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 259why, one step back259Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 260why, one step back260 @pytest.mark.parametrize("value", ("8.8.8.8.8", "localhost.localdomain"))Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 261–266why, one step back261 def test_invalid(self, value):262 assert not is_ipv4_address(value)263264265class TestIsValidCIDR:266 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 267why, one step back267 assert is_valid_cidr("192.168.1.0/24")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 268–269why, one step back268269 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 270–278why, one step back270 "value",271 (272 "8.8.8.8",273 "192.168.1.0/a",274 "192.168.1.0/128",275 "192.168.1.0/-1",276 "192.168.1.999/24",277 ),278 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 279–284why, one step back279 def test_invalid(self, value):280 assert not is_valid_cidr(value)281282283class TestAddressInNetwork:284 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 285why, one step back285 assert address_in_network("192.168.1.1", "192.168.1.0/24")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 286–287why, one step back286287 def test_invalid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 288why, one step back288 assert not address_in_network("172.16.0.1", "192.168.1.0/24")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 289–292why, one step back289290291class TestGuessFilename:292 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 293–294why, one step back293 "value",294 (1, type("Fake", (object,), {"name": 1})()),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 295–299why, one step back295 )296 def test_guess_filename_invalid(self, value):297 assert guess_filename(value) is None298299 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 300–305why, one step back300 "value, expected_type",301 (302 (b"value", compat.bytes),303 (b"value".decode("utf-8"), compat.str),304 ),305 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 306why, one step back306 def test_guess_filename_valid(self, value, expected_type):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 307why, one step back307 obj = type("Fake", (object,), {"name": value})()Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 308–314why, one step back308 result = guess_filename(obj)309 assert result == value310 assert isinstance(result, expected_type)311312313class TestExtractZippedPaths:314 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 315–317why, one step back315 "path",316 (317 "/",Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 318–319why, one step back318 __file__,319 pytest.__file__,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 320–322why, one step back320 "/etc/invalid/location",321 ),322 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 323–326why, one step back323 def test_unzipped_paths_unchanged(self, path):324 assert path == extract_zipped_paths(path)325326 def test_zipped_paths_extracted(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 327–328why, one step back327 zipped_py = tmpdir.join("test.zip")328 with zipfile.ZipFile(zipped_py.strpath, "w") as f:Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 329–331why, one step back329 f.write(__file__)330331 _, name = os.path.splitdrive(__file__)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 332why, one step back332 zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/"))Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 333–338why, one step back333 extracted_path = extract_zipped_paths(zipped_path)334335 assert extracted_path != zipped_path336 assert os.path.exists(extracted_path)337 assert filecmp.cmp(extracted_path, __file__)338Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851)Thomas Lambefore adoptiond8829f9
lines 339–342why, one step back339 def test_invalid_unc_path(self):340 path = r"\\localhost\invalid\location"341 assert extract_zipped_paths(path) == path342Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 343–345why, one step back343344class TestContentEncodingDetection:345 def test_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 346why, one step back346 encodings = get_encodings_from_content("")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 347–349why, one step back347 assert not len(encodings)348349 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 350–351why, one step back350 "content",351 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 352–359why, one step back352 # HTML5 meta charset attribute353 '<meta charset="UTF-8">',354 # HTML4 pragma directive355 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',356 # XHTML 1.x served with text/html MIME type357 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',358 # XHTML 1.x served as XML359 '<?xml version="1.0" encoding="UTF-8"?>',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 360–361why, one step back360 ),361 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 362–364why, one step back362 def test_pragmas(self, content):363 encodings = get_encodings_from_content(content)364 assert len(encodings) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 365why, one step back365 assert encodings[0] == "UTF-8"Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 366–367why, one step back366367 def test_precedence(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 368why, one step back368 content = """Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 369–371why, one step back369 <?xml version="1.0" encoding="XML"?>370 <meta charset="HTML5">371 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 372–373why, one step back372 """.strip()373 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 374–377why, one step back374375376class TestGuessJSONUTF:377 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 378–389why, one step back378 "encoding",379 (380 "utf-32",381 "utf-8-sig",382 "utf-16",383 "utf-8",384 "utf-16-be",385 "utf-16-le",386 "utf-32-be",387 "utf-32-le",388 ),389 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 390why, one step back390 def test_encoded(self, encoding):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 391why, one step back391 data = "{}".encode(encoding)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 392–394why, one step back392 assert guess_json_utf(data) == encoding393394 def test_bad_utf_like_encoding(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 395why, one step back395 assert guess_json_utf(b"\x00\x00\x00\x00") is NoneUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 396–397why, one step back396397 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 398–405why, one step back398 ("encoding", "expected"),399 (400 ("utf-16-be", "utf-16"),401 ("utf-16-le", "utf-16"),402 ("utf-32-be", "utf-32"),403 ("utf-32-le", "utf-32"),404 ),405 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 406why, one step back406 def test_guess_by_bom(self, encoding, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 407why, one step back407 data = "\ufeff{}".encode(encoding)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 408–411why, one step back408 assert guess_json_utf(data) == expected409410411USER = PASSWORD = "%!*'();:@&=+$,/?#[] "Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 412–413why, one step back412ENCODED_USER = compat.quote(USER, "")413ENCODED_PASSWORD = compat.quote(PASSWORD, "")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 414–416why, one step back414415416@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 417–418why, one step back417 "url, auth",418 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 419why, one step back419 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 420–421why, one step back420 f"http://{ENCODED_USER}:{ENCODED_PASSWORD}@request.com/url.html#test",421 (USER, PASSWORD),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 422why, one step back422 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 423why, one step back423 ("http://user:pass@complex.url.com/path?query=yes", ("user", "pass")),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 424why, one step back424 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 425–426why, one step back425 "http://user:pass%20pass@complex.url.com/path?query=yes",426 ("user", "pass pass"),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 427why, one step back427 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 428why, one step back428 ("http://user:pass pass@complex.url.com/path?query=yes", ("user", "pass pass")),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 429why, one step back429 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 430–431why, one step back430 "http://user%25user:pass@complex.url.com/path?query=yes",431 ("user%user", "pass"),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 432–433why, one step back432 ),433 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 434–435why, one step back434 "http://user:pass%23pass@complex.url.com/path?query=yes",435 ("user", "pass#pass"),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 436why, one step back436 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 437–439why, one step back437 ("http://complex.url.com/path?query=yes", ("", "")),438 ),439)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 440–444why, one step back440def test_get_auth_from_url(url, auth):441 assert get_auth_from_url(url) == auth442443444@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 445–446why, one step back445 "uri, expected",446 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 447–448why, one step back447 (448 # Ensure requoting doesn't break expectationsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 449–450why, one step back449 "http://example.com/fiz?buz=%25ppicture",450 "http://example.com/fiz?buz=%25ppicture",Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 451–453why, one step back451 ),452 (453 # Ensure we handle unquoted percent signs in redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 454–455why, one step back454 "http://example.com/fiz?buz=%ppicture",455 "http://example.com/fiz?buz=%25ppicture",Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 456why, one step back456 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 457–458why, one step back457 ),458)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 459–464why, one step back459def test_requote_uri_with_unquoted_percents(uri, expected):460 """See: https://github.com/psf/requests/issues/2356"""461 assert requote_uri(uri) == expected462463464@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 465–466why, one step back465 "uri, expected",466 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 467–468why, one step back467 (468 # Illegal bytesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 469–470why, one step back469 "http://example.com/?a=%--",470 "http://example.com/?a=%--",Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 471–473why, one step back471 ),472 (473 # Reserved charactersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 474–478why, one step back474 "http://example.com/?a=%300",475 "http://example.com/?a=00",476 ),477 ),478)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 479–483why, one step back479def test_unquote_unreserved(uri, expected):480 assert unquote_unreserved(uri) == expected481482483@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 484–490why, one step back484 "mask, expected",485 (486 (8, "255.0.0.0"),487 (24, "255.255.255.0"),488 (25, "255.255.255.128"),489 ),490)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 491–494why, one step back491def test_dotted_netmask(mask, expected):492 assert dotted_netmask(mask) == expected493494Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 495–507why, one step back495http_proxies = {496 "http": "http://http.proxy",497 "http://some.host": "http://some.host.proxy",498}499all_proxies = {500 "all": "socks5://http.proxy",501 "all://some.host": "socks5://some.host.proxy",502}503mixed_proxies = {504 "http": "http://http.proxy",505 "http://some.host": "http://some.host.proxy",506 "all": "socks5://http.proxy",507}Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 508–509why, one step back508509Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 510–526why, one step back510@pytest.mark.parametrize(511 "url, expected, proxies",512 (513 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),514 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),515 ("hTTp:///path", "http://http.proxy", http_proxies),516 ("hTTps://Other.Host", None, http_proxies),517 ("file:///etc/motd", None, http_proxies),518 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),519 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),520 ("hTTp:///path", "socks5://http.proxy", all_proxies),521 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),522 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),523 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),524 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),525 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),526 ("https://", "socks5://http.proxy", mixed_proxies),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 527why, one step back527 # XXX: unsure whether this is reasonable behaviorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 528–530why, one step back528 ("file:///etc/motd", "socks5://http.proxy", all_proxies),529 ),530)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 531–536why, one step back531def test_select_proxies(url, expected, proxies):532 """Make sure we can select per-host proxies correctly."""533 assert select_proxy(url, proxies) == expected534535536@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 537–542why, one step back537 "value, expected",538 (539 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),540 ("key_without_value", {"key_without_value": None}),541 ),542)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 543–547why, one step back543def test_parse_dict_header(value, expected):544 assert parse_dict_header(value) == expected545546547@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 548–550why, one step back548 "value, expected",549 (550 ("application/xml", ("application/xml", {})),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 551why, one step back551 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 552–553why, one step back552 "application/json ; charset=utf-8",553 ("application/json", {"charset": "utf-8"}),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 554–555why, one step back554 ),555 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 556–557why, one step back556 "application/json ; Charset=utf-8",557 ("application/json", {"charset": "utf-8"}),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 558why, one step back558 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 559why, one step back559 ("text/plain", ("text/plain", {})),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 560why, one step back560 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 561–569why, one step back561 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",562 (563 "multipart/form-data",564 {565 "boundary": "something",566 "boundary2": "something_else",567 "no_equals": True,568 },569 ),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 570–571why, one step back570 ),571 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 572–580why, one step back572 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',573 (574 "multipart/form-data",575 {576 "boundary": "something",577 "boundary2": "something_else",578 "no_equals": True,579 },580 ),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 581–582why, one step back581 ),582 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 583–591why, one step back583 "multipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals ",584 (585 "multipart/form-data",586 {587 "boundary": "something",588 "boundary2": "something_else",589 "no_equals": True,590 },591 ),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 592–594why, one step back592 ),593 (594 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 595–602why, one step back595 (596 "multipart/form-data",597 {598 "boundary": "something",599 "boundary2": "something_else",600 "no_equals": True,601 },602 ),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 603why, one step back603 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 604–606why, one step back604 ("application/json ; ; ", ("application/json", {})),605 ),606)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 607–611why, one step back607def test__parse_content_type_header(value, expected):608 assert _parse_content_type_header(value) == expected609610611@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 612–614why, one step back612 "value, expected",613 (614 (CaseInsensitiveDict(), None),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 615why, one step back615 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 616–617why, one step back616 CaseInsensitiveDict({"content-type": "application/json; charset=utf-8"}),617 "utf-8",Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 618why, one step back618 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 619–621why, one step back619 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),620 ),621)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 622–626why, one step back622def test_get_encoding_from_headers(value, expected):623 assert get_encoding_from_headers(value) == expected624625626@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 627–636why, one step back627 "value, length",628 (629 ("", 0),630 ("T", 1),631 ("Test", 4),632 ("Cont", 0),633 ("Other", -5),634 ("Content", None),635 ),636)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 637–645why, one step back637def test_iter_slices(value, length):638 if length is None or (length <= 0 and len(value) > 0):639 # Reads all content at once640 assert len(list(iter_slices(value, length))) == 1641 else:642 assert len(list(iter_slices(value, 1))) == length643644645@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 646–647why, one step back646 "value, expected",647 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 648–649why, one step back648 (649 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 650why, one step back650 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 651why, one step back651 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 652–653why, one step back652 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),653 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 654–656why, one step back654 (655 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',656 [Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 657–659why, one step back657 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},658 {"url": "http://.../back.jpeg"},659 ],Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 660why, one step back660 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 661–663why, one step back661 ("", []),662 ),663)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 664–668why, one step back664def test_parse_header_links(value, expected):665 assert parse_header_links(value) == expected666667668@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 669–673why, one step back669 "value, expected",670 (671 ("example.com/path", "http://example.com/path"),672 ("//example.com/path", "http://example.com/path"),673 ("example.com:80", "http://example.com:80"),Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 674why, one step back674 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 675–676why, one step back675 "http://user:pass@example.com/path?query",676 "http://user:pass@example.com/path?query",Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 677why, one step back677 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 678–680why, one step back678 ("http://user@example.com/path?query", "http://user@example.com/path?query"),679 ),680)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 681why, one step back681def test_prepend_scheme_if_needed(value, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 682why, one step back682 assert prepend_scheme_if_needed(value, "http") == expectedUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 683–685why, one step back683684685@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 686–692why, one step back686 "value, expected",687 (688 ("T", "T"),689 (b"T", "T"),690 ("T", "T"),691 ),692)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 693–697why, one step back693def test_to_native_string(value, expected):694 assert to_native_string(value) == expected695696697@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 698–707why, one step back698 "url, expected",699 (700 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),701 ("http://example.com/path", "http://example.com/path"),702 ("//u:p@example.com/path", "//example.com/path"),703 ("//example.com/path", "//example.com/path"),704 ("example.com/path", "//example.com/path"),705 ("scheme:u:p@example.com/path", "scheme://example.com/path"),706 ),707)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 708–712why, one step back708def test_urldefragauth(url, expected):709 assert urldefragauth(url) == expected710711712@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 713–726why, one step back713 "url, expected",714 (715 ("http://192.168.0.1:5000/", True),716 ("http://192.168.0.1/", True),717 ("http://172.16.1.1/", True),718 ("http://172.16.1.1:5000/", True),719 ("http://localhost.localdomain:5000/v1.0/", True),720 ("http://google.com:6000/", True),721 ("http://172.16.1.12/", False),722 ("http://172.16.1.12:5000/", False),723 ("http://google.com:5000/v1.0/", False),724 ("file:///some/path/on/disk", True),725 ),726)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 727–730why, one step back727def test_should_bypass_proxies(url, expected, monkeypatch):728 """Tests for function should_bypass_proxies to check if proxy729 can be bypassed or not730 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 731–738why, one step back731 monkeypatch.setenv(732 "no_proxy",733 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",734 )735 monkeypatch.setenv(736 "NO_PROXY",737 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",738 )Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 739–742why, one step back739 assert should_bypass_proxies(url, no_proxy=None) == expected740741742@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 743–754why, one step back743 "url, expected",744 (745 ("http://172.16.1.1/", "172.16.1.1"),746 ("http://172.16.1.1:5000/", "172.16.1.1"),747 ("http://user:pass@172.16.1.1", "172.16.1.1"),748 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),749 ("http://hostname/", "hostname"),750 ("http://hostname:5000/", "hostname"),751 ("http://user:pass@hostname", "hostname"),752 ("http://user:pass@hostname:5000", "hostname"),753 ),754)Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 755why, one step back755def test_should_bypass_proxies_pass_only_hostname(url, expected):Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 756–758why, one step back756 """The proxy_bypass function should be called with a hostname or IP without757 a port number or auth credentials.758 """Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 759–761why, one step back759 with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:760 should_bypass_proxies(url, no_proxy=None)761 proxy_bypass.assert_called_once_with(expected)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 762–764why, one step back762763764@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 765–766why, one step back765 "cookiejar",766 (Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 767why, one step back767 compat.cookielib.CookieJar(),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 768–770why, one step back768 RequestsCookieJar(),769 ),770)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 771–774why, one step back771def test_add_dict_to_cookiejar(cookiejar):772 """Ensure add_dict_to_cookiejar works for773 non-RequestsCookieJar CookieJars774 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 775why, one step back775 cookiedict = {"test": "cookies", "good": "cookies"}Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 776–781why, one step back776 cj = add_dict_to_cookiejar(cookiejar, cookiedict)777 cookies = {cookie.name: cookie.value for cookie in cj}778 assert cookiedict == cookies779780781@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 782–787why, one step back782 "value, expected",783 (784 ("test", True),785 ("æíöû", False),786 ("ジェーピーニック", False),787 ),Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 788–793why, one step back788)789def test_unicode_is_ascii(value, expected):790 assert unicode_is_ascii(value) is expected791792793@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 794–806why, one step back794 "url, expected",795 (796 ("http://192.168.0.1:5000/", True),797 ("http://192.168.0.1/", True),798 ("http://172.16.1.1/", True),799 ("http://172.16.1.1:5000/", True),800 ("http://localhost.localdomain:5000/v1.0/", True),801 ("http://172.16.1.12/", False),802 ("http://172.16.1.12:5000/", False),803 ("http://google.com:5000/v1.0/", False),804 ),805)806def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 807–809why, one step back807 """Tests for function should_bypass_proxies to check if proxy808 can be bypassed or not using the 'no_proxy' argument809 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 810why, one step back810 no_proxy = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 811–814why, one step back811 # Test 'no_proxy' argument812 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected813814Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 815why, one step back815@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 816why, one step back816@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 817–831why, one step back817 "url, expected, override",818 (819 ("http://192.168.0.1:5000/", True, None),820 ("http://192.168.0.1/", True, None),821 ("http://172.16.1.1/", True, None),822 ("http://172.16.1.1:5000/", True, None),823 ("http://localhost.localdomain:5000/v1.0/", True, None),824 ("http://172.16.1.22/", False, None),825 ("http://172.16.1.22:5000/", False, None),826 ("http://google.com:5000/v1.0/", False, None),827 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),828 ("http://192.168.0.1/", False, ""),829 ),830)831def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 832–835why, one step back832 """Tests for function should_bypass_proxies to check if proxy833 can be bypassed or not with Windows registry settings834 """835 if override is None:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 836why, one step back836 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583
line 837why, one step back837 import winregUpdate number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 838–850why, one step back838839 class RegHandle:840 def Close(self):841 pass842843 ie_settings = RegHandle()844 proxyEnableValues = deque([1, "1"])845846 def OpenKey(key, subkey):847 return ie_settings848849 def QueryValueEx(key, value_name):850 if key is ie_settings:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 851why, one step back851 if value_name == "ProxyEnable":Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 852–854why, one step back852 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)853 proxyEnableValues.rotate()854 return [proxyEnableValues[0]]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 855why, one step back855 elif value_name == "ProxyOverride":Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 856–857why, one step back856 return [override]857Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 858–864why, one step back858 monkeypatch.setenv("http_proxy", "")859 monkeypatch.setenv("https_proxy", "")860 monkeypatch.setenv("ftp_proxy", "")861 monkeypatch.setenv("no_proxy", "")862 monkeypatch.setenv("NO_PROXY", "")863 monkeypatch.setattr(winreg, "OpenKey", OpenKey)864 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 865–867why, one step back865 assert should_bypass_proxies(url, None) == expected866867Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f
lines 868–900why, one step back868@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")869def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):870 """Tests for function should_bypass_proxies to check if proxy871 can be bypassed or not with Windows invalid registry settings.872 """873 import winreg874875 class RegHandle:876 def Close(self):877 pass878879 ie_settings = RegHandle()880881 def OpenKey(key, subkey):882 return ie_settings883884 def QueryValueEx(key, value_name):885 if key is ie_settings:886 if value_name == "ProxyEnable":887 # Invalid response; Should be an int or int-y value888 return [""]889 elif value_name == "ProxyOverride":890 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]891892 monkeypatch.setenv("http_proxy", "")893 monkeypatch.setenv("https_proxy", "")894 monkeypatch.setenv("no_proxy", "")895 monkeypatch.setenv("NO_PROXY", "")896 monkeypatch.setattr(winreg, "OpenKey", OpenKey)897 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)898 assert should_bypass_proxies("http://172.16.1.1/", None) is False899900Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 901why, one step back901@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 902–909why, one step back902 "env_name, value",903 (904 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),905 ("no_proxy", None),906 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),907 ("a_new_key", None),908 ),909)Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
lines 910–922why, one step back910def test_set_environ(env_name, value):911 """Tests set_environ will set environ values and will restore the environ."""912 environ_copy = copy.deepcopy(os.environ)913 with set_environ(env_name, value):914 assert os.environ.get(env_name) == value915916 assert os.environ == environ_copy917918919def test_set_environ_raises_exception():920 """Tests set_environ will raise exceptions in context when the921 value parameter is None."""922 with pytest.raises(Exception) as exception:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 923–924why, one step back923 with set_environ("test1", None):924 raise Exception("Expected exception")Update number of dependents on requests (#5495)Bharat Raghunathanbefore adoption737dd0c
line 925why, one step back925Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 926why, one step back926 assert "Expected exception" in str(exception.value)