Skip to content

[patch] Run Doctest #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2024
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
21 changes: 11 additions & 10 deletions pyiron_snippets/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@ class Deprecator:
If message and version are not initialized or given during the decorating
call the respective parts are left out from the message.

>>> from pyiron_snippets.deprecate import Deprecator
>>>
>>> deprecate = Deprecator()
>>> @deprecate
... def foo(a, b):
... pass
>>> foo(1, 2)
>>> foo(1, 2) # doctest: +SKIP
DeprecationWarning: __main__.foo is deprecated

>>> @deprecate("use bar() instead")
... def foo(a, b):
... pass
>>> foo(1, 2)
>>> foo(1, 2) # doctest: +SKIP
DeprecationWarning: __main__.foo is deprecated: use bar instead

>>> @deprecate("use bar() instead", version="0.4.0")
... def foo(a, b):
... pass
>>> foo(1, 2)
DeprecationWarning: __main__.foo is deprecated: use bar instead. It is not
guaranteed to be in service in vers. 0.4.0
>>> foo(1, 2) # doctest: +SKIP
DeprecationWarning: __main__.foo is deprecated: use bar instead. It is not guaranteed to be in service in vers. 0.4.0

>>> deprecate = Deprecator(message="I say no!", version="0.5.0")
>>> @deprecate
... def foo(a, b):
... pass
>>> foo(1, 2)
DeprecationWarning: __main__.foo is deprecated: I say no! It is not
guaranteed to be in service in vers. 0.5.0
>>> foo(1, 2) # doctest: +SKIP
DeprecationWarning: __main__.foo is deprecated: I say no! It is not guaranteed to be in service in vers. 0.5.0`

Alternatively the decorator can also be called with `arguments` set to a dictionary
mapping names of keyword arguments to deprecation messages. In this case the
Expand All @@ -62,7 +62,7 @@ class Deprecator:
... def foo(bar=None, baz=None):
... pass
>>> foo(baz=True)
>>> foo(bar=True)
>>> foo(bar=True) # doctest: +SKIP
DeprecationWarning: __main__.foo(bar=True) is deprecated: use baz instead.

As a short-cut, it is also possible to pass the values in the arguments dict
Expand All @@ -72,8 +72,9 @@ class Deprecator:
... def foo(bar=None, baz=None):
... pass
>>> foo(baz=True)
>>> foo(bar=True)
>>> foo(bar=True) # doctest: +SKIP
DeprecationWarning: __main__.foo(bar=True) is deprecated: use baz instead.

"""

def __init__(self, message=None, version=None, pending=False):
Expand Down
6 changes: 3 additions & 3 deletions pyiron_snippets/import_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class ImportAlarm:
>>> try:
... from mystery_package import Enigma, Puzzle, Conundrum
... import_alarm = ImportAlarm()
>>> except ImportError:
>>> import_alarm = ImportAlarm(
... except ImportError:
... import_alarm = ImportAlarm(
... "MysteryJob relies on mystery_package, but this was unavailable. Please ensure your python environment "
... "has access to mystery_package, e.g. with `conda install -c conda-forge mystery_package`"
... )
...
>>> class MysteryJob:
... @import_alarm
... def __init__(self, project, job_name)
... def __init__(self, project, job_name):
... super().__init__()
... self.riddles = [Enigma(), Puzzle(), Conundrum()]

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import doctest
import pkgutil
import unittest

import pyiron_snippets


def load_tests(loader, tests, ignore):
for importer, name, ispkg in pkgutil.walk_packages(
pyiron_snippets.__path__, pyiron_snippets.__name__ + '.'
):
tests.addTests(doctest.DocTestSuite(name))
return tests


class TestTriggerFromIDE(unittest.TestCase):
"""
Just so we can instruct it to run unit tests here with a gui run command on the file
"""

def test_void(self):
pass


if __name__ == '__main__':
unittest.main()
Loading