Ejemplo n.º 1
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert fields.add_empty('a', at='node') is not fields.add_empty('a', at='node', noclobber=False)
    assert fields.add_ones('b', at='node') is not fields.add_ones('b', at='node', noclobber=False)
    assert fields.add_zeros('c', at='node') is not fields.add_zeros('c', at='node', noclobber=False)
Ejemplo n.º 2
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert_dict_equal(dict(), fields.at_node)
    assert_raises(AttributeError, lambda: fields.at_cell)

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Ejemplo n.º 3
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones("z", at="node")
    assert_array_equal(np.ones(12), fields.at_node["z"])
Ejemplo n.º 4
0
def test_at_attribute():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    assert dict() == fields.at_node
    with pytest.raises(AttributeError):
        fields.at_cell

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields.at_node['z'])
Ejemplo n.º 5
0
def test_grid_field_add_zeros_ones_empty():
    """Test creating scalar fields with add_zeros, add_empty, and add_ones."""
    fields = ModelDataFields()
    fields.new_field_location("grid", 1)

    with pytest.raises(ValueError):
        fields.add_zeros("value", at="grid")
    with pytest.raises(ValueError):
        fields.add_empty("value", at="grid")
    with pytest.raises(ValueError):
        fields.add_ones("value", at="grid")
Ejemplo n.º 6
0
def test_add_ones():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    fields.add_ones('z', at='node')
    assert_array_equal(np.ones(12), fields['node']['z'])
    assert_array_equal(np.ones(12), fields.field_values('node', 'z'))

    fields.add_ones('z', at='cell')
    assert_array_equal(np.ones(2), fields['cell']['z'])
    assert_array_equal(np.ones(2), fields.field_values('cell', 'z'))
Ejemplo n.º 7
0
def test_add_existing_field_with_noclobber():
    """Test noclobber raises an error with an existing field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.add_empty("z", at="node")

    with pytest.raises(FieldError):
        fields.add_empty("z", at="node", noclobber=True)
    with pytest.raises(FieldError):
        fields.add_ones("z", at="node", noclobber=True)
    with pytest.raises(FieldError):
        fields.add_zeros("z", at="node", noclobber=True)
Ejemplo n.º 8
0
def test_add_existing_field_default():
    """Test default is to not replace existing field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.add_empty("z", at="node")

    with pytest.raises(FieldError):
        fields.add_empty("z", at="node")
    with pytest.raises(FieldError):
        fields.add_ones("z", at="node")
    with pytest.raises(FieldError):
        fields.add_zeros("z", at="node")
Ejemplo n.º 9
0
def test_add_ones():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    fields.add_ones("z", at="node")
    assert_array_equal(np.ones(12), fields["node"]["z"])
    assert_array_equal(np.ones(12), fields.field_values("node", "z"))

    fields.add_ones("z", at="cell")
    assert_array_equal(np.ones(2), fields["cell"]["z"])
    assert_array_equal(np.ones(2), fields.field_values("cell", "z"))
Ejemplo n.º 10
0
def test_add_field_with_noclobber():
    """Test noclobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location('node', 12)

    fields.add_empty('a', at='node', noclobber=True)
    assert_true('a' in fields['node'])

    fields.add_ones('b', at='node', noclobber=True)
    assert_true('b' in fields['node'])

    fields.add_zeros('c', at='node', noclobber=True)
    assert_true('c' in fields['node'])
Ejemplo n.º 11
0
def test_add_field_with_noclobber():
    """Test noclobber does not raise an error with an new field."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    fields.add_empty("a", at="node", noclobber=True)
    assert "a" in fields["node"]

    fields.add_ones("b", at="node", noclobber=True)
    assert "b" in fields["node"]

    fields.add_zeros("c", at="node", noclobber=True)
    assert "c" in fields["node"]
Ejemplo n.º 12
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location('node', 12)
    fields.new_field_location('cell', 2)

    rtn_value = fields.add_ones('z', at='node')
    assert_array_equal(rtn_value, np.ones(12))
    assert_is(rtn_value, fields['node']['z'])
    assert_is(rtn_value, fields.field_values('node', 'z'))

    rtn_value = fields.add_ones('z', at='cell')
    assert_array_equal(rtn_value, np.ones(2))
    assert_is(rtn_value, fields['cell']['z'])
    assert_is(rtn_value, fields.field_values('cell', 'z'))
Ejemplo n.º 13
0
def test_add_ones_return_value():
    fields = ModelDataFields()
    fields.new_field_location("node", 12)
    fields.new_field_location("cell", 2)

    rtn_value = fields.add_ones("z", at="node")
    assert_array_equal(rtn_value, np.ones(12))
    assert rtn_value is fields["node"]["z"]
    assert rtn_value is fields.field_values("node", "z")

    rtn_value = fields.add_ones("z", at="cell")
    assert_array_equal(rtn_value, np.ones(2))
    assert rtn_value is fields["cell"]["z"]
    assert rtn_value is fields.field_values("cell", "z")
Ejemplo n.º 14
0
def test_add_field_with_clobber():
    """Test adding a field with clobber on."""
    fields = ModelDataFields()
    fields.new_field_location("node", 12)

    assert fields.add_empty("a", at="node") is not fields.add_empty(
        "a", at="node", noclobber=False
    )
    assert fields.add_ones("b", at="node") is not fields.add_ones(
        "b", at="node", noclobber=False
    )
    assert fields.add_zeros("c", at="node") is not fields.add_zeros(
        "c", at="node", noclobber=False
    )