Exemplo n.º 1
0
def test_component_set_field_with_scalar_value_correctly_sets_field_value():
    comp = Component("comp4")
    field_name = "testfield"
    data = 123
    dtype = ValueTypes.INT

    comp.set_field_value(field_name, data, dtype)

    field_dataset = comp[field_name]

    assert field_dataset.name == field_name
    assert field_dataset.values == data
    assert field_dataset.type == dtype
Exemplo n.º 2
0
def test_component_set_field_with_numpy_array_correctly_sets_field_value():

    comp = Component("comp4")
    data = [[1], [2]]
    dtype = ValueTypes.INT
    field_name = "field1"
    field_value = np.asarray(data, dtype=int)

    comp.set_field_value(field_name, field_value, dtype)

    field_dataset = comp["field1"]
    assert field_dataset.name == field_name
    assert np.array_equal(field_dataset.values, field_value)
    assert field_dataset.type == dtype
Exemplo n.º 3
0
def _add_component_to_file(field_name: str,
                           field_value: Any,
                           component_name: str = "test_component"):
    component = Component(component_name)
    component.set_field_value(
        field_name,
        Dataset(
            parent_node=None,
            name=field_name,
            type=ValueTypes.DOUBLE,
            size="[1]",
            values=field_value,
        ),
        dtype=ValueTypes.DOUBLE,
    )

    return component