def test_get_class_multiple_pms(self): self.write_example_class_to_pipeline_dict_file() self.write_example_class_to_pipeline_dict_file(file_path=self.second_pipeline_dict_path) pipeline_manager = self.create_pm() pipeline_manager.load() pipeline_manager2 = self.create_pm( folder=self.second_pm_folder, name=self.second_test_name, ) pipeline_manager2.load() sel = Selector() # Get from pipeline manager 1 iv = sel.test_pipeline_manager.stuff.ExampleClass iv_obj = pipeline_manager.get(iv) str_obj = pipeline_manager.get('stuff.ExampleClass') assert iv_obj is str_obj is iv() assert iv_obj == ExampleClass(None) # Get from pipeline manager 2 iv = sel.test_pipeline_manager2.stuff.ExampleClass iv_obj = pipeline_manager2.get(iv) str_obj = pipeline_manager2.get('stuff.ExampleClass') assert iv_obj is str_obj is iv() assert iv_obj == ExampleClass(None)
def test_get_specific_class_dict_section_multiple_pms(self): self.write_example_class_dict_to_file() self.write_example_class_dict_to_file(pm_index=1) pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST ) pipeline_manager.load() pipeline_manager2 = self.create_pm( folder=self.second_pm_folder, name=self.second_test_name, specific_class_config_dicts=CLASS_CONFIG_DICT_LIST, ) pipeline_manager2.load() sel = Selector() # Get pipeline manager 1 section iv = sel.test_pipeline_manager.example_class.stuff expect_ec = ExampleClass(None, name='data') iv_section = pipeline_manager.get(iv) iv_obj = iv_section[0] str_section = pipeline_manager.get('example_class.stuff') str_obj = str_section[0] assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a # Get pipeline manager 2 section iv = sel.test_pipeline_manager2.example_class.stuff expect_ec = ExampleClass(None, name='data') iv_section = pipeline_manager2.get(iv) iv_obj = iv_section[0] str_section = pipeline_manager2.get('example_class.stuff') str_obj = str_section[0] assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a
def test_create_from_specific_class_dict_multiple_pms(self): self.write_example_class_dict_to_file() self.write_example_class_dict_to_file(pm_index=1) pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST) pipeline_manager.load() pipeline_manager2 = self.create_pm( folder=self.second_pm_folder, name=self.second_test_name, specific_class_config_dicts=CLASS_CONFIG_DICT_LIST, ) pipeline_manager2.load() sel = Selector() # Assert pipeline manager 1 create ec = sel.test_pipeline_manager.example_class.stuff.data expect_ec = ExampleClass(None, name='data') assert ec.name == expect_ec.name assert ec.a == expect_ec.a # Assert pipeline manager 2 create ec = sel.test_pipeline_manager2.example_class.stuff.data expect_ec = ExampleClass(None, name='data') assert ec.name == expect_ec.name assert ec.a == expect_ec.a
def test_create_then_update_entry_for_specific_class_dict(self): self.write_example_class_dict_to_file() pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST) pipeline_manager.load() sel = Selector() pipeline_manager.create('example_class.thing.data') iv = sel.test_pipeline_manager.example_class.thing.data expected_a_result = (1, 2) section_path = SectionPath.from_section_str_list( SectionPath(iv.section_path_str)[1:]) pipeline_manager.update(a=expected_a_result, section_path_str=section_path.path_str) class_folder = os.path.join(self.defaults_path, 'example_class') module_folder = os.path.join(class_folder, 'thing') class_path = os.path.join(module_folder, 'data.py') with open(class_path, 'r') as f: contents = f.read() self.assert_example_class_dict_config_file_contents(contents) ec = sel.test_pipeline_manager.example_class.thing.data result = pipeline_manager.run(ec) assert result == 'woo' expect_ec = ExampleClass(name='data', a=expected_a_result) got_ec = ec.item assert ec.name == expect_ec.name == got_ec.name assert ec.a == expect_ec.a == got_ec.a
def test_create_class(self): self.write_example_class_to_pipeline_dict_file() pipeline_manager = self.create_pm() pipeline_manager.load() sel = Selector() ec = sel.test_pipeline_manager.stuff.ExampleClass() assert ec == ExampleClass(None)
def test_get_class(self): self.write_example_class_to_pipeline_dict_file() pipeline_manager = self.create_pm() pipeline_manager.load() sel = Selector() iv = sel.test_pipeline_manager.stuff.ExampleClass iv_obj = pipeline_manager.get(iv) str_obj = pipeline_manager.get('stuff.ExampleClass') assert iv_obj is str_obj is iv() assert iv_obj == ExampleClass(None)
def test_create_from_specific_class_dict(self): self.write_example_class_dict_to_file() pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST) pipeline_manager.load() sel = Selector() ec = sel.test_pipeline_manager.example_class.stuff.data expect_ec = ExampleClass(None, name='data') assert ec.name == expect_ec.name assert ec.a == expect_ec.a
def test_create_class_multiple_pms(self): self.write_example_class_to_pipeline_dict_file() self.write_example_class_to_pipeline_dict_file( file_path=self.second_pipeline_dict_path) pipeline_manager = self.create_pm() pipeline_manager.load() pipeline_manager2 = self.create_pm( folder=self.second_pm_folder, name=self.second_test_name, ) pipeline_manager2.load() sel = Selector() # Assert pipeline manager 1 create ec = sel.test_pipeline_manager.stuff.ExampleClass() assert ec == ExampleClass(None) # Assert pipeline manager 2 create ec = sel.test_pipeline_manager2.stuff.ExampleClass() assert ec == ExampleClass(None)
def test_create_entries_for_specific_class_dict_get_section(self): self.write_example_class_dict_to_file() pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST) pipeline_manager.load() sel = Selector() pipeline_manager.create('example_class.thing.data') pipeline_manager.create('example_class.thing.data2') class_folder = os.path.join(self.defaults_path, 'example_class') module_folder = os.path.join(class_folder, 'thing') for attr in ['data', 'data2']: class_path = os.path.join(module_folder, f'{attr}.py') with open(class_path, 'r') as f: contents = f.read() self.assert_example_class_dict_config_file_contents( contents, name_value=f"name: Optional[str] = '{attr}'") iv = sel.test_pipeline_manager.example_class.thing result = pipeline_manager.get(iv) assert result[0] == ExampleClass(a=None, name='data') assert result[1] == ExampleClass(a=None, name='data2') assert len(result) == 2
def test_get_class_from_specific_config_dict(self): self.write_example_class_dict_to_file() pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST ) pipeline_manager.load() sel = Selector() iv = sel.test_pipeline_manager.example_class.stuff.data expect_ec = ExampleClass(None, name='data') iv_obj = pipeline_manager.get(iv) str_obj = pipeline_manager.get('example_class.stuff.data') assert iv_obj is str_obj is iv.item assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a
def test_create_from_multiple_specific_class_dicts_different_class(self): self.write_example_class_dict_to_file() # example_class self.write_example_class_dict_to_file(2) # second_example_class pipeline_manager = self.create_pm( specific_class_config_dicts=DIFFERENT_CLASS_CONFIG_DICT_LIST) pipeline_manager.load() sel = Selector() ec = sel.test_pipeline_manager.example_class.stuff.data sec = sel.test_pipeline_manager.second_example_class.stuff.data expect_ec = ExampleClass(None, name='data') expect_sec = SecondExampleClass(name='data') assert ec.name == expect_sec.name == expect_ec.name assert ec.a == expect_ec.a assert sec.b == expect_sec.b
def test_get_specific_class_dict_nested_section(self): self.write_example_class_dict_to_file(nest_section=True) pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST ) pipeline_manager.load() sel = Selector() iv = sel.test_pipeline_manager.example_class expect_ec = ExampleClass(None, name='data') iv_section = pipeline_manager.get(iv) iv_obj = iv_section['my_section']['stuff'][0] str_section = pipeline_manager.get('example_class') str_obj = str_section['my_section']['stuff'][0] assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a
def test_get_specific_class_dict_section_custom_name(self): self.write_example_class_dict_to_file() pipeline_manager = self.create_pm( specific_class_config_dicts=CLASS_CONFIG_DICT_LIST ) pipeline_manager.load() self.append_to_specific_class_config('name: str = "My Name"') pipeline_manager.reload() sel = Selector() iv = sel.test_pipeline_manager.example_class.stuff expect_ec = ExampleClass(None, name='My Name') iv_section = pipeline_manager.get(iv) iv_obj = iv_section[0] str_section = pipeline_manager.get('example_class.stuff') str_obj = str_section[0] assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a
def test_get_specific_class_dict_custom_key_attr_section(self): self.write_example_class_dict_to_file() class_config_dict_list = deepcopy(CLASS_CONFIG_DICT_LIST) class_config_dict_list[0].update( key_attr='a' ) pipeline_manager = self.create_pm( specific_class_config_dicts=class_config_dict_list ) pipeline_manager.load() sel = Selector() iv = sel.test_pipeline_manager.example_class.stuff expect_ec = ExampleClass(a='data') iv_section = pipeline_manager.get(iv) iv_obj = iv_section[0] str_section = pipeline_manager.get('example_class.stuff') str_obj = str_section[0] assert iv_obj.name == str_obj.name == expect_ec.name assert iv_obj.a == str_obj.a == expect_ec.a
def test_get_class_from_specific_config_dict_custom_key_attr_and_key(self): self.write_example_class_dict_to_file() ccdl = deepcopy(CLASS_CONFIG_DICT_LIST) for cd in ccdl: cd['key_attr'] = 'c' pipeline_manager = self.create_pm( specific_class_config_dicts=ccdl ) pipeline_manager.load() self.append_to_specific_class_config('c: str = "My Name"') pipeline_manager.reload() sel = Selector() iv = sel.test_pipeline_manager.example_class.stuff.data expect_ec = ExampleClass(None, c='My Name', name=None) iv_obj = pipeline_manager.get(iv) str_obj = pipeline_manager.get('example_class.stuff.data') assert iv_obj is str_obj is iv.item assert iv_obj.c == str_obj.c == expect_ec.c assert iv_obj.a == str_obj.a == expect_ec.a