Skip to content

Commit

Permalink
Fixed deleting non-existing environment variables.
Browse files Browse the repository at this point in the history
Added simple tests for these.
  • Loading branch information
mauritsvanrees committed Mar 6, 2020
1 parent 5cbe07e commit e040f7c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/z3c/autoinclude/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def disable_dependencies():


def enable_dependencies():
del os.environ[DEP_KEY]
os.environ.pop(DEP_KEY, None)


def plugins_disabled():
Expand All @@ -26,15 +26,15 @@ def disable_plugins():


def enable_plugins():
del os.environ[PLUGIN_KEY]
os.environ.pop(PLUGIN_KEY, None)


def debug_enabled():
return DEBUG_KEY in os.environ


def disable_debug():
del os.environ[DEBUG_KEY]
os.environ.pop(DEBUG_KEY, None)


def enable_debug():
Expand Down
71 changes: 71 additions & 0 deletions src/z3c/autoinclude/api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
=============
API functions
=============

The ``api.py`` module has some helpful functions.


Plugins
=======

We can disable and enable autoincluding the plugins::

>>> from z3c.autoinclude import api
>>> api.plugins_disabled()
False
>>> api.disable_plugins()
>>> api.plugins_disabled()
True
>>> api.disable_plugins() # called twice to see if this breaks
>>> api.plugins_disabled()
True
>>> api.enable_plugins()
>>> api.plugins_disabled()
False
>>> api.enable_plugins() # called twice to see if this breaks
>>> api.plugins_disabled()
False


Dependencies
============

We can disable and enable autoincluding the dependencies::

>>> from z3c.autoinclude import api
>>> api.dependencies_disabled()
False
>>> api.disable_dependencies()
>>> api.dependencies_disabled()
True
>>> api.disable_dependencies() # called twice to see if this breaks
>>> api.dependencies_disabled()
True
>>> api.enable_dependencies()
>>> api.dependencies_disabled()
False
>>> api.enable_dependencies() # called twice to see if this breaks
>>> api.dependencies_disabled()
False


Debug
=====

We can disable and enable the debug report of autoincluded packages::

>>> from z3c.autoinclude import api
>>> api.debug_enabled()
False
>>> api.enable_debug()
>>> api.debug_enabled()
True
>>> api.enable_debug() # called twice to see if this breaks
>>> api.debug_enabled()
True
>>> api.disable_debug()
>>> api.debug_enabled()
False
>>> api.disable_debug() # called twice to see if this breaks
>>> api.debug_enabled()
False
11 changes: 9 additions & 2 deletions src/z3c/autoinclude/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ def test_suite():

from pprint import pprint

suite = doctest.DocFileSuite(
simple_suite = doctest.DocFileSuite(
'../api.txt',
globs={'pprint': pprint},
checker=IgnoreCaseChecker(),
optionflags=doctest.ELLIPSIS,
)

advanced_suite = doctest.DocFileSuite(
'../utils.txt',
'../dependency.txt',
'../plugin.txt',
Expand All @@ -129,7 +136,7 @@ def test_suite():
optionflags=doctest.ELLIPSIS,
)

return unittest.TestSuite((suite,))
return unittest.TestSuite((simple_suite, advanced_suite))


if __name__ == '__main__':
Expand Down

0 comments on commit e040f7c

Please sign in to comment.