Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions modelx/tests/export/test_lifelib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import shutil
import sys
import math

Expand Down Expand Up @@ -83,6 +84,35 @@ def test_appliedlife(tmp_path_factory):
model.close()


def test_annuallife(tmp_path_factory):
import lifelib
library, name = 'annuallife', 'TradLife_A_EX1'

tmp = tmp_path_factory.mktemp('tmp') / library
lifelib.create(library, tmp)

model = mx.read_model(tmp / name)

# Export next to the source model so that input.xlsx, which the model
# reads from its parent directory at run time, is found by the exported
# model as well. Remove a bundled copy of the exported model if any.
nomx_dir = tmp / (name + '_nomx')
shutil.rmtree(nomx_dir, ignore_errors=True)
model.export(nomx_dir)

try:
sys.path.insert(0, str(tmp))
nomx = importlib.import_module(name + '_nomx').mx_model
for i in (0, 299):
assert math.isclose(
model.Projection[i].risk_margin(0),
nomx.Projection[i].risk_margin(0)
)
finally:
sys.path.pop(0)
model.close()


def test_assets(tmp_path_factory):
import lifelib
library, name, arg = 'assets', 'BasicBonds', None
Expand Down
Loading