]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Test Requests entrypoints (#330)
authorFlorimond Manca <florimond.manca@gmail.com>
Thu, 12 Sep 2019 21:24:33 +0000 (23:24 +0200)
committerGitHub <noreply@github.com>
Thu, 12 Sep 2019 21:24:33 +0000 (23:24 +0200)
* Test Requests entrypoints

* Show summary of unsuccessful tests

setup.cfg
tests/requests_compat/__init__.py [new file with mode: 0644]
tests/requests_compat/conftest.py [new file with mode: 0644]
tests/requests_compat/test_api.py [new file with mode: 0644]

index 88442bc80cb6c915d38da88d8ffabfff7e0d4956..4a6475250c0c883a02b421e1e88385a89e61133e 100644 (file)
--- 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 (file)
index 0000000..e69de29
diff --git a/tests/requests_compat/conftest.py b/tests/requests_compat/conftest.py
new file mode 100644 (file)
index 0000000..18fade7
--- /dev/null
@@ -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 (file)
index 0000000..0aff992
--- /dev/null
@@ -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