Skip to content

Commit

Permalink
test: Add case that test to skip validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed Jan 23, 2025
1 parent ab4d99a commit e2cb6e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/r2x/parser/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_parser_data(


def create_model_instance(
model_class: type["Component"], skip_validation: bool = False, **field_values: dict[str, Any]
model_class: type["Component"], skip_validation: bool = False, **field_values
) -> Any:
"""Create R2X model instance."""
valid_fields = {
Expand Down
15 changes: 15 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from r2x.enums import PrimeMoversType
from r2x.models import Generator, ACBus, Emission, HydroPumpedStorage, ThermalStandard
from r2x.models import MinMax
from r2x.parser.handler import create_model_instance
from r2x.units import EmissionRate, ureg


Expand Down Expand Up @@ -48,3 +49,17 @@ def test_serialize_active_power_limits():

output = generator.serialize_active_power_limits(active_power_limits)
assert output == {"min": 0, "max": 100}


def test_create_model_instance():
name = "TestGen"
generator = create_model_instance(Generator, name=name)
assert isinstance(generator, Generator)
assert isinstance(generator.name, str)
assert generator.name == name

name = ["TestGen"]
generator = create_model_instance(Generator, name=name, skip_validation=True)
assert isinstance(generator, Generator)
assert isinstance(generator.name, list)
assert generator.name == name

0 comments on commit e2cb6e5

Please sign in to comment.