Skip to content

Commit

Permalink
✔️ Add tests for the broken environment case (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret authored Apr 22, 2024
1 parent ba8f622 commit 57e6c29
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Release History
===============

3.6.1 (2024-04-21)
3.6.1 (2024-04-22)
------------------

**Fixed**
Expand Down
9 changes: 7 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def tests_impl(
session: nox.Session,
extras: str = "socks",
cohabitation: bool = False,
cohabitation: bool | None = False,
) -> None:
# Install deps and the package itself.
session.install("-r", "requirements-dev.txt")
Expand All @@ -19,9 +19,13 @@ def tests_impl(
session.run("pip", "--version")
session.run("python", "--version")

if cohabitation:
if cohabitation is True:
session.run("pip", "install", "urllib3")
session.run("python", "-m", "niquests.help")
elif cohabitation is None:
session.run("pip", "install", "urllib3")
session.run("pip", "uninstall", "-y", "urllib3")
session.run("python", "-m", "niquests.help")

session.run(
"python",
Expand Down Expand Up @@ -55,6 +59,7 @@ def test(session: nox.Session) -> None:
)
def test_cohabitation(session: nox.Session) -> None:
tests_impl(session, cohabitation=True)
tests_impl(session, cohabitation=None)


@nox.session
Expand Down
7 changes: 6 additions & 1 deletion src/niquests/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

try:
import urllib3
except ImportError:

# force detect broken or dummy urllib3 package
urllib3.Timeout # noqa
urllib3.Retry # noqa
urllib3.__version__ # noqa
except (ImportError, AttributeError):
urllib3 = None # type: ignore[assignment]


Expand Down
6 changes: 5 additions & 1 deletion src/niquests/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

if HAS_LEGACY_URLLIB3 is True:
import urllib3_future as urllib3
from urllib3 import __version__ as __legacy_urllib3_version__

try:
from urllib3 import __version__ as __legacy_urllib3_version__
except (ImportError, AttributeError):
__legacy_urllib3_version__ = None # type: ignore[assignment]
else:
import urllib3 # type: ignore[no-redef]

Expand Down
7 changes: 6 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,12 @@ def test_prepared_copy(kwargs):


def test_urllib3_retries(httpbin):
from urllib3.util import Retry
from niquests._compat import HAS_LEGACY_URLLIB3

if not HAS_LEGACY_URLLIB3:
from urllib3.util import Retry
else:
from urllib3_future.util import Retry

s = niquests.Session()
s.mount("http://", HTTPAdapter(max_retries=Retry(total=2, status_forcelist=[500])))
Expand Down
7 changes: 6 additions & 1 deletion tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import pytest

from niquests.structures import CaseInsensitiveDict, LookupDict
from urllib3 import HTTPHeaderDict
from niquests._compat import HAS_LEGACY_URLLIB3

if not HAS_LEGACY_URLLIB3:
from urllib3 import HTTPHeaderDict
else:
from urllib3_future import HTTPHeaderDict


class TestCaseInsensitiveDict:
Expand Down

0 comments on commit 57e6c29

Please sign in to comment.