# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest from qlib.finco.tpl import get_tpl_path import ruamel.yaml as yaml from qlib.data.dataset.handler import DataHandlerLP from qlib.utils import init_instance_by_config from qlib.tests import TestAutoData class FincoTpl(TestAutoData): def test_tpl_consistence(self): """Motivation: make sure the configuable template is consistent with the default config""" tpl_p = get_tpl_path() with (tpl_p / "sl" / "workflow_config.yaml").open("rb") as fp: config = yaml.safe_load(fp) # init_data_handler hd: DataHandlerLP = init_instance_by_config(config["task"]["dataset"]["kwargs"]["handler"]) # NOTE: The config in workflow_config_ds.yaml is generated by the following code: # dump in yaml format to file without auto linebreak # print(yaml.dump(hd.data_loader.fields, width=10000, stream=open("_tmp", "w"))) with (tpl_p / "sl-cfg" / "workflow_config_ds.yaml").open("rb") as fp: config = yaml.safe_load(fp) hd_ds: DataHandlerLP = init_instance_by_config(config["task"]["dataset"]["kwargs"]["handler"]) self.assertEqual(hd_ds.data_loader.fields, hd.data_loader.fields) check = hd_ds.fetch().fillna(0.) == hd.fetch().fillna(0.) self.assertTrue(check.all().all()) if __name__ == "__main__": unittest.main()