def setUp(self): modelname = "Test model" model_cfg = HubitModelConfig.from_cfg(yaml.load( model, Loader=yaml.FullLoader), base_path=THIS_DIR) self.hmodel = HubitModel(model_cfg, name=modelname, output_path=REL_TMP_DIR) self.input = yaml.load(yml_input, Loader=yaml.FullLoader) self.use_multi_processing_values = False, True # Query which does not consume results self.idx = 1 self.querystr_level0 = "list[{}].some_attr.two_x_numbers".format( self.idx) self.expected_result_level0 = level0_results_at_idx( self.input, self.idx) self.querystr_level1 = "list[{}].some_attr.two_x_numbers_x_factor".format( self.idx) self.querystr_level0_slice = "list[:].some_attr.two_x_numbers" self.expected_result_level0_slice = [ level0_results_at_idx(self.input, 0), level0_results_at_idx(self.input, 1), ] self.querystr_level0_last = "list[-1].some_attr.two_x_numbers"
def test_duplicate_providers(self): model = """ components: - func_name: move_number path: ./components/comp0.py provides_results: - name: number path: first_coor[IDX1].second_coor[IDX2].value - func_name: multiply_by_2 path: ./components/comp1.py provides_results: - name: number path: first_coor[IDX1].second_coor[IDX2].value """ with pytest.raises(HubitError): HubitModelConfig.from_cfg(yaml.load(model, Loader=yaml.FullLoader), base_path=THIS_DIR)
def test_cmpids_for_query(self): # Test the default model qpath = HubitQueryPath("first_coor[:].second_coor[:].value") result = self.hmodel._cmpids_for_query(qpath, check_intersection=True) expected_result = ["cmp0@./components/comp0.move_number"] assert result == expected_result # Test model with explicit indices model = get_model_with_explicit_indices() model_cfg = HubitModelConfig.from_cfg(yaml.load( model, Loader=yaml.FullLoader), base_path=THIS_DIR) hmodel = HubitModel(model_cfg, name="TEST", output_path=REL_TMP_DIR) TestModel.run_cmpids_for_query_tests(hmodel) # Test model with index scopes model = get_model_with_index_scopes() model_cfg = HubitModelConfig.from_cfg(yaml.load( model, Loader=yaml.FullLoader), base_path=THIS_DIR) hmodel = HubitModel(model_cfg, name="TEST", output_path=REL_TMP_DIR) TestModel.run_cmpids_for_query_tests(hmodel)
def test_mpaths_for_qpath_fields_only(self): # Test the default model qpath = HubitQueryPath("first_coor[:].second_coor[:].value") mpaths, cmp_ids = self.hmodel._mpaths_for_qpath_fields_only(qpath) expected_cmp_ids = [ "cmp0@./components/comp0.move_number", ] assert cmp_ids == expected_cmp_ids expected_mpaths = ["first_coor[IDX1].second_coor[IDX2].value"] assert mpaths == expected_mpaths model = get_model_with_explicit_indices() model_cfg = HubitModelConfig.from_cfg(yaml.load( model, Loader=yaml.FullLoader), base_path=THIS_DIR) hmodel = HubitModel(model_cfg, name="TEST", output_path=REL_TMP_DIR) TestModel.run_mpaths_for_qpath_fields_only(hmodel)
def test_cartesian_product_method(self): query_paths = [] query = Query.from_paths(query_paths) input_values_for_path = { "segments[2].layers[2].material": ("brick", "concrete"), "segments[0].layers[2].thickness": (0.08, 0.12), } hmodel = HubitModel( HubitModelConfig.from_cfg(yaml.load(model, Loader=yaml.FullLoader), base_path=THIS_DIR)) flat_inputs, args = hmodel._cartesian_product_method( query, input_values_for_path, ) expected_inputs = [ { "segments[2].layers[2].material": "brick", "segments[0].layers[2].thickness": 0.08, }, { "segments[2].layers[2].material": "brick", "segments[0].layers[2].thickness": 0.12, }, { "segments[2].layers[2].material": "concrete", "segments[0].layers[2].thickness": 0.08, }, { "segments[2].layers[2].material": "concrete", "segments[0].layers[2].thickness": 0.12, }, ] assert flat_inputs == expected_inputs for i, arg in enumerate(args): assert type(arg[0]) == _QueryRunner assert type(arg[1]) == Query assert arg[2] == expected_inputs[i] assert arg[3] == FlatData()
def setUp(self): cfg = yaml.load(model, Loader=yaml.FullLoader) self.model_cfg = HubitModelConfig.from_cfg(cfg, base_path=THIS_DIR) self.hmodel = HubitModel( self.model_cfg, name="My model", output_path=REL_TMP_DIR, ) use_multi_processing = False self.qr = query_runner_factory(use_multi_processing, self.hmodel) self.input = yaml.load(yml_input, Loader=yaml.FullLoader) self.hmodel.set_input(self.input) # Query which does not consume results self.idx = 1 self.querystr_level0 = HubitQueryPath( "list[{}].some_attr.two_x_numbers".format(self.idx)) self.querystr_level1 = HubitQueryPath( "list[{}].some_attr.two_x_numbers_x_factor".format(self.idx))