This decorator is an specialization of :function::taurus.test.insertTest for macro testing. It inserts test methods from a helper method that may accept arguments.
macroTest provides a very economic API for creating new tests for a given macro based on a helper method.
macroTest accepts the following arguments:
- helper_name (str): the name of the helper method. macroTest will
insert a test method which calls the helper with any the helper_kwargs (see below).
- test_method_name (str): Optional. Name of the test method to be used.
If None given, one will be generated from the macro and helper names.
- test_method_doc (str): The docstring for the inserted test method
(this shows in the unit test output). If None given, a default one is generated which includes the input parameters and the helper name.
- **helper_kwargs: All remaining keyword arguments are passed to the
helper.
macroTest assumes that the decorated class has a macro_name class member.
This decorator can be considered a “base” decorator. It is often used to create other decorators in which the helper method is pre-set. Some of them are already provided in this module:
The advantage of using the decorators compared to writing the test methods directly is that the helper method can get keyword arguments and therefore avoid duplication of code for very similar tests (think, e.g. on writing similar tests for various sets of macro input parameters):
Consider the following code written using the RunMacroTestCase.macro_runs() helper:
class FooTest(RunMacroTestCase, unittest.TestCase)
macro_name = twice
def test_foo_runs_with_input_2(self):
'''test that twice(2) runs'''
self.macro_runs(macro_params=['2'])
def test_foo_runs_with_input_minus_1(self):
'''test that twice(2) runs'''
self.macro_runs(macro_params=['-1'])
The equivalent code could be written as:
@macroTest(helper_name='macro_runs', macro_params=['2'])
@macroTest(helper_name='macro_runs', macro_params=['-1'])
class FooTest(RunMacroTestCase, unittest.TestCase):
macro_name = 'twice'
Or, even better, using the specialized testRun decorator:
@testRun(macro_params=['2'])
@testRun(macro_params=['-1'])
class FooTest(RunMacroTestCase, unittest.TestCase):
macro_name = 'twice'
See also
:function::taurus.test.insertTest
Abstract MacroExecutor class. Inherit from it if you want to create your own macro executor.
Execute macro.
Parameters: |
|
---|
Wait until macro is done. Use it in asynchronous executions.
Parameters: | timeout – (float) waiting timeout (in s) |
---|
Stop macro execution. Execute macro in synchronous way before using this method.
Parameters: | started_event_timeout – (float) waiting timeout for started event |
---|
Start registering log messages.
Parameters: | log_level – (str) string indicating the log level |
---|
Stop registering log messages.
Parameters: | log_level – (str) string indicating the log level |
---|
Get log messages.
Parameters: | log_level – (str) string indicating the log level |
---|---|
Returns: | (seq<str>) list of strings with log messages |
Register for macro result, all log levels and common buffer.
Unregister macro result, all log levels and common buffer.
Register for macro result
Unregister macro result.
Get macro result.
Returns: | (seq<str>) list of strings with Result messages |
---|
Create a common buffer, where all the registered logs will be stored.
Returns: | (seq<str>) list of strings with messages from all log levels See also |
---|
Get macro execution state.
Returns: | (str) |
---|
Get buffer (history) of macro execution states.
Returns: | (seq<str>) |
---|
Get macro exception type representation (None if the macro state is not exception).
Returns: | (str) |
---|
A scheme-agnostic factory for MacroExecutor instances
Example:
f = MacroExecutorFactory()
f.getMacroExecutor('tango://my/door/name') #returns a TangoMacroExecutor
Note: For the moment, only TangoMacroExecutor is supported
Returns a macro executor instance (a subclass of BaseMacroExecutor) depending on the door being used.
An abstract class for macro testing. BaseMacroTestCase will provide a macro_executor member which is an instance of BaseMacroExecutor and which can be used to run a macro.
To use it, simply inherit from BaseMacroTestCase and unittest.TestCase and provide the following class members:
macro_name (string) name of the macro to be tested (mandatory)
- door_name (string) name of the door where the macro will be executed.
This is optional. If not set, sardanacustomsettings.UNITTEST_DOOR_NAME is used
Then you may define test methods.
A macro_executor instance must be created
The macro_executor instance must be removed
A base class for testing execution of arbitrary Sardana macros. See BaseMacroTestCase for requirements.
Asserts that macro has finished.
Preconditions: - Those from BaseMacroTestCase - the macro executor registers to all the log levels
A helper method to create tests that check if the macro can be successfully executed for the given input parameters. It may also optionally perform checks on the outputs from the execution.
Parameters: |
|
---|
Check that the macro fails to run for the given input parameters
Parameters: |
|
---|
The macro_executor instance must be removed
This is an extension of RunMacroTestCase to include helpers for testing the abort process of a macro. Useful for Runnable and Stopable macros.
It provides the macro_stops() helper
Asserts that macro was stopped
A helper method to create tests that check if the macro can be successfully stoped (a.k.a. aborted) after it has been launched.
Parameters: |
|
---|
Asserts that macro has finished.
Check that the macro fails to run for the given input parameters
Parameters: |
|
---|
A helper method to create tests that check if the macro can be successfully executed for the given input parameters. It may also optionally perform checks on the outputs from the execution.
Parameters: |
|
---|
Preconditions: - Those from BaseMacroTestCase - the macro executor registers to all the log levels
The macro_executor instance must be removed
Class to get _SAR_DEMO environment variable with cross checking with the MacroServer (given by UNITTEST_DOOR_NAME)
Return the name of sardemo element(s) of given elem type
Parameters: | elem_type – (str) type of elemnts to return (all by default) |
---|---|
Returns: | (list<str>) |
Return the name of moveable(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of controllers(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of counter timer exp channel(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of motor(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of pseudomotor(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of zerod exp channel(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of one exp channel(s) defined by SarDemo
Returns: | (list<str>) |
---|
Return the name of two exp channel(s) defined by SarDemo
Returns: | (list<str>) |
---|
Change the door name and reset all lists