The configurations system for dectest. Offers two different methods of configuration; as a python file or from a dict. Each method is implemented in a different class, but they all provide the same interface.
Every class that intends to be used as a config class should implement this simple interface.
An interface that all classes implementing config methods should inherit.
Methods that implementing classes must provide the following methods/properties. More information on the required behaviour of each attribute can be found in their individual documentation in this class.
This property must be implemented by all classes implementing the config interface. It should be a mapping of section names to a mapping of item names to values. If that dosn’t make sense, this may help:
>>> conf = DefaultConfig()
>>> conf.store
{'section': {'item1': True, 'item2': 3, 'item4': "foo"}}
This method can be implemented by implementing classes, though it is optional. When called it should reload the config from it’s source.
Returns the config value in the given section with the given name. If the value does not exist, then we look in the DEFAULTS global, and if we can’t find it there, we raise a warning, and return None.
Converts the config value into a boolean. If the value is a string, then a number of values will be checked. The mappings are:
| str | bool |
|---|---|
| ‘yes’ | True |
| ‘true’ | |
| ‘y’ | |
| ‘no’ | False |
| ‘false’ | |
| ‘n’ |
These values are not case sensitive. If the value is not a string or a boolean, then None will be returned.
Returns the config value at the given section as a list.
If the value is not a string, then it will be converted into a list by calling list(value). If the value is a string, it will be treated as a CSV, and split then returned.
If the value converted to a list is empty, or the value could not be converted, then None will be returned.
Tries to return the object at the given name. If the object cannot be found, then None is returned.
The name of an object is it’s module name and then the identifier that you would have to type to access the object. For example, in the module dectest.suite, there is the class TestSuite. The name for that item would be dectest.suite.TestSuite.
If the name argument is not a str or unicode, then it will just be returned.
Sets the logger that the config class can use to report any errors or warnings in get_foo methods.
These are the classes that dectest provides built in. Note that theses are all very simple, and are not more than a few lines long.
A config class that loads the dictionary from the global namespace of any given python file. The file should define a class for each section, with attributes for each value. The class names and attribute names are not case sensitive
For example:
# dectest_config.py
class section1:
item1 = 0
item2 = "one"
item3 = True
class section2:
foo = "bar"