Skip to content

Commit

Permalink
Merge pull request #7 from adamboche/doctest
Browse files Browse the repository at this point in the history
Use doctest
  • Loading branch information
adamboche committed Jun 8, 2019
2 parents 0326c34 + 5d7d630 commit f501b3b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions dev-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ readme-renderer
pygments
isort
mypy
pytest-sphinx
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ py==1.8.0 # via pytest, tox
pygments==2.4.2
pylint==2.3.1
pyparsing==2.4.0 # via packaging
pytest-sphinx==0.2.2
pytest==4.6.2
pyyaml==5.1.1 # via watchdog
readme-renderer==24.0
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@
napoleon_use_param = True

autoapi_dirs = ["../src/marshmallow_union"]

43 changes: 27 additions & 16 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@
Usage
=====

To use marshmallow-union in a project::
To use marshmallow-union in a project

import marshmallow_union
.. testcode::

import marshmallow
import marshmallow_union

class PersonSchema(marshmallow.Schema):
name = marshmallow.fields.String()
number_or_numbers = marshmallow_union.Union(
[
marshmallow.fields.List(marshmallow.fields.Integer()),
marshmallow.fields.Integer(),
],
reverse_serialize_candidates=True,
)

class PersonSchema(marshmallow.Schema):
name = marshmallow.fields.String()
number_or_numbers = marshmallow_union.Union(
[
marshmallow.fields.List(marshmallow.fields.Integer()),
marshmallow.fields.Integer(),
],
reverse_serialize_candidates=True,
)

data = {"name": "Alice", "number_or_numbers": 25}
schema = PersonSchema()
loaded = schema.load(data)
dumped = schema.dump(data)


input_data = {"name": "Alice", "number_or_numbers": 25}
schema = PersonSchema()

loaded = schema.load(input_data)
dumped = schema.dump(loaded)

assert dumped == input_data




.. testoutput::
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ deps =
-r{toxinidir}/docs/requirements.txt
commands =
sphinx-apidoc -o docs/reference -f src
sphinx-build {posargs:-E} -b doctest docs dist/docs
sphinx-build {posargs:-E} -b html docs dist/docs
sphinx-build -b linkcheck docs dist/docs

Expand Down

0 comments on commit f501b3b

Please sign in to comment.