from __future__ import absolute_import
from casatasks import casalog
def skipUnlessHasParam(param):
def _wrapper(*args, **kwargs):
task_args = inspect.getargs(task.__call__.__code__).args
if isinstance(param, str):
condition = param in task_args
reason = '%s doesn\'t have parameter \'%s\''%(str(task), param)
condition = all([p in task_args for p in param])
reason = '%s doesn\'t have parameter %s'%(task.__name__, map(lambda x: '\'' + str(x) + '\'', param))
return unittest.skipUnless(condition, reason)(func)(*args, **kwargs)
def skipIfNoChannelSelection(func):
def wrapper(*args, **kwargs):
condition = args[0].spw_channel_selection
reason = '%s doens\'nt accept channel selection on parameter spw'%(task.__name__)
return unittest.skipUnless(condition, reason)(func)(*args, **kwargs)
class SelectionSyntaxTest(unittest.TestCase):
Base class for data selection syntax unit test.
All the tests are defined in this class but all fail by
default. Subclasses must override necessary tests.
Unnecessary tests will be automatically skipped.
In the test implementation, it is recommended to use
run_task method instead of running task directly. It
will check whether the test is properly implemented in
__metaclass__ = abc.ABCMeta
task is an abstract attribute that must be defined
at each subclass. It must point task as a function