From: Florimond Manca Date: Thu, 12 Sep 2019 21:24:33 +0000 (+0200) Subject: Test Requests entrypoints (#330) X-Git-Tag: 0.7.3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1dde95d358a5a707d75e6d61f912224ed65ee8e;p=thirdparty%2Fhttpx.git Test Requests entrypoints (#330) * Test Requests entrypoints * Show summary of unsuccessful tests --- diff --git a/setup.cfg b/setup.cfg index 88442bc8..4a647525 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,4 +16,6 @@ line_length = 88 multi_line_output = 3 [tool:pytest] -addopts = --cov=httpx --cov=tests --cov-report=term-missing +addopts = --cov=httpx --cov=tests --cov-report=term-missing -rxXs +markers = + copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accodomate e.g. our test setup diff --git a/tests/requests_compat/__init__.py b/tests/requests_compat/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/requests_compat/conftest.py b/tests/requests_compat/conftest.py new file mode 100644 index 00000000..18fade73 --- /dev/null +++ b/tests/requests_compat/conftest.py @@ -0,0 +1,17 @@ +import sys + +import pytest + +import httpx + + +def pytest_configure(config): + # Allow to 'import requests' without having to write 'import httpx as requests'. + # This means we *could* literally copy-paste Requests test code as-is, if relevant. + sys.modules["requests"] = httpx + + +@pytest.fixture(autouse=True) +def patch_httpx(monkeypatch): + """Monkey-patch Requests APIs onto HTTPX.""" + monkeypatch.setattr(httpx, "session", httpx.Client, raising=False) diff --git a/tests/requests_compat/test_api.py b/tests/requests_compat/test_api.py new file mode 100644 index 00000000..0aff992f --- /dev/null +++ b/tests/requests_compat/test_api.py @@ -0,0 +1,30 @@ +"""Test compatibility with the Requests high-level API.""" +import pytest + +import requests + + +@pytest.mark.copied_from( + "https://github.com/psf/requests/blob/v2.22.0/tests/test_requests.py#L61-L70" +) +def test_entrypoints(): + requests.session + requests.session().get + requests.session().head + requests.get + requests.head + requests.put + requests.patch + requests.post + + +@pytest.mark.copied_from( + "https://github.com/psf/requests/blob/v2.22.0/tests/test_requests.py#L72", + changes=["added noqa comment to silence flake8"], +) +@pytest.mark.xfail( + reason="PoolManager has no obvious equivalent in HTTPX", raises=ImportError +) +def test_poolmanager_entrypoint(): + # Not really an entry point, but people rely on it. + from requests.packages.urllib3.poolmanager import PoolManager # noqa: F401