Skip to content

Commit

Permalink
Class reference type, forgot to add new animals conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
davidorme committed Sep 29, 2023
1 parent 0d4e99c commit 4784638
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
98 changes: 98 additions & 0 deletions tests/models/animals/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""Collection of fixtures to assist the animal model testing scripts."""

import numpy as np
import pytest
import xarray


@pytest.fixture
def plant_data_instance():
"""Fixture returning a simple data instance containing plant resource data."""
from virtual_rainforest.core.data import Data
from virtual_rainforest.core.grid import Grid

# Populate data with a layers x cell id layer_leaf_mass array
data = Data(grid=Grid(cell_nx=3, cell_ny=3))
leaf_mass = np.full((15, 9), fill_value=np.nan)
leaf_mass[1:4, :] = 10000
data["layer_leaf_mass"] = xarray.DataArray(
data=leaf_mass, dims=["layers", "cell_id"]
)

return data


@pytest.fixture
def functional_group_list_instance(shared_datadir):
"""Fixture for an animal functional group used in tests."""
from virtual_rainforest.models.animals.functional_group import (
import_functional_groups,
)

file = shared_datadir / "example_functional_group_import.csv"
fg_list = import_functional_groups(file)

return fg_list


@pytest.fixture
def animal_model_instance(data_instance, functional_group_list_instance):
"""Fixture for an animal model object used in tests."""
from pint import Quantity

from virtual_rainforest.models.animals.animal_model import AnimalModel

return AnimalModel(data_instance, Quantity("1 day"), functional_group_list_instance)


@pytest.fixture
def animal_community_instance(
functional_group_list_instance, animal_model_instance, plant_data_instance
):
"""Fixture for an animal community used in tests."""
from virtual_rainforest.models.animals.animal_communities import AnimalCommunity

return AnimalCommunity(
functional_groups=functional_group_list_instance,
data=plant_data_instance,
community_key=4,
neighbouring_keys=[1, 3, 5, 7],
get_destination=animal_model_instance.get_community_by_key,
)


@pytest.fixture
def herbivore_functional_group_instance(shared_datadir):
"""Fixture for an animal functional group used in tests."""
from virtual_rainforest.models.animals.functional_group import (
import_functional_groups,
)

file = shared_datadir / "example_functional_group_import.csv"
fg_list = import_functional_groups(file)

return fg_list[3]


@pytest.fixture
def herbivore_cohort_instance(herbivore_functional_group_instance):
"""Fixture for an animal cohort used in tests."""
from virtual_rainforest.models.animals.animal_cohorts import AnimalCohort

return AnimalCohort(herbivore_functional_group_instance, 10000.0, 1)


@pytest.fixture
def excrement_instance():
"""Fixture for a soil pool used in tests."""
from virtual_rainforest.models.animals.decay import ExcrementPool

return ExcrementPool(100000.0, 0.0)


@pytest.fixture
def plant_instance(plant_data_instance):
"""Fixture for a plant community used in tests."""
from virtual_rainforest.models.animals.plant_resources import PlantResources

return PlantResources(data=plant_data_instance, cell_id=4)
2 changes: 1 addition & 1 deletion virtual_rainforest/models/animals/plant_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PlantResources:
"""A class implementing the Resource protocol for plant data.
This class acts as the interface between plant model data stored in the core data
object using the :class:`~virtual_rainforest.models.animals.protocols.Resources`
object using the :class:`~virtual_rainforest.models.animals.protocols.Resource`
protocol.
At present, it only exposes a single resource - the total leaf mass of the entire
Expand Down

0 comments on commit 4784638

Please sign in to comment.