From 5dced76548d6251dc7f3938e93725c66684faaa3 Mon Sep 17 00:00:00 2001 From: Fumito Hamamura Date: Sun, 12 Jul 2026 10:56:17 +0900 Subject: [PATCH 1/2] TST: Add export test for TradLife_A_EX1 risk margin Compare Projection[i].risk_margin(0) for i=0 and 299 between the modelx model and its exported counterpart. The model reads input.xlsx from its parent directory at run time, so the workbook is copied next to the exported model as well. Co-Authored-By: Claude Fable 5 --- modelx/tests/export/test_lifelib.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modelx/tests/export/test_lifelib.py b/modelx/tests/export/test_lifelib.py index 3608b72e..5d341f2b 100644 --- a/modelx/tests/export/test_lifelib.py +++ b/modelx/tests/export/test_lifelib.py @@ -1,4 +1,5 @@ import importlib +import shutil import sys import math @@ -83,6 +84,34 @@ 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) + nomx_path = tmp_path_factory.mktemp('nomx_models') + model.export(nomx_path / (name + '_nomx')) + + # The model reads input.xlsx from its parent directory at run time, + # so the exported model needs a copy next to it as well. + shutil.copy(tmp / 'input.xlsx', nomx_path / 'input.xlsx') + + try: + sys.path.insert(0, str(nomx_path)) + 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 From 13090d481d75b537ca62717da92bb59f320064bf Mon Sep 17 00:00:00 2001 From: Fumito Hamamura Date: Sun, 12 Jul 2026 11:01:37 +0900 Subject: [PATCH 2/2] TST: Export TradLife_A_EX1 next to the source model Exporting into the same directory as the source model lets the exported model find input.xlsx in its parent directory, removing the need to copy the workbook separately. A bundled copy of the exported model, if any, is removed before exporting. Co-Authored-By: Claude Fable 5 --- modelx/tests/export/test_lifelib.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modelx/tests/export/test_lifelib.py b/modelx/tests/export/test_lifelib.py index 5d341f2b..447e05ca 100644 --- a/modelx/tests/export/test_lifelib.py +++ b/modelx/tests/export/test_lifelib.py @@ -92,15 +92,16 @@ def test_annuallife(tmp_path_factory): lifelib.create(library, tmp) model = mx.read_model(tmp / name) - nomx_path = tmp_path_factory.mktemp('nomx_models') - model.export(nomx_path / (name + '_nomx')) - # The model reads input.xlsx from its parent directory at run time, - # so the exported model needs a copy next to it as well. - shutil.copy(tmp / 'input.xlsx', nomx_path / 'input.xlsx') + # 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(nomx_path)) + sys.path.insert(0, str(tmp)) nomx = importlib.import_module(name + '_nomx').mx_model for i in (0, 299): assert math.isclose(