calibration_config_base

This module contains base classes for config objects, and the OneOrMany pattern.

Config nodes are represented by classes derived from ConfigObjectBase and XmlConfigObject, and groups of config nodes by OneOrMany collection. Most operations performed on OneOrMany collections will return OneOrMany collections of results.

For the derived classes and Ph2ACF config implementation, see the calibration_config module.

Classes

ConfigContext(cls, xml_file[, cascade])

Context handler for Config.

ConfigObjectBase(id, parent)

Base interface for all config nodes in config tree.

OneOrMany([iterable])

Base class implementing one-or-many selector pattern on a container (in this case, python list).

XmlConfigObject(xml_root[, id, parent])

Representation of config XML nodes wrapping lxml etree nodes.

ConfigContext

class module_testing.config.calibration_config_base.ConfigContext(cls, xml_file, cascade=True)

Bases: object

Context handler for Config.

__init__(cls, xml_file, cascade=True)
Parameters:
  • cls – class to load config file as.

  • xml_file – open readable file handle for xml file.

  • cascade – whether to cascade __enter__ through config node tree (e.g. to load sub-config-files or RD53 text files).

ConfigObjectBase

class module_testing.config.calibration_config_base.ConfigObjectBase(id, parent)

Bases: object

Base interface for all config nodes in config tree.

__init__(id, parent)
Parameters:
  • id – id of object (e.g. chip id for chips, or register name for registers).

  • parent – parent config node.

OneOrMany

class module_testing.config.calibration_config_base.OneOrMany(iterable=None)

Bases: list

Base class implementing one-or-many selector pattern on a container (in this case, python list).

Classes inheriting from this class can be accessed using <container>.one(<id>) [or equivalently <container>(<id>)], and <container>.all() [or equivalently <container>()]. Attribute accesses return OneOrMany collections containing results for all contained items, and method execution delegates to all items and packages results as OneOrMany collections.

Some operators are also provided - see map(), flatten(), flatmap().

__init__(iterable=None)
Parameters:

iterable – iterable to copy contents of to the new OneOrMany collection. May be None.

all()

Get all contained items.

Returns:

new container copy with same contents.

flatmap(func)

Run func(item) for all items in this collection after flatten().

Equivalent to self.flattened().map(func).

Parameters:

func – function to run on items.

Returns:

OneOrMany collection of results.

flatten()

Flatten hierarchy of OneOrMany collections.

Returns:

iterator/generator containing all items in hierarchy in DFS order.

flattened()

Retrieve flattened hierarchy of OneOrMany collections as OneOrMany.

Returns:

OneOrMany containing all items in hierarchy in DFS order.

map(func)

Run func(item) for all items in this collection.

Parameters:

func – function to run on items.

Returns:

OneOrMany collection of results.

one(id)

Get one or more items by id.

Parameters:

id – item ID, or iterable of item IDs.

Returns:

single item, or OneOrMany of items (if tuple of IDs).

XmlConfigObject

class module_testing.config.calibration_config_base.XmlConfigObject(xml_root, id=None, parent=None)

Bases: ConfigObjectBase

Representation of config XML nodes wrapping lxml etree nodes.

XML attributes and children are transparently accessed as attributes of this object.

__init__(xml_root, id=None, parent=None)
Parameters:
  • xml_root – lxml etree node.

  • id – id of xml object (e.g. chip id for chips, or register name for registers).

  • parent – parent config node.

classmethod open(xml_file, cascade=True)

Mirror for File.open(…) for all xml-based config classes.

Utilises ConfigContext context manager.

Parameters:
  • cls – current class in hierarchy.

  • xml_file – open readable xml file to load.

  • cascade – whether to cascade __enter__ through tree.

Returns:

ConfigContext for given class, file and cascade that can be used with with ...: to load config.