Skip to content

Commit

Permalink
Incorporate changes from #110
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Aug 22, 2024
1 parent 5405760 commit 7b510d8
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 92 deletions.
25 changes: 9 additions & 16 deletions tests/core/test_optimization_equation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pandas as pd
import pytest

from ixmp4 import Platform
import ixmp4
from ixmp4.core import Equation, IndexSet

from ..utils import all_platforms, create_indexsets_for_run
from ..utils import create_indexsets_for_run


def df_from_list(equations: list):
Expand All @@ -31,10 +31,8 @@ def df_from_list(equations: list):
)


@all_platforms
class TestCoreEquation:
def test_create_equation(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_create_equation(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")

# Test normal creation
Expand Down Expand Up @@ -95,8 +93,7 @@ def test_create_equation(self, test_mp, request):
assert equation_3.columns[0].dtype == "object"
assert equation_3.columns[1].dtype == "int64"

def test_get_equation(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_get_equation(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")
(indexset,) = create_indexsets_for_run(
platform=test_mp, run_id=run.id, amount=1
Expand All @@ -117,8 +114,7 @@ def test_get_equation(self, test_mp, request):
with pytest.raises(Equation.NotFound):
_ = run.optimization.equations.get("Equation 2")

def test_equation_add_data(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_equation_add_data(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")
indexset, indexset_2 = tuple(
IndexSet(_backend=test_mp.backend, _model=model)
Expand Down Expand Up @@ -238,13 +234,12 @@ def test_equation_add_data(self, test_mp, request):
equation_3.add(data=test_data_4)
test_data_5 = test_data_3.copy()
for key, value in test_data_4.items():
test_data_5[key].extend(value)
test_data_5[key].extend(value) # type: ignore
assert equation_3.data == test_data_5
assert equation_3.levels == test_data_5["levels"]
assert equation_3.marginals == test_data_5["marginals"]

def test_list_equation(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_list_equation(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")
indexset, indexset_2 = create_indexsets_for_run(platform=test_mp, run_id=run.id)
equation = run.optimization.equations.create(
Expand Down Expand Up @@ -272,8 +267,7 @@ def test_list_equation(self, test_mp, request):
]
assert not (set(expected_id) ^ set(list_id))

def test_tabulate_equation(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_tabulate_equation(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")
indexset, indexset_2 = tuple(
IndexSet(_backend=test_mp.backend, _model=model)
Expand Down Expand Up @@ -322,8 +316,7 @@ def test_tabulate_equation(self, test_mp, request):
run.optimization.equations.tabulate(),
)

def test_equation_docs(self, test_mp, request):
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
def test_equation_docs(self, test_mp: ixmp4.Platform):
run = test_mp.runs.create("Model", "Scenario")
(indexset,) = tuple(
IndexSet(_backend=test_mp.backend, _model=model)
Expand Down
Loading

0 comments on commit 7b510d8

Please sign in to comment.