def test_kymograph_collection(tmp_path):
    """test making kymographs for field collections"""
    # create some storage
    field = FieldCollection([
        ScalarField(UnitGrid(8), label="a"),
        ScalarField(UnitGrid(8), label="b")
    ])
    with get_memory_storage(field) as storage:
        for i in range(8):
            field.data = i
            storage.append(field, i)

    # create single kymograph
    path = tmp_path / "test1.png"
    plotting.plot_kymograph(storage,
                            field_index=1,
                            colorbar=True,
                            transpose=True,
                            filename=path)
    assert path.stat().st_size > 0

    # create multiple kymographs
    path = tmp_path / "test2.png"
    plotting.plot_kymographs(storage, filename=path)
    assert path.stat().st_size > 0
def test_data_managment():
    """test how data is set"""
    grid = UnitGrid([2, 2])
    for cls in (ScalarField, VectorField, Tensor2Field):
        s1 = cls(grid, data=1)
        np.testing.assert_allclose(s1.data, 1)

        s2 = cls(grid)
        np.testing.assert_allclose(s2.data, 0)

        c = FieldCollection([s1, s2])
        s1.data = 0
        np.testing.assert_allclose(c.data, 0)

        c.data = 2
        np.testing.assert_allclose(s1.data, 2)
        np.testing.assert_allclose(s2.data, 2)

        c.data += 1
        np.testing.assert_allclose(s1.data, 3)
        np.testing.assert_allclose(s2.data, 3)

        c[0].data += 2  # reference to s1
        c[1].data *= 2  # reference to s2
        np.testing.assert_allclose(s1.data, 5)
        np.testing.assert_allclose(s2.data, 6)

        c[0] = s2
        np.testing.assert_allclose(c.data, 6)

        # nested collections
        with pytest.raises(RuntimeError):
            FieldCollection([c])