[9d3784]: / aiagents4pharma / talk2biomodels / tests / test_sys_bio_model.py

Download this file

64 lines (54 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
This file contains the unit tests for the BioModel class.
'''
from typing import List, Dict, Union, Optional
from pydantic import Field
import pytest
from ..models.sys_bio_model import SysBioModel
class TestBioModel(SysBioModel):
'''
A test BioModel class for unit testing.
'''
biomodel_id: Optional[int] = Field(None, description="BioModel ID of the model")
sbml_file_path: Optional[str] = Field(None, description="Path to an SBML file")
name: Optional[str] = Field(..., description="Name of the model")
description: Optional[str] = Field("", description="Description of the model")
param1: Optional[float] = Field(0.0, description="Parameter 1")
param2: Optional[float] = Field(0.0, description="Parameter 2")
def get_model_metadata(self) -> Dict[str, Union[str, int]]:
'''
Get the metadata of the model.
'''
return self.biomodel_id
def update_parameters(self, parameters):
'''
Update the model parameters.
'''
self.param1 = parameters.get('param1', 0.0)
self.param2 = parameters.get('param2', 0.0)
def simulate(self, duration: Union[int, float]) -> List[float]:
'''
Simulate the model.
'''
return [self.param1 + self.param2 * t for t in range(int(duration))]
def test_get_model_metadata():
'''
Test the get_model_metadata method of the BioModel class.
'''
model = TestBioModel(biomodel_id=123, name="Test Model", description="A test model")
metadata = model.get_model_metadata()
assert metadata == 123
def test_check_biomodel_id_or_sbml_file_path():
'''
Test the check_biomodel_id_or_sbml_file_path method of the BioModel class.
'''
with pytest.raises(ValueError):
TestBioModel(name="Test Model", description="A test model")
def test_simulate():
'''
Test the simulate method of the BioModel class.
'''
model = TestBioModel(biomodel_id=123, name="Test Model", description="A test model")
model.update_parameters({'param1': 1.0, 'param2': 2.0})
results = model.simulate(duration=4.0)
assert results == [1.0, 3.0, 5.0, 7.0]