Skip to content
Myr

Test coverage for HTTPVersionConfig

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by Tom Christie · parent f72fa68 · Browse files · 2 files+37 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+37 added−4 removed

  • tests:+30 added−0 removed
  • other:+7 added−4 removed

2 files+37 added−4 removed

modified:httpx/config.py+7 added-4 removed
234 unmodified lines
235 if http_versions is None:236 http_versions = ['HTTP/1.1', 'HTTP/2']237238 if isinstance(http_versions, str):239 self.http_versions = set([http_versions])239 self.http_versions = set([http_versions.upper()])240 elif isinstance(http_versions, HTTPVersionConfig):241 self.http_versions = http_versions.http_versions242 else:243 self.http_versions = set(sorted(http_versions))243 self.http_versions = set(sorted([version.upper() for version in http_versions]))244245 for version in self.http_versions:246 if version not in ('HTTP/1.1', 'HTTP/2'):247 raise ValueError(f"Unsupported protocol value {protocol!r}")247 raise ValueError(f"Unsupported HTTP version {version!r}.")248249 if not self.http_versions:250 raise ValueError(f"HTTP versions cannot be an empty list.")251252 @property253 def alpn_strings(self) -> typing.List[str]:254 """255 Returns a list of supported ALPN identifiers. (One or more of "http/1.1", "h2").
2 unmodified lines
258 return [mapping[version] for version in self.http_versions]259260 def __repr__(self) -> str:261 class_name = self.__class__.__name__259 value = list(self.http_versions)262 value = sorted(list(self.http_versions))263 return f"{class_name}({value!r})"264265266class PoolLimits:
36 unmodified lines
modified:tests/test_config.py+30 added
88 unmodified lines
89 ssl = httpx.SSLConfig(verify=False)90 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"919293def test_http_versions_repr():94 http_versions = httpx.HTTPVersionConfig()95 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1', 'HTTP/2'])"969798def test_http_versions_from_string():99 http_versions = httpx.HTTPVersionConfig("HTTP/1.1")100 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"101102103def test_http_versions_from_list():104 http_versions = httpx.HTTPVersionConfig(["http/1.1"])105 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"106107108def test_http_versions_from_config():109 http_versions = httpx.HTTPVersionConfig(httpx.HTTPVersionConfig("HTTP/1.1"))110 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"111112113def test_invalid_http_version():114 with pytest.raises(ValueError):115 httpx.HTTPVersionConfig("HTTP/9")116117118def test_empty_http_version():119 with pytest.raises(ValueError):120 httpx.HTTPVersionConfig([])121122123def test_timeout_repr():124 timeout = httpx.TimeoutConfig(timeout=5.0)125 assert repr(timeout) == "TimeoutConfig(timeout=5.0)"126
37 unmodified lines