Skip to content
Snippets Groups Projects
Commit 68af4ce1 authored by Florian Ziemen's avatar Florian Ziemen
Browse files

basic experiment type -- still very rough

parent 6e7879c7
No related branches found
No related tags found
No related merge requests found
Pipeline #53474 passed with warnings
from collections.abc import Sequence
from dataclasses import dataclass
from dataset import dataset
@dataclass
class model_setup:
git_repo: str
commit_id: str
@dataclass
class icon_setup(model_setup):
configure_command: str
config: str
host: str
@dataclass
class experiment:
experiment_id: str
model: str
setup: model_setup
point_of_contact: str
copyright_info: str
cite_as: str
description: str
datasets: Sequence[dataset]
def __post_init__(self):
self.datasets = list(self.datasets)
if not all(isinstance(x, dataset) for x in self.datasets):
raise TypeError(
f"Datesets must be of type dataset, found {[type(x) for x in self.datasets]}"
)
if not isinstance(self.setup, model_setup):
raise TypeError(
f"setup must be of type model_setup, found {type(self.setup)}."
)
#!/usr/bin/env python
import experiment
import unittest
class test_experiment(unittest.TestCase):
setup = experiment.icon_setup(
configure_command="configure",
config="sensible",
host="levante",
git_repo="gitlab.dkrz.de",
commit_id="abc123",
)
def test_experiment(self):
setup = experiment.icon_setup(
configure_command="configure",
config="sensible",
host="levante",
git_repo="gitlab.dkrz.de",
commit_id="abc123",
)
experiment.experiment(
experiment_id="test",
model="icon",
setup=setup,
point_of_contact="flo",
copyright_info="cc-by-4.0 Flo",
cite_as="Flo",
description="test experiment",
datasets=[],
)
def test_experiment_fail(self):
with self.assertRaises(TypeError):
experiment.icon_setup(
configure_command="configure",
# config="sensible",
host="levante",
git_repo="gitlab.dkrz.de",
commit_id="abc123",
)
with self.assertRaises(TypeError):
experiment.experiment(
experiment_id="test",
model="icon",
setup="BAD SETUP", # !
point_of_contact="flo",
copyright_info="cc-by-4.0 Flo",
cite_as="Flo",
description="test experiment",
datasets=[],
)
with self.assertRaises(TypeError):
experiment.experiment(
experiment_id="test",
model="icon",
setup=test_experiment.setup,
point_of_contact="flo",
copyright_info="cc-by-4.0 Flo",
cite_as="Flo",
description="test experiment",
datasets=("BAD", "DATASET"), # !
)
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment