Open main menu

Changes

Relax source design

37 bytes added, 13:11, 26 September 2014
→‎The check_*() functions: More changes to the check_*() function design.
== The check_*() functions ==
These functions are for performing checks for certain data being present. The idea uses the [https://en.wikipedia.org/wiki/Strategy_pattern strategy design pattern] which is implemented in the lib.checks.Check class. Therefore these are really function-like objects.
=== Packages ===
* 1 - In addition to returning True or False, the function will throw a RelaxWarning for better user feedback.
* 2 - This will cause a RelaxError to be raised if the data is missing, not set up, etc. Otherwise the function returns True.
 
The default value is 2.
=== Implementation ===
# relax module imports.
from lib.checks import Check
from lib.errors import RelaxError
@keyword b: Some check specific keyword argument.
@type b: int
@return: The status of the check and the message to send to the userinitialised RelaxError object or nothing. @rtype: bool, strNone or RelaxError instance
"""
 
# Init.
check_ok = True
# Check that...
if not something(a, b):
check_ok = False  # Return the status and message. return check_ok, RelaxError("Something is missing.Some text")
# Create the checking object.
a = '600 MHz'
b = 600
check_aaa(a, b=b, escalate=2)
</source>
Note that the lib.checks.Check.__call__() method will take the escalate argument for itself and pass 'a' and 'b' into the 'check_aaa_func' function as arguments. The escalate argument defaults to 2.
Trusted, Bureaucrats
4,223

edits