Skip to content

Commit

Permalink
Update tests for marshmallow 4 compat; build updates (#963)
Browse files Browse the repository at this point in the history
* Fix tests for marshmallow 4.0

* pre-commit autoupdate

* Update changelog and badge

* Fix badge

* Update changelog

* Remove unnecessary ignore; use fixed marshmallow version
  • Loading branch information
sloria authored Jan 7, 2025
1 parent 6583194 commit 59751b7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 34 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,14 @@ on:
jobs:
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- {
name: "3.9-ma3",
python: "3.9",
os: ubuntu-latest,
tox: py39-marshmallow3,
}
- {
name: "3.13-ma3",
python: "3.13",
os: ubuntu-latest,
tox: py313-marshmallow3,
}
- {
name: "3.13-madev",
python: "3.13",
os: ubuntu-latest,
tox: py313-marshmallowdev,
}
- { name: "3.9-ma3", python: "3.9", tox: py39-marshmallow3 }
- { name: "3.13-ma3", python: "3.13", tox: py313-marshmallow3 }
- { name: "3.13-madev", python: "3.13", tox: py313-marshmallowdev }
steps:
- uses: actions/checkout@v4.2.2
- uses: actions/setup-python@v5
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.8.6
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -15,9 +15,9 @@ repos:
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies: [black==23.12.1]
additional_dependencies: [black==24.10.0]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies: ["marshmallow>=3,<4", "types-PyYAML"]
additional_dependencies: ["marshmallow>=3.24.1,<5", "types-PyYAML"]
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------

6.9.0 (unreleased)
******************

Support:

- Support marshmallow 4 (:pr:`963`).

6.8.0 (2024-12-02)
******************

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apispec
*******

|pypi| |build-status| |docs| |marshmallow3| |openapi|
|pypi| |build-status| |docs| |marshmallow-support| |openapi|

.. |pypi| image:: https://badgen.net/pypi/v/apispec
:target: https://pypi.org/project/apispec/
Expand All @@ -16,9 +16,9 @@ apispec
:target: https://apispec.readthedocs.io/
:alt: Documentation

.. |marshmallow3| image:: https://badgen.net/badge/marshmallow/3?list=1
.. |marshmallow-support| image:: https://badgen.net/badge/marshmallow/3,4?list=1
:target: https://marshmallow.readthedocs.io/en/latest/upgrading.html
:alt: marshmallow 3 only
:alt: marshmallow 3|4 compatible

.. |openapi| image:: https://badgen.net/badge/OAS/2,3?list=1&color=cyan
:target: https://github.com/OAI/OpenAPI-Specification
Expand Down
2 changes: 1 addition & 1 deletion src/apispec/ext/marshmallow/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def resolve_schema_instance(
return schema()
if isinstance(schema, marshmallow.Schema):
return schema
return marshmallow.class_registry.get_class(schema)() # type: ignore
return marshmallow.class_registry.get_class(schema)()


def resolve_schema_cls(
Expand Down
10 changes: 4 additions & 6 deletions tests/test_ext_marshmallow_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_field2choices_preserving_order(openapi):
("FieldClass", "jsontype"),
[
(fields.Integer, "integer"),
(fields.Number, "number"),
(fields.Float, "number"),
(fields.String, "string"),
(fields.Str, "string"),
Expand All @@ -46,9 +45,8 @@ def test_field2property_type(FieldClass, jsontype, spec_fixture):
assert res["type"] == jsontype


@pytest.mark.parametrize("FieldClass", [fields.Field, fields.Raw])
def test_field2property_no_type_(FieldClass, spec_fixture):
field = FieldClass()
def test_field2property_no_type(spec_fixture):
field = fields.Raw()
res = spec_fixture.openapi.field2property(field)
assert "type" not in res

Expand Down Expand Up @@ -291,14 +289,14 @@ def test_field_with_load_only(spec_fixture):


def test_field_with_range_no_type(spec_fixture):
field = fields.Field(validate=validate.Range(min=1, max=10))
field = fields.Raw(validate=validate.Range(min=1, max=10))
res = spec_fixture.openapi.field2property(field)
assert res["x-minimum"] == 1
assert res["x-maximum"] == 10
assert "type" not in res


@pytest.mark.parametrize("field", (fields.Number, fields.Integer))
@pytest.mark.parametrize("field", (fields.Float, fields.Integer))
def test_field_with_range_string_type(spec_fixture, field):
field = field(validate=validate.Range(min=1, max=10))
res = spec_fixture.openapi.field2property(field)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
envlist=
lint
py{39,310,311,312,313}-marshmallow3
py312-marshmallowdev
py313-marshmallowdev
docs

[testenv]
Expand Down

0 comments on commit 59751b7

Please sign in to comment.