Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- name: Checkout
uses: actions/checkout@v7
Expand Down
14 changes: 10 additions & 4 deletions connect/client/help_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# Copyright (c) 2025 CloudBlue. All Rights Reserved.
#
import inflect
from connect.utils.terminal.markdown import render

from connect.client.models import (
Expand All @@ -29,7 +28,7 @@
class DefaultFormatter:
def __init__(self, specs):
self._specs = specs
self._p = inflect.engine()
self._p = None

def format_client(self):
lines = [
Expand Down Expand Up @@ -101,13 +100,20 @@ def format_collection(self, collection):

return render('\n'.join(lines))

def _singular(self, noun):
if self._p is None:
# inflect takes most of a second to import, so only the help of a resource loads it.
import inflect

self._p = inflect.engine()
return self._p.singular_noun(noun)

def format_resource(self, resource):
res_info = self._specs.get_resource(resource.path)
if not res_info:
return render(f'~~{resource.path}~~ **does not exists.**')

resource_name = resource.path.split('/')[-2]
resource_name = self._p.singular_noun(resource_name)
resource_name = self._singular(resource.path.split('/')[-2])
lines = [
f'# {resource_name.title()} resource',
f'**path: /{resource.path}**',
Expand Down
6 changes: 6 additions & 0 deletions connect/client/models/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_item(self, item):


class AbstractIterator(AbstractBaseIterator):
def __iter__(self):
return self

def _load(self):
if not self._loaded:
self._rs._results, self._rs._content_range = self._execute_request()
Expand Down Expand Up @@ -83,6 +86,9 @@ def _execute_request(self):


class AbstractAsyncIterator(AbstractBaseIterator):
def __aiter__(self):
return self

async def _load(self):
if not self._loaded:
self._rs._results, self._rs._content_range = await self._execute_request()
Expand Down
51 changes: 18 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Utilities",
"Topic :: Software Development :: Libraries",
]
Expand Down Expand Up @@ -52,10 +54,9 @@ pytest-mock = "^3.10"
coverage = {extras = ["toml"], version = ">=5.3,<7"}
flake8 = ">=6"
flake8-black = "0.*"
flake8-bugbear = ">=20,<23"
flake8-bugbear = ">=24"
flake8-cognitive-complexity = "^0.1"
flake8-commas = "~4"
flake8-future-import = "~0.4"
flake8-import-order = ">=0.18.2"
flake8-isort = "^6.0"
flake8-broken-line = ">=1.0"
Expand Down
14 changes: 14 additions & 0 deletions tests/client/test_help_formatter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import subprocess
import sys

import pytest

from connect.client.help_formatter import DefaultFormatter
Expand Down Expand Up @@ -107,3 +110,14 @@ def test_format_rs(openapi_specs, rs_factory):
rs = rs_factory(path='does-not-exists')
formatted = formatter.format(rs)
assert 'does not exist' in formatted


def test_importing_the_client_does_not_import_inflect():
result = subprocess.run(
[sys.executable, '-c', 'import sys, connect.client; print("inflect" in sys.modules)'],
capture_output=True,
text=True,
check=True,
)

assert result.stdout.strip() == 'False'
35 changes: 21 additions & 14 deletions tests/client/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ def test_create():
client = ConnectClient('api_key', endpoint='http://localhost')
assert client.products.create(data=b'binary content') == {'test': 'data'}

with pytest.raises(ClientError):
with ConnectClientMocker('http://localhost') as mocker:
mocker.products.create(return_value={'test': 'data'}, match_body=b'another content')
client = ConnectClient('api_key', endpoint='http://localhost')
assert client.products.create(data=b'binary content') == {'test': 'data'}
mocker = ConnectClientMocker('http://localhost')
mocker.start()
try:
mocker.products.create(return_value={'test': 'data'}, match_body=b'another content')
products = ConnectClient('api_key', endpoint='http://localhost').products
with pytest.raises(ClientError):
products.create(data=b'binary content')
finally:
# The mocked request is meant not to match, so don't check that it was used.
mocker.reset(success=False)

with ConnectClientMocker('http://localhost') as mocker:
mocker('my_namespace').products.create(return_value={'test': 'data'})
Expand Down Expand Up @@ -350,21 +355,23 @@ def test_count_error():
with ConnectClientMocker('http://localhost') as mocker:
mocker.products.all().count(status_code=500)

client = ConnectClient('api_key', endpoint='http://localhost')
products = ConnectClient('api_key', endpoint='http://localhost').products.all()
with pytest.raises(ClientError) as cv:
client.products.all().count()
products.count()

assert cv.value.status_code == 500


def test_invalid_return_value():
with pytest.raises(TypeError):
with ConnectClientMocker('http://localhost') as mocker:
mocker.products.all().mock(return_value='hello')
with ConnectClientMocker('http://localhost') as mocker:
products = mocker.products.all()
with pytest.raises(TypeError):
products.mock(return_value='hello')

with pytest.raises(TypeError):
with ConnectClientMocker('http://localhost') as mocker:
mocker.products.all().count(return_value='hello')
with ConnectClientMocker('http://localhost') as mocker:
products = mocker.products.all()
with pytest.raises(TypeError):
products.count(return_value='hello')


def test_inner_mockers():
Expand Down Expand Up @@ -411,6 +418,6 @@ def test_mocker_reset(mocker):
)
mocked_reset = mocker.patch('connect.client.testing.fluent._mocker.reset')
mocker = ConnectClientMocker('http://localhost')
with pytest.raises(Exception):
with pytest.raises(Exception, match='error'):
mocker.reset()
mocked_reset.assert_called_once()
Loading