Skip to content

Commit

Permalink
Merge pull request #134 from ross/pyproject-toml
Browse files Browse the repository at this point in the history
pytest mark network, pyproject.toml, isort
  • Loading branch information
ross committed Jun 19, 2023
2 parents ddd4f9b + 36f4313 commit dee08fd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.black]
line-length=80
skip-string-normalization=true
skip-magic-trailing-comma=true

[tool.isort]
profile = "black"
known_first_party="requests_futures"
line_length=80

[tool.pytest.ini_options]
markers = [
"network: tests that require network connectivity to pass"
]
pythonpath = "."
4 changes: 2 additions & 2 deletions requests_futures/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
print(response.content)
"""
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from functools import partial
from logging import getLogger
from pickle import dumps, PickleError
from pickle import PickleError, dumps

from requests import Session
from requests.adapters import DEFAULT_POOLSIZE, HTTPAdapter
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ coverage==7.2.7
docutils==0.20.1
importlib-metadata==6.7.0
iniconfig==2.0.0
isort==5.12.0
jaraco.classes==3.2.3
keyring==23.13.1
markdown-it-py==3.0.0
Expand Down
3 changes: 2 additions & 1 deletion script/format
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ SOURCES=$(find *.py requests_futures tests -name "*.py")

. env/bin/activate

black --line-length=80 --skip-string-normalization --skip-magic-trailing-comma "$@" $SOURCES
isort "$@" $SOURCES
black "$@" $SOURCES
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
+ (
'black>=22.3.0',
'build>=0.7.0',
'isort>=5.11.4',
'pyflakes>=2.2.0',
'readme_renderer[rst]>=26.0',
'twine>=3.4.2',
Expand Down
14 changes: 13 additions & 1 deletion tests/test_requests_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
from sys import pypy_version_info
except ImportError:
pypy_version_info = None
from unittest import TestCase, main, skipIf
import logging
from unittest import TestCase, main, skipIf

import pytest
from requests import Response, session
from requests.adapters import DEFAULT_POOLSIZE

from requests_futures.sessions import FuturesSession

HTTPBIN = environ.get('HTTPBIN_URL', 'https://nghttp2.org/httpbin/')
Expand All @@ -30,6 +32,7 @@ def httpbin(*suffix):


class RequestsTestCase(TestCase):
@pytest.mark.network
def test_futures_session(self):
# basic futures get
sess = FuturesSession()
Expand Down Expand Up @@ -65,6 +68,7 @@ def rasing_cb(s, r):
resp = future.result()
self.assertEqual('boom', cm.exception.args[0])

@pytest.mark.network
def test_supplied_session(self):
"""Tests the `session` keyword argument."""
requests_session = session()
Expand Down Expand Up @@ -112,6 +116,7 @@ def test_adapter_kwargs(self):
)
self.assertEqual(session.get_adapter('http://')._pool_connections, 20)

@pytest.mark.network
def test_redirect(self):
"""Tests for the ability to cleanly handle redirects."""
sess = FuturesSession()
Expand All @@ -125,6 +130,7 @@ def test_redirect(self):
resp = future.result()
self.assertEqual(404, resp.status_code)

@pytest.mark.network
def test_context(self):
class FuturesSessionTestHelper(FuturesSession):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -181,15 +187,18 @@ def setUp(self):
self.proc_executor = ProcessPoolExecutor(max_workers=2)
self.session = session()

@pytest.mark.network
@skipIf(session_required, 'not supported in python < 3.5')
def test_futures_session(self):
self._assert_futures_session()

@pytest.mark.network
@skipIf(not session_required, 'fully supported on python >= 3.5')
def test_exception_raised(self):
with self.assertRaises(RuntimeError):
self._assert_futures_session()

@pytest.mark.network
def test_futures_existing_session(self):
self.session.headers['Foo'] = 'bar'
self._assert_futures_session(session=self.session)
Expand Down Expand Up @@ -247,10 +256,12 @@ def _assert_futures_session(self, session=None):
resp = future.result()
self.assertEqual(404, resp.status_code)

@pytest.mark.network
@skipIf(session_required, 'not supported in python < 3.5')
def test_context(self):
self._assert_context()

@pytest.mark.network
def test_context_with_session(self):
self._assert_context(session=self.session)

Expand Down Expand Up @@ -285,6 +296,7 @@ def __exit__(self, *args, **kwargs):

@skipIf(not unsupported_platform, 'Exception raised when unsupported')
class ProcessPoolExceptionRaisedTestCase(TestCase):
@pytest.mark.network
def test_exception_raised(self):
executor = ProcessPoolExecutor(max_workers=2)
sess = FuturesSession(executor=executor, session=session())
Expand Down

0 comments on commit dee08fd

Please sign in to comment.