| |||||||||||||||
Testing an Insight Python model Description Files for testing the Insight-Python example "Portfolio Optimization" in the Xpress distribution using pytest. The full app forms part of the Insight developer kit. Assuming this has been extracted into the Xpress installation directory XPRESSDIR, you can find the full app in XPRESSDIR/examples/insight/basic_apps/python/portfolio_optimization Requires pytest to be installed within the Python environment Instructions for using these files:
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
test_application.py # Example file to set up parametrized unit tests for Xpress Insight - Portfolio Optimization example # Copyright (c) 2020-2024 Fair Isaac Corporation. All rights reserved. import os import sys import pytest import xpressinsight as xi sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python_source')) from application import InsightApp @pytest.mark.parametrize( ('input_value', 'expected_output'), ( (0.1, 0.0), (0.2, 13.42), (0.3, 14.24), ) ) def test_app(input_value, expected_output, tmp_path): """ Parametrized testing """ app = xi.create_app(InsightApp, app_work_dir=str(tmp_path)) app.call_exec_mode('LOAD') app.MaxPerShare = input_value app.data_connector.save_input() app.call_exec_mode('RUN') assert app.TotalReturn == pytest.approx(expected_output) if __name__ == "__main__": pytest.main() | |||||||||||||||
© Copyright 2024 Fair Isaac Corporation. |