def test_field_labels(): """ test the FieldCollection.labels property """ grid = UnitGrid([5]) s1 = ScalarField(grid, label="s1") s2 = ScalarField(grid) fc = FieldCollection([s1, s2]) assert fc.labels == ["s1", None] assert len(fc.labels) == 2 assert fc.labels[0] == "s1" fc.labels = ["a", "b"] assert fc.labels == ["a", "b"] fc.labels[0] = "c" assert fc.labels == ["c", "b"] assert str(fc.labels) == str(["c", "b"]) assert repr(fc.labels) == repr(["c", "b"]) assert fc.labels[0:1] == ["c"] assert fc.labels[:] == ["c", "b"] fc.labels[0:1] = "d" assert fc.labels == ["d", "b"] fc.labels[:] = "a" assert fc.labels == ["a", "a"] labels = fc.labels[:] labels[0] = "e" assert fc.labels == ["a", "a"] fc = FieldCollection([s1, s2], labels=[None, "b"]) assert fc.labels == [None, "b"] fc = FieldCollection([s1, s2], labels=["a", "b"]) assert fc.labels == ["a", "b"]
def test_field_labels(): """ test the FieldCollection.labels property """ grid = UnitGrid([5]) s1 = ScalarField(grid, label="s1") s2 = ScalarField(grid) fc = FieldCollection([s1, s2]) assert fc.labels == ["s1", None] assert len(fc.labels) == 2 assert fc.labels[0] == "s1" assert fc.labels.index("s1") == 0 assert fc.labels.index(None) == 1 with pytest.raises(ValueError): fc.labels.index("a") fc.labels = ["a", "b"] assert fc.labels == ["a", "b"] fc.labels[0] = "c" assert fc.labels == ["c", "b"] assert str(fc.labels) == str(["c", "b"]) assert repr(fc.labels) == repr(["c", "b"]) assert fc.labels[0:1] == ["c"] assert fc.labels[:] == ["c", "b"] fc.labels[0:1] = "d" assert fc.labels == ["d", "b"] fc.labels[:] = "a" assert fc.labels == ["a", "a"] labels = fc.labels[:] labels[0] = "e" assert fc.labels == ["a", "a"] fc = FieldCollection([s1, s2], labels=[None, "b"]) assert fc.labels == [None, "b"] fc = FieldCollection([s1, s2], labels=["a", "b"]) assert fc.labels == ["a", "b"] with pytest.raises(TypeError): fc.labels = [1, "b"] with pytest.raises(TypeError): fc.labels[0] = 1