From 070bad470c63216f48a3cc7845777bc4b0c99791 Mon Sep 17 00:00:00 2001 From: davidvlaminck <“david.vlaminck@mow.vlaanderen.be”> Date: Mon, 2 Dec 2024 11:34:31 +0100 Subject: [PATCH 1/3] calling function of the converter to clear list of list attributes --- otlmow_template/SubsetTemplateCreator.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/otlmow_template/SubsetTemplateCreator.py b/otlmow_template/SubsetTemplateCreator.py index b16add5..5164036 100644 --- a/otlmow_template/SubsetTemplateCreator.py +++ b/otlmow_template/SubsetTemplateCreator.py @@ -90,11 +90,8 @@ def generate_basic_template(self, path_to_subset: Path, path_to_template_file_an instance.fill_with_dummy_data() otl_objects.append(instance) - # TODO: check if this is needed, as the above line should cover this - attributen = collector.find_attributes_by_class(class_object) - for attribute_object in attributen: - attr = getattr(instance, '_' + attribute_object.name) - attr.fill_with_dummy_data() + DotnotationHelper.clear_list_of_list_attributes(instance) + converter = OtlmowConverter() converter.from_objects_to_file(file_path=temporary_path, sequence_of_objects=otl_objects, **kwargs) From 7537e641f1b5f5365b3f75f7d042bc55011123ba Mon Sep 17 00:00:00 2001 From: davidvlaminck <“david.vlaminck@mow.vlaanderen.be”> Date: Mon, 2 Dec 2024 11:34:45 +0100 Subject: [PATCH 2/3] various small code fixes --- otlmow_template/SubsetTemplateCreator.py | 106 ++++++++++------------- 1 file changed, 48 insertions(+), 58 deletions(-) diff --git a/otlmow_template/SubsetTemplateCreator.py b/otlmow_template/SubsetTemplateCreator.py index 5164036..334399b 100644 --- a/otlmow_template/SubsetTemplateCreator.py +++ b/otlmow_template/SubsetTemplateCreator.py @@ -77,7 +77,7 @@ def generate_basic_template(self, path_to_subset: Path, path_to_template_file_an continue if amount_of_examples != 0: - for i in range(amount_of_examples): + for _ in range(amount_of_examples): instance = dynamic_create_instance_from_uri(class_object.objectUri, model_directory=model_directory) if instance is None: continue @@ -151,7 +151,7 @@ def filters_assets_by_subset(cls, path_to_subset: Path, list_of_otl_objectUri: [ collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset) if list_of_otl_objectUri == []: - return [x for x in collector.classes] + return collector.classes return [x for x in collector.classes if x.objectUri in list_of_otl_objectUri] @staticmethod @@ -218,7 +218,7 @@ def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: list is_deprecated = True if is_deprecated: - cell.value = '[DEPRECATED] ' + cell.value + cell.value = f'[DEPRECATED] {cell.value}' @classmethod def find_uri_in_sheet(cls, sheet): @@ -262,16 +262,10 @@ def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_ name = dotnotation_attribute.field.naam valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items() if v.status != 'verwijderd'] - if dotnotation_attribute.field.naam in choice_list_dict: - column = choice_list_dict[dotnotation_attribute.field.naam] - else: - choice_list_dict = cls.add_choice_list_to_sheet(workbook=workbook, name=name, - options=valid_options, - choice_list_dict=choice_list_dict) - column = choice_list_dict[dotnotation_attribute.field.naam] - option_list = [] - for option in valid_options: - option_list.append(option) + if (dotnotation_attribute.field.naam not in choice_list_dict): + choice_list_dict = cls.add_choice_list_to_sheet( + workbook=workbook, name=name, options=valid_options, choice_list_dict=choice_list_dict) + column = choice_list_dict[dotnotation_attribute.field.naam] start_range = f"${column}$2" end_range = f"${column}${len(valid_options) + 1}" data_val = DataValidation(type="list", formula1=f"Keuzelijsten!{start_range}:{end_range}", @@ -313,7 +307,7 @@ def multiple_csv_template(cls, path_to_template_file_and_extension, path_to_subs file_name = ntpath.basename(path_to_template_file_and_extension) split_file_name = file_name.split('.') things_in_there = os.listdir(tempdir) - csv_templates = [x for x in things_in_there if x.startswith(split_file_name[0] + '_')] + csv_templates = [x for x in things_in_there if x.startswith(f'{split_file_name[0]}_')] for file in csv_templates: test_template_loc = Path(os.path.dirname(path_to_template_file_and_extension)) / file temp_loc = Path(tempdir) / file @@ -335,27 +329,26 @@ def alter_csv_template(cls, path_to_template_file_and_extension, path_to_subset, amount_of_examples = kwargs.get('amount_of_examples', 0) quote_char = '"' with open(temporary_path, 'r+', encoding='utf-8') as csvfile: - new_file = open(path_to_template_file_and_extension, 'w', encoding='utf-8') - reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char) - for row_nr, row in enumerate(reader): - if row_nr == 0: - header = row - else: - data.append(row) - if add_geo_artefact is False: - [header, data] = cls.remove_geo_artefact_csv(header=header, data=data) - if add_attribute_info: - [info, header] = cls.add_attribute_info_csv(header=header, data=data, - instantiated_attributes=instantiated_attributes) - new_file.write(delimiter.join(info) + '\n') - data = cls.add_mock_data_csv(header=header, data=data, rows_of_examples=amount_of_examples) - if highlight_deprecated_attributes: - header = cls.highlight_deprecated_attributes_csv(header=header, data=data, - instantiated_attributes=instantiated_attributes) - new_file.write(delimiter.join(header) + '\n') - for d in data: - new_file.write(delimiter.join(d) + '\n') - new_file.close() + with open(path_to_template_file_and_extension, 'w', encoding='utf-8') as new_file: + reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char) + for row_nr, row in enumerate(reader): + if row_nr == 0: + header = row + else: + data.append(row) + if add_geo_artefact is False: + [header, data] = cls.remove_geo_artefact_csv(header=header, data=data) + if add_attribute_info: + [info, header] = cls.add_attribute_info_csv(header=header, data=data, + instantiated_attributes=instantiated_attributes) + new_file.write(delimiter.join(info) + '\n') + data = cls.add_mock_data_csv(header=header, data=data, rows_of_examples=amount_of_examples) + if highlight_deprecated_attributes: + header = cls.highlight_deprecated_attributes_csv(header=header, data=data, + instantiated_attributes=instantiated_attributes) + new_file.write(delimiter.join(header) + '\n') + for d in data: + new_file.write(delimiter.join(d) + '\n') @classmethod def add_attribute_info_csv(cls, header, data, instantiated_attributes): @@ -402,34 +395,31 @@ def highlight_deprecated_attributes_csv(cls, header, data, instantiated_attribut for dotnototation_title in header: if dotnototation_title == 'typeURI': continue - else: - index = header.index(dotnototation_title) - value = header[index] - try: - is_deprecated = False - if dotnototation_title.count('.') == 1: - dot_split = dotnototation_title.split('.') - attribute = dotnotation_module.get_attribute_by_dotnotation(single_object, - dot_split[0]) - - if len(attribute.deprecated_version) > 0: - is_deprecated = True - dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object, - dotnototation_title) - if len(dotnotation_attribute.deprecated_version) > 0: + + index = header.index(dotnototation_title) + value = header[index] + try: + is_deprecated = False + if dotnototation_title.count('.') == 1: + dot_split = dotnototation_title.split('.') + attribute = dotnotation_module.get_attribute_by_dotnotation(single_object, + dot_split[0]) + + if len(attribute.deprecated_version) > 0: is_deprecated = True - except AttributeError: - continue - if is_deprecated: - header[index] = "[DEPRECATED] " + value + dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object, + dotnototation_title) + if len(dotnotation_attribute.deprecated_version) > 0: + is_deprecated = True + except AttributeError: + continue + if is_deprecated: + header[index] = f"[DEPRECATED] {value}" return header @classmethod def find_uri_in_csv(cls, header): - filter_uri = None - if 'typeURI' in header: - filter_uri = header.index('typeURI') - return filter_uri + return header.index('typeURI') if 'typeURI' in header else None @classmethod def add_choice_list_to_sheet(cls, workbook, name, options, choice_list_dict): From afde07f8f99e0ae8ef6cd9ee5189e4d360d343a7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 2 Dec 2024 10:35:38 +0000 Subject: [PATCH 3/3] Updated coverage.svg --- UnitTests/.coverage | Bin 53248 -> 53248 bytes UnitTests/htmlcov/class_index.html | 12 +- UnitTests/htmlcov/function_index.html | 88 +-- UnitTests/htmlcov/index.html | 12 +- UnitTests/htmlcov/status.json | 2 +- ...88057a1f1ff9_SubsetTemplateCreator_py.html | 747 +++++++++--------- 6 files changed, 429 insertions(+), 432 deletions(-) diff --git a/UnitTests/.coverage b/UnitTests/.coverage index 2b099ac5c51e99be75cb40f5c284daf72dcd50a1..3806077a459d5566a16c4b954040b16c183c7b10 100644 GIT binary patch delta 61 zcmZozz}&Eac|&ZU-rE0v&qu!hUY-Akmw_RHfuVsB!~lZ-e{cW4{lC7yl9_>_28bCX Nco;Y~clVV#0sukR7z+RZ delta 61 zcmZozz}&Eac|&ZU-r4`}>(5o~zhC`0pMimanSp`l0f@oC@Z

coverage.py v7.6.8, - created at 2024-12-02 09:52 +0000 + created at 2024-12-02 10:35 +0000

@@ -435,10 +435,10 @@

/home/runner/work/OTLMOW-Template/OTLMOW-Template/otlmow_template/SubsetTemplateCreator.py SubsetTemplateCreator - 295 + 292 156 0 - 47% + 47% /home/runner/work/OTLMOW-Template/OTLMOW-Template/otlmow_template/SubsetTemplateCreator.py @@ -461,10 +461,10 @@

Total   - 1368 + 1365 416 0 - 70% + 70% @@ -476,7 +476,7 @@

coverage.py v7.6.8, - created at 2024-12-02 09:52 +0000 + created at 2024-12-02 10:35 +0000