factories
– The factory functions¶
Factory functions
A number of tests have a lot of machinery in common, so here we provide some factory functions to avoid repetitions and bugs.
Examples¶
>>> # create a driver with a custom function
>>> def foo(vcheck, fname, lpath):
... msg = "doing something on {} for the driver {}"
... print(msg.format(fname[lpath:], vcheck))
>>> a_function_driver = function_factory(foo)
>>> # create a driver with a command line call
>>> cmd = "ls -lh"
>>> ls_driver = command_line_factory(cmd)
>>> # also a list is accepted
>>> cmd = ["ls", "-lh"]
>>> ls_driver = command_line_factory(cmd)
>>> # if you want to use a cure tool, the command must be:
>>> cmd = "checkheader -E -r {recipe}"
>>> cure_driver = command_line_factory(cmd)
>>> # create a driver with a function returning the command line
>>> def cmd_func(vcheck, fname, log, conf):
... cmd = "ls -lh"
... return cmd
>>> ls_driver = command_func_factory(cmd_func)
-
libvhc.factories.
FILES_IFU
= 4¶ number of files per ifu
-
class
libvhc.factories.
function_factory
(func, files_IFU=4, n_exp_option='n_exposures')[source]¶ Bases:
object
Gives the number of expected files per IFU to the html interface, loops through the files for the recipe at hand, and call
func
.Parameters: - func : callable
function to execute:
func(vcheck, fname, lpath)
vcheck : instance of VCheck
store the recipe name and the check currently executing fname : string name of the file to check lpath : int lenght of the path in fname
to remove for the html interface- files_IFU : int
expected files per IFU. Should always be 4.
- n_exp_option : string
name of the option containing the number of exposures. This option must be present in the section of the recipe at hand.
Returns: - driver : callable
implementation of the driver. For the signature see
function_signature()
;args
andkwargs
are not implemented here.
-
class
libvhc.factories.
command_func_factory
(cmd_func, files_IFU=4, n_exp_option='n_exposures')[source]¶ Bases:
libvhc.factories.function_factory
Gives the number of expected files per IFU to the html interface, loop through the files for the recipe at hand, and call a function that execute the shell command returned by
cmd_func
on each file, log the stdout and stderr appropriately and inform the html renderer about the test.The factory can expands the following variables in the output of
cmd_func
:recipe recipe at hand driver driver at hand ifuslot id of the slot from fname
ifuid id of the ifu corresponding to the above fname name of the file to test headkey instruct cure
to write in the fits headers the version of VHC and whether the check is successful or notjson instruct cure
to write json ouput of the to STDOUT, this is then parsed by the loggersThe substitution syntax follow the new string format; e.g.
checkheader {fname}
expands thefname
to the value passed to the function.Parameters: - cmd_func : callable
function returning the string of the shell call:
cmd_func(vcheck, fname, log, conf) -> cmd
Parameters: vcheck : instance of VCheck
store the recipe name and the check currently executing fname : string name of the file to check log : instance of logging.LoggerAdapter
logger conf : instance of configparser.ConfigParser
configuration object Returns: cmd : string string of the command to execute - files_IFU : int
expected files per IFU. Should always be 4.
- n_exp_option : string
name of the option containing the number of exposures. This option must be present in the section of the recipe at hand.
Returns: - driver : callable
implementation of the driver. For the signature see
function_signature()
;args
andkwargs
are not implemented here.
-
class
libvhc.factories.
command_line_factory
(cmd, files_IFU=4, n_exp_option='n_exposures')[source]¶ Bases:
libvhc.factories.command_func_factory
Gives the number of expected files per IFU to the html interface, loop through the files for the recipe at hand, and call a function that execute the shell command
cmd
on each file, log the stdout and stderr appropriately and inform the html renderer about the test.The factory allows to expand the variables described in
command_func_factory
Parameters: - cmd : string or list of string
command to execute
- files_IFU : int
expected files per IFU. Should always be 4.
- n_exp_option : string
name of the option containing the number of exposures. This option must be present in the section of the recipe at hand.
Returns: - driver : callable
implementation of the driver. For the signature see
function_signature()
;args
andkwargs
are not implemented here.
-
libvhc.factories.
_pickle_method
(m)[source]¶ In python 2 it’s not possible to pickle instance methods directly. This function does some magic to do it.
Only for python 2 is this function registers to allow methods pickling
Copied from Stack Overflow