Exemple #1
0
def test_set_value(class_node: yatiml.Node) -> None:
    assert class_node.is_mapping()
    class_node.set_value(42)
    assert class_node.is_scalar(int)
    assert class_node.yaml_node.value == '42'
    class_node.set_value(True)
    assert class_node.is_scalar(bool)
    assert class_node.yaml_node.value == 'true'
Exemple #2
0
def test_is_scalar(class_node: yatiml.Node) -> None:
    assert class_node.get_attribute('attr1').is_scalar()
    assert class_node.get_attribute('attr1').is_scalar(int)
    assert class_node.get_attribute('null_attr').is_scalar(None)
    assert not class_node.is_scalar()
    with pytest.raises(ValueError):
        class_node.get_attribute('attr1').is_scalar(dict)
Exemple #3
0
    def _yatiml_savorize(cls, node: yatiml.Node) -> None:
        # enum.Enum has a __members__ attribute which contains its
        # members, which we reverse here to make a look-up table that
        # converts values in the YAML file to names expected by YAtiML.
        yaml_to_python = {
                v.value: v.name for v in cls.__members__.values()}

        # Remember that the node can be anything here. We only convert
        # if it's a string with an expected value, otherwise we leave
        # it alone so that a useful error message can be generated.
        if node.is_scalar(str):
            if node.get_value() in yaml_to_python:
                node.set_value(yaml_to_python[node.get_value()])
 def _yatiml_savorize(cls, node: yatiml.Node) -> None:
     yaml_to_py = {v._value_: v._name_ for v in cls.__members__.values()}
     if node.is_scalar(str):
         node.set_value(yaml_to_py.get(node.get_value()))
Exemple #5
0
def test_make_mapping(scalar_node: yatiml.Node) -> None:
    assert scalar_node.is_scalar(int)
    scalar_node.make_mapping()
    assert isinstance(scalar_node.yaml_node, yaml.MappingNode)
    assert scalar_node.yaml_node.tag == 'tag:yaml.org,2002:map'
    assert scalar_node.yaml_node.value == []
Exemple #6
0
 def yatiml_savorize(self, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())  # type: ignore
Exemple #7
0
 def _yatiml_savorize(cls, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())