Skip to content

Commit

Permalink
Implement Model.__repr__ (#319)
Browse files Browse the repository at this point in the history
Include the model ID in `Model.__repr__`.
  • Loading branch information
dweindl authored Nov 8, 2024
1 parent be3a5eb commit 09661eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions petab/v1/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Model(abc.ABC):
def __init__(self):
...

def __repr__(self):
return f"<{self.__class__.__name__} {self.model_id!r}>"

@staticmethod
@abc.abstractmethod
def from_file(filepath_or_buffer: Any, model_id: str) -> Model:
Expand Down
6 changes: 6 additions & 0 deletions tests/v1/test_model_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ def test_pattern_parsing(uses_pysb):
pattern = pysb.as_complex_pattern(B(s="a") ** c1)
assert pattern_from_string(str(pattern), model).matches(pattern)
assert str(pattern) == str(pattern_from_string("B(s='a') ** c1", model))


def test_pysb_model_repr(uses_pysb):
model = pysb.Model(name="test")
petab_model = PySBModel(model)
assert repr(petab_model) == "<PySBModel 'test'>"
11 changes: 11 additions & 0 deletions tests/v1/test_sbml.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import sys

import libsbml
import pandas as pd
import pytest

from petab.v1.models.sbml_model import SbmlModel

sys.path.append(os.getcwd())
import petab # noqa: E402

Expand Down Expand Up @@ -122,3 +125,11 @@ def test_get_condition_specific_models():
)

check_model(condition_model)


def test_sbml_model_repr():
sbml_document = libsbml.SBMLDocument()
sbml_model = sbml_document.createModel()
sbml_model.setId("test")
petab_model = SbmlModel(sbml_model)
assert repr(petab_model) == "<SbmlModel 'test'>"

0 comments on commit 09661eb

Please sign in to comment.