API
drypy
The package provides some basic function to turn on/off the dryrun mode.
drypy - dryrun for python
- drypy.dryrun(state=None)
Return current dryrun mode, If state is provided activate/deactivate dryrun before returning the status
- Optional args:
state (bool): Set dryrun mode to the desired state.
- Returns:
bool
- drypy.get_logging_level()
Return the current logging level used by drypy
- drypy.get_status()
Returns True if the dryrun system is active.
- Returns:
True or False
- drypy.set_dryrun(value)
Set the dryrun mode on or off.
- Args:
value (bool): Mode to be in.
- drypy.set_logging_level(level)
Set the logging level drypy will use by default.
- drypy.toggle_dryrun()
Toggle the current dryrun mode.
patterns.py
This module provide the decorators to mark your own function you want to dryrun.
- drypy.patterns.sentinel(return_value=None)
Decorator which makes drypy to log the call of the target function and returns a user defined value without executing it.
Deprecated since version 1.2.0: Use sham with arguments instead.
- Example 1:
>>> @sentinel(return_value=25) ... def foo(bar, baz=None): ... return 42 ... >>> a = foo("sport", baz=False) >>> print(a) 42 >>> dryrun(True) >>> b = foo("sport", baz=False) INFO:drypy.sentinel:[DRYRUN] call to 'foo(sport, baz=False)' >>> print(b) 25
- Example 2:
>>> @sentinel(return_value="I am Sakshi") ... def sakfoo(bar): ... return "I am sakfoo" ... >>> a = sakfoo("sport") >>> print(a) 'I am sakfoo' >>> dryrun(True) >>> b = sakfoo("sport") INFO:drypy.sentinel:[DRYRUN] call to 'sakfoo(sport)' >>> print(b) 'I am Sakshi'
- drypy.patterns.sham(func=None, log_level=None, return_value=None, custom_msg=None)
Decorator which makes drypy to log the call of the target function without executing it.
- Parameters:
- Example:
>>> @sham ... def foo(bar, baz=None): ... return 42 ... >>> foo("sport", baz=False) 42 >>> foo("sport", baz=False) INFO:drypy.sham:[DRYRUN] call to 'foo(sport, baz=False)'
- Example with args:
>>> @sham(log_level=logging.DEBUG, return_value=21) ... def foo(bar, baz=None): ... return 42 ... >>> foo("sport", baz=False) 42 >>> foo("sport", baz=False) DEBUG:drypy.sham:[DRYRUN] call to 'foo(sport, baz=False)' 21
- Example with custom message:
>>> @sham(custom_msg="This is a custom message") ... def foo(bar, baz=None): ... return 42 ... >>> foo("sport", baz=False) 42 >>> foo("sport", baz=False) INFO:drypy.sham:[DRYRUN] This is a custom message
- drypy.patterns.sheriff(func)
Decorator which makes drypy to run func.deputy instead of func.
- Example:
>>> @sheriff ... def woody(): ... print("I'm the Sheriff!") ... >>> @woody.deputy ... def woody(): ... print("I'm the Deputy!") ... ... >>> woody() I'm the Sheriff! >>> drypy.set_dryrun(True) >>> woody() I'm the Deputy!