Exemplo n.º 1
0
def test_condition_template():
    """Test creation and serde of condition templates."""
    bounds = RealBounds(2.5, 10.0, default_units='cm')
    template = ConditionTemplate("Chamber width", bounds=bounds, description="width of chamber")
    assert template.uids is not None  # uids should be added automatically

    # Take template through a serde cycle and ensure that it is unchanged
    assert ConditionTemplate.build(template.dump()) == template
    # A more complicated cycle that goes through both gemd-python and citrine-python serde.
    assert ConditionTemplate.build(loads(dumps(template.dump())).as_dict()) == template
    def _build_child_objects(cls, data: dict, session: Session = None):
        """
        Build the condition and parameter templates and bounds.

        Parameters
        ----------
        data: dict
            A serialized material template.
        session: Session, optional
            Citrine session used to connect to the database.

        Returns
        -------
        None
            The serialized process template is modified so that its conditions are now a list
            of object pairs of the form [ConditionTemplate,
            :py:class:`BaseBounds <taurus.entity.bounds.base_bounds.BaseBounds>`],
            and the parameters are [ParameterTemplate,
            :py:class:`BaseBounds <taurus.entity.bounds.base_bounds.BaseBounds>`].

        """
        if 'conditions' in data and len(data['conditions']) != 0:
            data['conditions'] = [[
                ConditionTemplate.build(cond[0].as_dict()),
                loads(dumps(cond[1]))
            ] for cond in data['conditions']]
        if 'parameters' in data and len(data['parameters']) != 0:
            data['parameters'] = [[
                ParameterTemplate.build(param[0].as_dict()),
                loads(dumps(param[1]))
            ] for param in data['parameters']]