From 0c683d30bf8d03333d1c488a12b9485fb25e7ea6 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Thu, 1 Dec 2022 18:51:21 +0100 Subject: [PATCH 01/13] create subpackage for annotation tests --- .../annotations/test_rename_migration.py | 185 +++++++++++++++++ .../processing/migration/test_migration.py | 189 +----------------- 2 files changed, 192 insertions(+), 182 deletions(-) create mode 100644 package-parser/tests/processing/migration/annotations/test_rename_migration.py diff --git a/package-parser/tests/processing/migration/annotations/test_rename_migration.py b/package-parser/tests/processing/migration/annotations/test_rename_migration.py new file mode 100644 index 000000000..c23819a8c --- /dev/null +++ b/package-parser/tests/processing/migration/annotations/test_rename_migration.py @@ -0,0 +1,185 @@ +from typing import Callable, Tuple + +from package_parser.processing.annotations.model import ( + AbstractAnnotation, + EnumReviewResult, + RenameAnnotation, + TodoAnnotation, +) +from package_parser.processing.api.model import ( + Parameter, + ParameterAssignment, + ParameterDocumentation, +) +from package_parser.processing.migration.annotations import ( + migrate_rename_annotation, + migration_author, +) +from package_parser.processing.migration.model import ( + Mapping, + OneToManyMapping, + OneToOneMapping, +) + + +def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation], + Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], +]: + parameterv1 = Parameter( + id_="test/test.Test_", + name="Test", + qname="test.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2 = Parameter( + id_="test/test.TestB", + name="TestB", + qname="test.TestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = OneToOneMapping(1.0, parameterv1, parameterv2) + annotationsv1 = RenameAnnotation( + target="test/test.Test_", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newName="TestE", + ) + annotationsv2 = RenameAnnotation( + target="test/test.TestB", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newName="TestE", + ) + return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation + + +def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation], + Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], +]: + parameterv1 = Parameter( + id_="test/test.Test", + name="Test", + qname="test.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.TestA", + name="TestA", + qname="test.TestA", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.TestB", + name="TestB", + qname="test.TestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) + annotationsv1 = RenameAnnotation( + target="test/test.Test", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newName="TestA", + ) + annotationsv2 = RenameAnnotation( + target="test/test.TestA", + authors=["testauthor", migration_author], + reviewers=[], + comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + reviewResult=EnumReviewResult.UNSURE, + newName="TestA", + ) + return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation + + +def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation], + Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], +]: + parameterv1 = Parameter( + id_="test/test.Test", + name="Test", + qname="test.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.TestA", + name="TestA", + qname="test.TestA", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.TestB", + name="TestB", + qname="test.TestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) + annotationsv1 = RenameAnnotation( + target="test/test.Test", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newName="TestZ", + ) + annotationsv2_a = TodoAnnotation( + target="test/test.TestA", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + ) + annotationsv2_b = TodoAnnotation( + target="test/test.TestB", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + ) + return ( + mappings, + annotationsv1, + [annotationsv2_a, annotationsv2_b], + migrate_rename_annotation, + ) diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index d6eefdde9..8c30ea4ea 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -1,193 +1,18 @@ -from typing import Callable, Tuple - +from typing import Callable import pytest + from package_parser.processing.annotations.model import ( AbstractAnnotation, AnnotationStore, - EnumReviewResult, - RenameAnnotation, - TodoAnnotation, -) -from package_parser.processing.api.model import ( - Parameter, - ParameterAssignment, - ParameterDocumentation, ) from package_parser.processing.migration import migrate_annotations -from package_parser.processing.migration.annotations import ( - migrate_rename_annotation, - migration_author, -) -from package_parser.processing.migration.model import ( - Mapping, - OneToManyMapping, - OneToOneMapping, +from package_parser.processing.migration.model import Mapping +from tests.processing.migration.annotations.test_rename_migration import ( + migrate_rename_annotation_data_one_to_many_mapping, + migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name, + migrate_rename_annotation_data_one_to_one_mapping, ) - -def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ - Mapping, - AbstractAnnotation, - list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], -]: - parameterv1 = Parameter( - id_="test/test.Test_", - name="Test", - qname="test.Test", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - parameterv2 = Parameter( - id_="test/test.TestB", - name="TestB", - qname="test.TestB", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - mappings = OneToOneMapping(1.0, parameterv1, parameterv2) - annotationsv1 = RenameAnnotation( - target="test/test.Test_", - authors=["testauthor"], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newName="TestE", - ) - annotationsv2 = RenameAnnotation( - target="test/test.TestB", - authors=["testauthor", migration_author], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newName="TestE", - ) - return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation - - -def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() -> Tuple[ - Mapping, - AbstractAnnotation, - list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], -]: - parameterv1 = Parameter( - id_="test/test.Test", - name="Test", - qname="test.Test", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - parameterv2_a = Parameter( - id_="test/test.TestA", - name="TestA", - qname="test.TestA", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - parameterv2_b = Parameter( - id_="test/test.TestB", - name="TestB", - qname="test.TestB", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) - annotationsv1 = RenameAnnotation( - target="test/test.Test", - authors=["testauthor"], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newName="TestA", - ) - annotationsv2 = RenameAnnotation( - target="test/test.TestA", - authors=["testauthor", migration_author], - reviewers=[], - comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", - reviewResult=EnumReviewResult.UNSURE, - newName="TestA", - ) - return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation - - -def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ - Mapping, - AbstractAnnotation, - list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], -]: - parameterv1 = Parameter( - id_="test/test.Test", - name="Test", - qname="test.Test", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - parameterv2_a = Parameter( - id_="test/test.TestA", - name="TestA", - qname="test.TestA", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - parameterv2_b = Parameter( - id_="test/test.TestB", - name="TestB", - qname="test.TestB", - default_value=None, - assigned_by=ParameterAssignment.POSITION_OR_NAME, - is_public=True, - documentation=ParameterDocumentation("", "", ""), - ) - mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) - annotationsv1 = RenameAnnotation( - target="test/test.Test", - authors=["testauthor"], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newName="TestZ", - ) - annotationsv2_a = TodoAnnotation( - target="test/test.TestA", - authors=["testauthor", migration_author], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", - ) - annotationsv2_b = TodoAnnotation( - target="test/test.TestB", - authors=["testauthor", migration_author], - reviewers=[], - comment="", - reviewResult=EnumReviewResult.NONE, - newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", - ) - return ( - mappings, - annotationsv1, - [annotationsv2_a, annotationsv2_b], - migrate_rename_annotation, - ) - - test_data = [ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name(), migrate_rename_annotation_data_one_to_one_mapping(), From 8b74351d380962cece2c9ef5f0530672e3eec45c Mon Sep 17 00:00:00 2001 From: Aclrian Date: Thu, 1 Dec 2022 18:00:56 +0000 Subject: [PATCH 02/13] style: apply automated linter fixes --- package-parser/tests/processing/migration/test_migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index 8c30ea4ea..41f64fce7 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -1,6 +1,6 @@ from typing import Callable -import pytest +import pytest from package_parser.processing.annotations.model import ( AbstractAnnotation, AnnotationStore, From 1e0d3cbed02307b271ece6cdb38b609a84f50d48 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Sun, 4 Dec 2022 14:04:47 +0100 Subject: [PATCH 03/13] rename .mypy.ini to mypy.ini --- .mypy.ini => mypy.ini | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .mypy.ini => mypy.ini (100%) diff --git a/.mypy.ini b/mypy.ini similarity index 100% rename from .mypy.ini rename to mypy.ini From 51075791e712bf2c4daf99cad30f0b8f76077bcb Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:44:36 +0100 Subject: [PATCH 04/13] back to 'real' work --- .../annotations/_migrate_todo_annotation.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py new file mode 100644 index 000000000..fb746611d --- /dev/null +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -0,0 +1,61 @@ +from copy import deepcopy + +from package_parser.processing.annotations.model import ( + AbstractAnnotation, + EnumReviewResult, + TodoAnnotation, +) +from package_parser.processing.api.model import Attribute, Result +from package_parser.processing.migration.model import ( + ManyToOneMapping, + Mapping, + OneToOneMapping, +) + +from ._constants import migration_author + + +def migrate_todo_annotation( + todo_annotation: TodoAnnotation, mapping: Mapping +) -> list[AbstractAnnotation]: + todo_annotation = deepcopy(todo_annotation) + authors = todo_annotation.authors + authors.append(migration_author) + todo_annotation.authors = authors + + if isinstance(mapping, (ManyToOneMapping, OneToOneMapping)): + element = mapping.get_apiv2_elements()[0] + if isinstance(element, (Attribute, Result)): + return [] + else: + todo_annotation.target = element.id + return [todo_annotation] + + migrate_text = ( + "The @Todo Annotation with the todo '" + + todo_annotation.newTodo + + "' from the previous version was at '" + + todo_annotation.target + + "' and the possible alternatives in the new version of the api are: " + + ", ".join( + map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) + ) + + todo_annotations: list[AbstractAnnotation] = [] + elements = [element.id for element in mapping.get_apiv2_elements() if not isinstance(element, (Attribute, Result))] + if todo_annotation.target in elements: + return [todo_annotation] + + for element in mapping.get_apiv2_elements(): + if not isinstance(element, (Attribute, Result)): + todo_annotations.append( + TodoAnnotation( + element.id, + authors, + todo_annotation.reviewers, + todo_annotation.comment, + EnumReviewResult.UNSURE, + migrate_text + ) + ) + return todo_annotations From de0883f80826c600f1b13fa8808ea37eb387caa5 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:48:33 +0100 Subject: [PATCH 05/13] fix linter error --- .../migration/annotations/_migrate_todo_annotation.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index fb746611d..38c7f72d6 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -27,9 +27,8 @@ def migrate_todo_annotation( element = mapping.get_apiv2_elements()[0] if isinstance(element, (Attribute, Result)): return [] - else: - todo_annotation.target = element.id - return [todo_annotation] + todo_annotation.target = element.id + return [todo_annotation] migrate_text = ( "The @Todo Annotation with the todo '" From 7dbc40bbace1226be5e14d6ff318e7f89e9b7a53 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:44:09 +0100 Subject: [PATCH 06/13] add tests and adjust migration --- .../processing/migration/_migrate.py | 11 +- .../migration/annotations/__init__.py | 1 + .../annotations/_migrate_todo_annotation.py | 13 +- .../annotations/test_rename_migration.py | 33 ++- .../annotations/test_todo_migration.py | 205 ++++++++++++++++++ .../processing/migration/test_migration.py | 70 ++++-- 6 files changed, 286 insertions(+), 47 deletions(-) create mode 100644 package-parser/tests/processing/migration/annotations/test_todo_migration.py diff --git a/package-parser/package_parser/processing/migration/_migrate.py b/package-parser/package_parser/processing/migration/_migrate.py index 5efce7ae2..814ab3099 100644 --- a/package-parser/package_parser/processing/migration/_migrate.py +++ b/package-parser/package_parser/processing/migration/_migrate.py @@ -5,7 +5,10 @@ AnnotationStore, ) from package_parser.processing.api.model import Attribute, Result -from package_parser.processing.migration.annotations import migrate_rename_annotation +from package_parser.processing.migration.annotations import ( + migrate_todo_annotation, + migrate_rename_annotation, +) from package_parser.processing.migration.model import Mapping @@ -33,4 +36,10 @@ def migrate_annotations( for annotation in migrate_rename_annotation(rename_annotation, mapping): migrated_annotation_store.add_annotation(annotation) + for todo_annotation in annotationsv1.todoAnnotations: + mapping = _get_mapping_from_annotation(todo_annotation, mappings) + if mapping is not None: + for annotation in migrate_todo_annotation(todo_annotation, mapping): + migrated_annotation_store.add_annotation(annotation) + return migrated_annotation_store diff --git a/package-parser/package_parser/processing/migration/annotations/__init__.py b/package-parser/package_parser/processing/migration/annotations/__init__.py index 46404f106..2d9760c63 100644 --- a/package-parser/package_parser/processing/migration/annotations/__init__.py +++ b/package-parser/package_parser/processing/migration/annotations/__init__.py @@ -1,2 +1,3 @@ from ._constants import migration_author from ._migrate_rename_annotation import migrate_rename_annotation +from ._migrate_todo_annotation import migrate_todo_annotation diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index 38c7f72d6..4e40ac607 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -7,6 +7,7 @@ ) from package_parser.processing.api.model import Attribute, Result from package_parser.processing.migration.model import ( + ManyToManyMapping, ManyToOneMapping, Mapping, OneToOneMapping, @@ -30,6 +31,7 @@ def migrate_todo_annotation( todo_annotation.target = element.id return [todo_annotation] + todo_annotations: list[AbstractAnnotation] = [] migrate_text = ( "The @Todo Annotation with the todo '" + todo_annotation.newTodo @@ -38,13 +40,8 @@ def migrate_todo_annotation( + "' and the possible alternatives in the new version of the api are: " + ", ".join( map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) - ) - - todo_annotations: list[AbstractAnnotation] = [] - elements = [element.id for element in mapping.get_apiv2_elements() if not isinstance(element, (Attribute, Result))] - if todo_annotation.target in elements: - return [todo_annotation] - + ) if isinstance(mapping, ManyToManyMapping) else todo_annotation.newTodo + review_result = EnumReviewResult.UNSURE if isinstance(mapping, ManyToManyMapping) else EnumReviewResult.NONE for element in mapping.get_apiv2_elements(): if not isinstance(element, (Attribute, Result)): todo_annotations.append( @@ -53,7 +50,7 @@ def migrate_todo_annotation( authors, todo_annotation.reviewers, todo_annotation.comment, - EnumReviewResult.UNSURE, + review_result, migrate_text ) ) diff --git a/package-parser/tests/processing/migration/annotations/test_rename_migration.py b/package-parser/tests/processing/migration/annotations/test_rename_migration.py index c23819a8c..b836124df 100644 --- a/package-parser/tests/processing/migration/annotations/test_rename_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_rename_migration.py @@ -1,4 +1,4 @@ -from typing import Callable, Tuple +from typing import Tuple from package_parser.processing.annotations.model import ( AbstractAnnotation, @@ -11,10 +11,7 @@ ParameterAssignment, ParameterDocumentation, ) -from package_parser.processing.migration.annotations import ( - migrate_rename_annotation, - migration_author, -) +from package_parser.processing.migration.annotations import migration_author from package_parser.processing.migration.model import ( Mapping, OneToManyMapping, @@ -26,7 +23,6 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ Mapping, AbstractAnnotation, list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], ]: parameterv1 = Parameter( id_="test/test.Test_", @@ -47,7 +43,7 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ documentation=ParameterDocumentation("", "", ""), ) mappings = OneToOneMapping(1.0, parameterv1, parameterv2) - annotationsv1 = RenameAnnotation( + annotationv1 = RenameAnnotation( target="test/test.Test_", authors=["testauthor"], reviewers=[], @@ -55,7 +51,7 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ reviewResult=EnumReviewResult.NONE, newName="TestE", ) - annotationsv2 = RenameAnnotation( + annotationv2 = RenameAnnotation( target="test/test.TestB", authors=["testauthor", migration_author], reviewers=[], @@ -63,14 +59,13 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ reviewResult=EnumReviewResult.NONE, newName="TestE", ) - return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation + return mappings, annotationv1, [annotationv2] def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() -> Tuple[ Mapping, AbstractAnnotation, list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], ]: parameterv1 = Parameter( id_="test/test.Test", @@ -100,7 +95,7 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() documentation=ParameterDocumentation("", "", ""), ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) - annotationsv1 = RenameAnnotation( + annotationv1 = RenameAnnotation( target="test/test.Test", authors=["testauthor"], reviewers=[], @@ -108,7 +103,7 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() reviewResult=EnumReviewResult.NONE, newName="TestA", ) - annotationsv2 = RenameAnnotation( + annotationv2 = RenameAnnotation( target="test/test.TestA", authors=["testauthor", migration_author], reviewers=[], @@ -116,14 +111,13 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() reviewResult=EnumReviewResult.UNSURE, newName="TestA", ) - return mappings, annotationsv1, [annotationsv2], migrate_rename_annotation + return mappings, annotationv1, [annotationv2] def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ Mapping, AbstractAnnotation, list[AbstractAnnotation], - Callable[[RenameAnnotation, Mapping], list[AbstractAnnotation]], ]: parameterv1 = Parameter( id_="test/test.Test", @@ -153,7 +147,7 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ documentation=ParameterDocumentation("", "", ""), ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) - annotationsv1 = RenameAnnotation( + annotationv1 = RenameAnnotation( target="test/test.Test", authors=["testauthor"], reviewers=[], @@ -161,7 +155,7 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ reviewResult=EnumReviewResult.NONE, newName="TestZ", ) - annotationsv2_a = TodoAnnotation( + annotationv2_a = TodoAnnotation( target="test/test.TestA", authors=["testauthor", migration_author], reviewers=[], @@ -169,7 +163,7 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ reviewResult=EnumReviewResult.NONE, newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", ) - annotationsv2_b = TodoAnnotation( + annotationv2_b = TodoAnnotation( target="test/test.TestB", authors=["testauthor", migration_author], reviewers=[], @@ -179,7 +173,6 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ ) return ( mappings, - annotationsv1, - [annotationsv2_a, annotationsv2_b], - migrate_rename_annotation, + annotationv1, + [annotationv2_a, annotationv2_b], ) diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py new file mode 100644 index 000000000..34d19ec1a --- /dev/null +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -0,0 +1,205 @@ +from typing import Callable, Tuple + +from package_parser.processing.annotations.model import ( + AbstractAnnotation, + EnumReviewResult, + TodoAnnotation, + TodoAnnotation, +) +from package_parser.processing.api.model import ( + Parameter, + ParameterAssignment, + ParameterDocumentation, +) +from package_parser.processing.migration import ManyToManyMapping +from package_parser.processing.migration.annotations import ( + migrate_todo_annotation, + migration_author, +) +from package_parser.processing.migration.model import ( + Mapping, + OneToManyMapping, + OneToOneMapping, +) + + +def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation] +]: + parameterv1 = Parameter( + id_="test/test.todo.Test1", + name="Test1", + qname="test.todo.Test1", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2 = Parameter( + id_="test/test.todo.Test2", + name="Test2", + qname="test.todo.Test2", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = OneToOneMapping(1.0, parameterv1, parameterv2) + annotationsv1 = TodoAnnotation( + target="test/test.todo.Test1", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2 = TodoAnnotation( + target="test/test.todo.Test2", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + return mappings, annotationsv1, [annotationsv2] + + +def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation], +]: + parameterv1 = Parameter( + id_="test/test.todo.Test3", + name="Test3", + qname="test.todo.Test3", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.todo.Test4", + name="Test4", + qname="test.todo.Test4", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.todo.Test5", + name="Test5", + qname="test.todo.Test5", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) + annotationsv1 = TodoAnnotation( + target="test/test.todo.Test3", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2_a = TodoAnnotation( + target="test/test.todo.Test4", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2_b = TodoAnnotation( + target="test/test.todo.Test5", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + return mappings, annotationsv1, [annotationsv2_a, annotationsv2_b] + + +def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation] +]: + parameterv1_a = Parameter( + id_="test/test.todo.Test6", + name="Test6", + qname="test.todo.Test6", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv1_b = Parameter( + id_="test/test.todo.Test7", + name="Test7", + qname="test.todo.Test7", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.todo.Test8", + name="Test8", + qname="test.todo.Test8", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.todo.Test9", + name="Test9", + qname="test.todo.Test9", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("", "", ""), + ) + mappings = ManyToManyMapping(1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b]) + annotationv1 = TodoAnnotation( + target="test/test.todo.Test6", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationv2_a = TodoAnnotation( + target="test/test.todo.Test8", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.UNSURE, + newTodo="The @Todo Annotation with the todo 'todo' from the " + "previous version was at 'test/test.todo.Test6' and " + 'the possible alternatives in the new version of the ' + 'api are: Test8, Test9', + ) + annotationv2_b = TodoAnnotation( + target="test/test.todo.Test9", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.UNSURE, + newTodo="The @Todo Annotation with the todo 'todo' from the " + "previous version was at 'test/test.todo.Test6' and " + 'the possible alternatives in the new version of the ' + 'api are: Test8, Test9', + ) + return ( + mappings, + annotationv1, + [annotationv2_a, annotationv2_b], + ) diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index 41f64fce7..335c7028a 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -1,6 +1,3 @@ -from typing import Callable - -import pytest from package_parser.processing.annotations.model import ( AbstractAnnotation, AnnotationStore, @@ -12,34 +9,71 @@ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name, migrate_rename_annotation_data_one_to_one_mapping, ) +from tests.processing.migration.annotations.test_todo_migration import ( + migrate_todo_annotation_data_one_to_many_mapping, + migrate_todo_annotation_data_one_to_one_mapping, + migrate_todo_annotation_data_many_to_many_mapping, +) test_data = [ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name(), migrate_rename_annotation_data_one_to_one_mapping(), migrate_rename_annotation_data_one_to_many_mapping(), + migrate_todo_annotation_data_one_to_one_mapping(), + migrate_todo_annotation_data_one_to_many_mapping(), + migrate_todo_annotation_data_many_to_many_mapping(), ] -@pytest.mark.parametrize( - "mappings,annotationv1,expected_annotationsv2,migrate", test_data -) -def test_migrate_annotations( - mappings: Mapping, - annotationv1: AbstractAnnotation, - expected_annotationsv2: list[AbstractAnnotation], - migrate: Callable[[AbstractAnnotation, Mapping], list[AbstractAnnotation]], -): - assert migrate(annotationv1, mappings) == expected_annotationsv2 - - -def test_migrate_all_annotations(): +def test_migrate_all_annotations() -> None: mappings: list[Mapping] = [] annotation_store: AnnotationStore = AnnotationStore() expected_annotation_store: AnnotationStore = AnnotationStore() - for mapping, annotationv1, annotationsv2, _ in test_data: + for mapping, annotationv1, annotationsv2 in test_data: mappings.append(mapping) annotation_store.add_annotation(annotationv1) for expected_annotation in annotationsv2: expected_annotation_store.add_annotation(expected_annotation) - assert migrate_annotations(annotation_store, mappings) == expected_annotation_store + + actual_annotations = migrate_annotations(annotation_store, mappings) + + def get_key(annotation: AbstractAnnotation) -> str: + return annotation.target + + assert sorted(actual_annotations.boundaryAnnotations, key=get_key) == sorted( + expected_annotation_store.boundaryAnnotations, key=get_key + ) + assert sorted(actual_annotations.calledAfterAnnotations, key=get_key) == sorted( + expected_annotation_store.calledAfterAnnotations, key=get_key + ) + assert sorted(actual_annotations.completeAnnotations, key=get_key) == sorted( + expected_annotation_store.completeAnnotations, key=get_key + ) + assert sorted(actual_annotations.descriptionAnnotations, key=get_key) == sorted( + expected_annotation_store.descriptionAnnotations, key=get_key + ) + assert sorted(actual_annotations.enumAnnotations, key=get_key) == sorted( + expected_annotation_store.enumAnnotations, key=get_key + ) + assert sorted(actual_annotations.groupAnnotations, key=get_key) == sorted( + expected_annotation_store.groupAnnotations, key=get_key + ) + assert sorted(actual_annotations.moveAnnotations, key=get_key) == sorted( + expected_annotation_store.moveAnnotations, key=get_key + ) + assert sorted(actual_annotations.pureAnnotations, key=get_key) == sorted( + expected_annotation_store.pureAnnotations, key=get_key + ) + assert sorted(actual_annotations.removeAnnotations, key=get_key) == sorted( + expected_annotation_store.removeAnnotations, key=get_key + ) + assert sorted(actual_annotations.renameAnnotations, key=get_key) == sorted( + expected_annotation_store.renameAnnotations, key=get_key + ) + assert sorted(actual_annotations.todoAnnotations, key=get_key) == sorted( + expected_annotation_store.todoAnnotations, key=get_key + ) + assert sorted(actual_annotations.valueAnnotations, key=get_key) == sorted( + expected_annotation_store.valueAnnotations, key=get_key + ) From c2059573af8ea5e1179460353040c8ab363ab858 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 14:12:59 +0100 Subject: [PATCH 07/13] fix linter errors --- mypy.ini => .mypy.ini | 2 +- .../annotations/_migrate_todo_annotation.py | 2 +- .../annotations/test_rename_migration.py | 40 +++++++++---------- .../annotations/test_todo_migration.py | 22 +++++----- 4 files changed, 32 insertions(+), 34 deletions(-) rename mypy.ini => .mypy.ini (84%) diff --git a/mypy.ini b/.mypy.ini similarity index 84% rename from mypy.ini rename to .mypy.ini index 215e42c94..bf5a80ac2 100644 --- a/mypy.ini +++ b/.mypy.ini @@ -4,4 +4,4 @@ disallow_untyped_calls = true disallow_untyped_decorators = true disallow_untyped_defs = true ignore_missing_imports = true -no_site_packages = true +no_namespace_packages = true diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index 4e40ac607..b529c5bc9 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -39,7 +39,7 @@ def migrate_todo_annotation( + todo_annotation.target + "' and the possible alternatives in the new version of the api are: " + ", ".join( - map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) + map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) ) if isinstance(mapping, ManyToManyMapping) else todo_annotation.newTodo review_result = EnumReviewResult.UNSURE if isinstance(mapping, ManyToManyMapping) else EnumReviewResult.NONE for element in mapping.get_apiv2_elements(): diff --git a/package-parser/tests/processing/migration/annotations/test_rename_migration.py b/package-parser/tests/processing/migration/annotations/test_rename_migration.py index b836124df..4beeb144f 100644 --- a/package-parser/tests/processing/migration/annotations/test_rename_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_rename_migration.py @@ -68,27 +68,27 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() list[AbstractAnnotation], ]: parameterv1 = Parameter( - id_="test/test.Test", + id_="test/test.rename.Test", name="Test", - qname="test.Test", + qname="test.rename.Test", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("", "", ""), ) parameterv2_a = Parameter( - id_="test/test.TestA", + id_="test/test.rename.TestA", name="TestA", - qname="test.TestA", + qname="test.rename.TestA", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("", "", ""), ) parameterv2_b = Parameter( - id_="test/test.TestB", + id_="test/test.rename.TestB", name="TestB", - qname="test.TestB", + qname="test.rename.TestB", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, @@ -96,7 +96,7 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) annotationv1 = RenameAnnotation( - target="test/test.Test", + target="test/test.rename.Test", authors=["testauthor"], reviewers=[], comment="", @@ -104,10 +104,10 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() newName="TestA", ) annotationv2 = RenameAnnotation( - target="test/test.TestA", + target="test/test.rename.TestA", authors=["testauthor", migration_author], reviewers=[], - comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB", reviewResult=EnumReviewResult.UNSURE, newName="TestA", ) @@ -120,27 +120,27 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ list[AbstractAnnotation], ]: parameterv1 = Parameter( - id_="test/test.Test", + id_="test/test.rename.Test", name="Test", - qname="test.Test", + qname="test.rename.Test", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("", "", ""), ) parameterv2_a = Parameter( - id_="test/test.TestA", + id_="test/test.rename.TestA", name="TestA", - qname="test.TestA", + qname="test.rename.TestA", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("", "", ""), ) parameterv2_b = Parameter( - id_="test/test.TestB", + id_="test/test.rename.TestB", name="TestB", - qname="test.TestB", + qname="test.rename.TestB", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, @@ -148,7 +148,7 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) annotationv1 = RenameAnnotation( - target="test/test.Test", + target="test/test.rename.Test", authors=["testauthor"], reviewers=[], comment="", @@ -156,20 +156,20 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[ newName="TestZ", ) annotationv2_a = TodoAnnotation( - target="test/test.TestA", + target="test/test.rename.TestA", authors=["testauthor", migration_author], reviewers=[], comment="", reviewResult=EnumReviewResult.NONE, - newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB", ) annotationv2_b = TodoAnnotation( - target="test/test.TestB", + target="test/test.rename.TestB", authors=["testauthor", migration_author], reviewers=[], comment="", reviewResult=EnumReviewResult.NONE, - newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB", + newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB", ) return ( mappings, diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py index 34d19ec1a..4502e5f72 100644 --- a/package-parser/tests/processing/migration/annotations/test_todo_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -1,10 +1,9 @@ -from typing import Callable, Tuple +from typing import Tuple from package_parser.processing.annotations.model import ( AbstractAnnotation, EnumReviewResult, TodoAnnotation, - TodoAnnotation, ) from package_parser.processing.api.model import ( Parameter, @@ -13,7 +12,6 @@ ) from package_parser.processing.migration import ManyToManyMapping from package_parser.processing.migration.annotations import ( - migrate_todo_annotation, migration_author, ) from package_parser.processing.migration.model import ( @@ -35,7 +33,7 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv2 = Parameter( id_="test/test.todo.Test2", @@ -44,7 +42,7 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) mappings = OneToOneMapping(1.0, parameterv1, parameterv2) annotationsv1 = TodoAnnotation( @@ -78,7 +76,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv2_a = Parameter( id_="test/test.todo.Test4", @@ -87,7 +85,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv2_b = Parameter( id_="test/test.todo.Test5", @@ -96,7 +94,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) annotationsv1 = TodoAnnotation( @@ -138,7 +136,7 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv1_b = Parameter( id_="test/test.todo.Test7", @@ -147,7 +145,7 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv2_a = Parameter( id_="test/test.todo.Test8", @@ -156,7 +154,7 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) parameterv2_b = Parameter( id_="test/test.todo.Test9", @@ -165,7 +163,7 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, - documentation=ParameterDocumentation("", "", ""), + documentation=ParameterDocumentation("str", "", ""), ) mappings = ManyToManyMapping(1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b]) annotationv1 = TodoAnnotation( From 618ea8e8acf7fc9e09fc3daed2ffd0bad2ccc043 Mon Sep 17 00:00:00 2001 From: Aclrian Date: Mon, 5 Dec 2022 13:15:50 +0000 Subject: [PATCH 08/13] style: apply automated linter fixes --- .../processing/migration/_migrate.py | 2 +- .../annotations/_migrate_todo_annotation.py | 29 ++++++++++++------- .../annotations/test_todo_migration.py | 28 ++++++++---------- .../processing/migration/test_migration.py | 2 +- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/package-parser/package_parser/processing/migration/_migrate.py b/package-parser/package_parser/processing/migration/_migrate.py index 814ab3099..3d8bb4ab6 100644 --- a/package-parser/package_parser/processing/migration/_migrate.py +++ b/package-parser/package_parser/processing/migration/_migrate.py @@ -6,8 +6,8 @@ ) from package_parser.processing.api.model import Attribute, Result from package_parser.processing.migration.annotations import ( - migrate_todo_annotation, migrate_rename_annotation, + migrate_todo_annotation, ) from package_parser.processing.migration.model import Mapping diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index b529c5bc9..15c7593bd 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -33,15 +33,24 @@ def migrate_todo_annotation( todo_annotations: list[AbstractAnnotation] = [] migrate_text = ( - "The @Todo Annotation with the todo '" - + todo_annotation.newTodo - + "' from the previous version was at '" - + todo_annotation.target - + "' and the possible alternatives in the new version of the api are: " - + ", ".join( - map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) - ) if isinstance(mapping, ManyToManyMapping) else todo_annotation.newTodo - review_result = EnumReviewResult.UNSURE if isinstance(mapping, ManyToManyMapping) else EnumReviewResult.NONE + ( + "The @Todo Annotation with the todo '" + + todo_annotation.newTodo + + "' from the previous version was at '" + + todo_annotation.target + + "' and the possible alternatives in the new version of the api are: " + + ", ".join( + map(lambda api_element: api_element.name, mapping.get_apiv2_elements()) + ) + ) + if isinstance(mapping, ManyToManyMapping) + else todo_annotation.newTodo + ) + review_result = ( + EnumReviewResult.UNSURE + if isinstance(mapping, ManyToManyMapping) + else EnumReviewResult.NONE + ) for element in mapping.get_apiv2_elements(): if not isinstance(element, (Attribute, Result)): todo_annotations.append( @@ -51,7 +60,7 @@ def migrate_todo_annotation( todo_annotation.reviewers, todo_annotation.comment, review_result, - migrate_text + migrate_text, ) ) return todo_annotations diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py index 4502e5f72..ba9ce9d06 100644 --- a/package-parser/tests/processing/migration/annotations/test_todo_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -11,9 +11,7 @@ ParameterDocumentation, ) from package_parser.processing.migration import ManyToManyMapping -from package_parser.processing.migration.annotations import ( - migration_author, -) +from package_parser.processing.migration.annotations import migration_author from package_parser.processing.migration.model import ( Mapping, OneToManyMapping, @@ -22,9 +20,7 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ - Mapping, - AbstractAnnotation, - list[AbstractAnnotation] + Mapping, AbstractAnnotation, list[AbstractAnnotation] ]: parameterv1 = Parameter( id_="test/test.todo.Test1", @@ -125,9 +121,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ - Mapping, - AbstractAnnotation, - list[AbstractAnnotation] + Mapping, AbstractAnnotation, list[AbstractAnnotation] ]: parameterv1_a = Parameter( id_="test/test.todo.Test6", @@ -165,7 +159,9 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ is_public=True, documentation=ParameterDocumentation("str", "", ""), ) - mappings = ManyToManyMapping(1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b]) + mappings = ManyToManyMapping( + 1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b] + ) annotationv1 = TodoAnnotation( target="test/test.todo.Test6", authors=["testauthor"], @@ -181,9 +177,9 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ comment="", reviewResult=EnumReviewResult.UNSURE, newTodo="The @Todo Annotation with the todo 'todo' from the " - "previous version was at 'test/test.todo.Test6' and " - 'the possible alternatives in the new version of the ' - 'api are: Test8, Test9', + "previous version was at 'test/test.todo.Test6' and " + "the possible alternatives in the new version of the " + "api are: Test8, Test9", ) annotationv2_b = TodoAnnotation( target="test/test.todo.Test9", @@ -192,9 +188,9 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ comment="", reviewResult=EnumReviewResult.UNSURE, newTodo="The @Todo Annotation with the todo 'todo' from the " - "previous version was at 'test/test.todo.Test6' and " - 'the possible alternatives in the new version of the ' - 'api are: Test8, Test9', + "previous version was at 'test/test.todo.Test6' and " + "the possible alternatives in the new version of the " + "api are: Test8, Test9", ) return ( mappings, diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index 335c7028a..fff0aab9c 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -10,9 +10,9 @@ migrate_rename_annotation_data_one_to_one_mapping, ) from tests.processing.migration.annotations.test_todo_migration import ( + migrate_todo_annotation_data_many_to_many_mapping, migrate_todo_annotation_data_one_to_many_mapping, migrate_todo_annotation_data_one_to_one_mapping, - migrate_todo_annotation_data_many_to_many_mapping, ) test_data = [ From 5c992e2bc75a32bf5c1df0b824c3b018a3b909a0 Mon Sep 17 00:00:00 2001 From: Aclrian Date: Mon, 5 Dec 2022 17:04:02 +0000 Subject: [PATCH 09/13] style: apply automated linter fixes --- .../package_parser/processing/migration/_migrate.py | 2 +- .../tests/processing/migration/test_migration.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package-parser/package_parser/processing/migration/_migrate.py b/package-parser/package_parser/processing/migration/_migrate.py index 938e83842..f9273a2c3 100644 --- a/package-parser/package_parser/processing/migration/_migrate.py +++ b/package-parser/package_parser/processing/migration/_migrate.py @@ -6,9 +6,9 @@ ) from package_parser.processing.api.model import Attribute, Result from package_parser.processing.migration.annotations import ( + migrate_enum_annotation, migrate_rename_annotation, migrate_todo_annotation, - migrate_enum_annotation, ) from package_parser.processing.migration.model import Mapping diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index 4ca84a88c..360021a62 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -9,16 +9,16 @@ migrate_enum_annotation_data_one_to_many_mapping__only_one_relevant_mapping, migrate_enum_annotation_data_one_to_one_mapping, ) -from tests.processing.migration.annotations.test_todo_migration import ( - migrate_todo_annotation_data_many_to_many_mapping, - migrate_todo_annotation_data_one_to_many_mapping, - migrate_todo_annotation_data_one_to_one_mapping, -) from tests.processing.migration.annotations.test_rename_migration import ( migrate_rename_annotation_data_one_to_many_mapping, migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name, migrate_rename_annotation_data_one_to_one_mapping, ) +from tests.processing.migration.annotations.test_todo_migration import ( + migrate_todo_annotation_data_many_to_many_mapping, + migrate_todo_annotation_data_one_to_many_mapping, + migrate_todo_annotation_data_one_to_one_mapping, +) test_data = [ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name(), @@ -30,7 +30,6 @@ migrate_enum_annotation_data_one_to_one_mapping(), migrate_enum_annotation_data_one_to_many_mapping(), migrate_enum_annotation_data_one_to_many_mapping__only_one_relevant_mapping(), - ] From 27bc4d94c32824cd08f4f536148b3120202c25c0 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 18:42:51 +0100 Subject: [PATCH 10/13] inspect type of annotated element --- .../annotations/_migrate_todo_annotation.py | 41 ++++--- .../annotations/test_todo_migration.py | 107 ++++++++++-------- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index 15c7593bd..0c4b8fc59 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -31,35 +31,34 @@ def migrate_todo_annotation( todo_annotation.target = element.id return [todo_annotation] + target_type = None + for element in mapping.get_apiv1_elements(): + if not isinstance(element, (Attribute, Result)) and element.id: + target_type = element.__class__ + migrate_text = "The @Todo Annotation with the todo '" + todo_annotation.newTodo + "' from the previous version was at '" + todo_annotation.target + "' and the possible alternatives in the new version of the api are: " + ", ".join( + map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) + todo_annotations: list[AbstractAnnotation] = [] - migrate_text = ( - ( - "The @Todo Annotation with the todo '" - + todo_annotation.newTodo - + "' from the previous version was at '" - + todo_annotation.target - + "' and the possible alternatives in the new version of the api are: " - + ", ".join( - map(lambda api_element: api_element.name, mapping.get_apiv2_elements()) - ) - ) - if isinstance(mapping, ManyToManyMapping) - else todo_annotation.newTodo - ) - review_result = ( - EnumReviewResult.UNSURE - if isinstance(mapping, ManyToManyMapping) - else EnumReviewResult.NONE - ) for element in mapping.get_apiv2_elements(): - if not isinstance(element, (Attribute, Result)): + if isinstance(element, target_type): + todo_annotations.append( + TodoAnnotation( + element.id, + authors, + todo_annotation.reviewers, + todo_annotation.comment, + EnumReviewResult.NONE, + todo_annotation.newTodo, + ) + ) + elif not isinstance(element, (Attribute, Result)): todo_annotations.append( TodoAnnotation( element.id, authors, todo_annotation.reviewers, todo_annotation.comment, - review_result, + EnumReviewResult.UNSURE, migrate_text, ) ) diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py index ba9ce9d06..a1a5d6fb2 100644 --- a/package-parser/tests/processing/migration/annotations/test_todo_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -8,7 +8,7 @@ from package_parser.processing.api.model import ( Parameter, ParameterAssignment, - ParameterDocumentation, + ParameterDocumentation, Class, ClassDocumentation, ) from package_parser.processing.migration import ManyToManyMapping from package_parser.processing.migration.annotations import migration_author @@ -23,18 +23,18 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ Mapping, AbstractAnnotation, list[AbstractAnnotation] ]: parameterv1 = Parameter( - id_="test/test.todo.Test1", + id_="test/test.todo.test1.Test", name="Test1", - qname="test.todo.Test1", + qname="test.todo.test1.Test", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv2 = Parameter( - id_="test/test.todo.Test2", - name="Test2", - qname="test.todo.Test2", + id_="test/test.todo.test1.Test", + name="Test", + qname="test.todo.test1.Test", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, @@ -42,7 +42,7 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ ) mappings = OneToOneMapping(1.0, parameterv1, parameterv2) annotationsv1 = TodoAnnotation( - target="test/test.todo.Test1", + target="test/test.todo.test1.Test", authors=["testauthor"], reviewers=[], comment="", @@ -50,7 +50,7 @@ def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ newTodo="todo", ) annotationsv2 = TodoAnnotation( - target="test/test.todo.Test2", + target="test/test.todo.test1.Test", authors=["testauthor", migration_author], reviewers=[], comment="", @@ -66,27 +66,27 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ list[AbstractAnnotation], ]: parameterv1 = Parameter( - id_="test/test.todo.Test3", - name="Test3", - qname="test.todo.Test3", + id_="test/test.todo.test2.Test", + name="Test", + qname="test.todo.test1.Test", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv2_a = Parameter( - id_="test/test.todo.Test4", - name="Test4", - qname="test.todo.Test4", + id_="test/test.todo.test2.TestA", + name="TestA", + qname="test.todo.test2.TestA", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv2_b = Parameter( - id_="test/test.todo.Test5", - name="Test5", - qname="test.todo.Test5", + id_="test/test.todo.test2.TestB", + name="TestB", + qname="test.todo.test2.TestB", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, @@ -94,7 +94,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ ) mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) annotationsv1 = TodoAnnotation( - target="test/test.todo.Test3", + target="test/test.todo.test2.Test", authors=["testauthor"], reviewers=[], comment="", @@ -102,7 +102,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ newTodo="todo", ) annotationsv2_a = TodoAnnotation( - target="test/test.todo.Test4", + target="test/test.todo.test2.TestA", authors=["testauthor", migration_author], reviewers=[], comment="", @@ -110,7 +110,7 @@ def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ newTodo="todo", ) annotationsv2_b = TodoAnnotation( - target="test/test.todo.Test5", + target="test/test.todo.test2.TestB", authors=["testauthor", migration_author], reviewers=[], comment="", @@ -124,46 +124,57 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ Mapping, AbstractAnnotation, list[AbstractAnnotation] ]: parameterv1_a = Parameter( - id_="test/test.todo.Test6", - name="Test6", - qname="test.todo.Test6", + id_="test/test.todo.test3.TestA", + name="TestA", + qname="test.todo.test3.TestA", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv1_b = Parameter( - id_="test/test.todo.Test7", - name="Test7", - qname="test.todo.Test7", + id_="test/test.todo.test3.TestB", + name="TestB", + qname="test.todo.test3.TestB", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv2_a = Parameter( - id_="test/test.todo.Test8", - name="Test8", - qname="test.todo.Test8", + id_="test/test.todo.test3.NewTestA", + name="NewTestA", + qname="test.todo.test3.NewTestA", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) parameterv2_b = Parameter( - id_="test/test.todo.Test9", - name="Test9", - qname="test.todo.Test9", + id_="test/test.todo.test3.NewTestB", + name="NewTestB", + qname="test.todo.test3.NewTestB", default_value=None, assigned_by=ParameterAssignment.POSITION_OR_NAME, is_public=True, documentation=ParameterDocumentation("str", "", ""), ) + classv2 = Class( + id_="test/test.todo.test3.TestClass", + qname="test.todo.test3.TestClass", + decorators=[], + superclasses=[], + is_public=True, + reexported_by=[], + documentation=ClassDocumentation("", ""), + code="", + instance_attributes=[], + ) mappings = ManyToManyMapping( - 1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b] + 1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b, classv2] ) annotationv1 = TodoAnnotation( - target="test/test.todo.Test6", + target="test/test.todo.test3.TestA", authors=["testauthor"], reviewers=[], comment="", @@ -171,29 +182,35 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ newTodo="todo", ) annotationv2_a = TodoAnnotation( - target="test/test.todo.Test8", + target="test/test.todo.test3.NewTestA", authors=["testauthor", migration_author], reviewers=[], comment="", - reviewResult=EnumReviewResult.UNSURE, - newTodo="The @Todo Annotation with the todo 'todo' from the " - "previous version was at 'test/test.todo.Test6' and " - "the possible alternatives in the new version of the " - "api are: Test8, Test9", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", ) annotationv2_b = TodoAnnotation( - target="test/test.todo.Test9", + target="test/test.todo.test3.NewTestB", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationv2_class = TodoAnnotation( + target="test/test.todo.test3.TestClass", authors=["testauthor", migration_author], reviewers=[], comment="", reviewResult=EnumReviewResult.UNSURE, newTodo="The @Todo Annotation with the todo 'todo' from the " - "previous version was at 'test/test.todo.Test6' and " - "the possible alternatives in the new version of the " - "api are: Test8, Test9", + "previous version was at 'test/test.todo.test3.TestA' " + 'and the possible alternatives in the new version of ' + 'the api are: NewTestA, NewTestB, TestClass', + ) return ( mappings, annotationv1, - [annotationv2_a, annotationv2_b], + [annotationv2_a, annotationv2_b, annotationv2_class], ) From feab4e122bdf5fdec42364eba2cc1358a9303eeb Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 19:09:37 +0100 Subject: [PATCH 11/13] maually apply styple changes and fix linter errors --- .../annotations/_migrate_todo_annotation.py | 22 ++++++++++++++----- .../annotations/test_todo_migration.py | 11 +++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index 0c4b8fc59..711aa4ce7 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -7,7 +7,6 @@ ) from package_parser.processing.api.model import Attribute, Result from package_parser.processing.migration.model import ( - ManyToManyMapping, ManyToOneMapping, Mapping, OneToOneMapping, @@ -31,16 +30,27 @@ def migrate_todo_annotation( todo_annotation.target = element.id return [todo_annotation] - target_type = None + annotated_apiv1_element = None for element in mapping.get_apiv1_elements(): if not isinstance(element, (Attribute, Result)) and element.id: - target_type = element.__class__ - migrate_text = "The @Todo Annotation with the todo '" + todo_annotation.newTodo + "' from the previous version was at '" + todo_annotation.target + "' and the possible alternatives in the new version of the api are: " + ", ".join( - map(lambda api_element: api_element.name, mapping.get_apiv2_elements())) + annotated_apiv1_element = element + migrate_text = ( + "The @Todo Annotation with the todo '" + + todo_annotation.newTodo + + "' from the previous version was at '" + + todo_annotation.target + + "' and the possible alternatives in the new version of the api are: " + + ", ".join( + map(lambda api_element: api_element.name, mapping.get_apiv2_elements()) + ) + ) todo_annotations: list[AbstractAnnotation] = [] for element in mapping.get_apiv2_elements(): - if isinstance(element, target_type): + if ( + annotated_apiv1_element is None + or isinstance(element, type(annotated_apiv1_element)) + ) and not isinstance(element, (Attribute, Result)): todo_annotations.append( TodoAnnotation( element.id, diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py index a1a5d6fb2..9c3725a77 100644 --- a/package-parser/tests/processing/migration/annotations/test_todo_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -6,9 +6,11 @@ TodoAnnotation, ) from package_parser.processing.api.model import ( + Class, + ClassDocumentation, Parameter, ParameterAssignment, - ParameterDocumentation, Class, ClassDocumentation, + ParameterDocumentation, ) from package_parser.processing.migration import ManyToManyMapping from package_parser.processing.migration.annotations import migration_author @@ -204,10 +206,9 @@ def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ comment="", reviewResult=EnumReviewResult.UNSURE, newTodo="The @Todo Annotation with the todo 'todo' from the " - "previous version was at 'test/test.todo.test3.TestA' " - 'and the possible alternatives in the new version of ' - 'the api are: NewTestA, NewTestB, TestClass', - + "previous version was at 'test/test.todo.test3.TestA' " + "and the possible alternatives in the new version of " + "the api are: NewTestA, NewTestB, TestClass", ) return ( mappings, From 277f2aa9e355781c1f140e725698ac0c54d9a897 Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 19:27:16 +0100 Subject: [PATCH 12/13] ignore special case --- .../migration/annotations/_migrate_todo_annotation.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index 711aa4ce7..a5282f8bb 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -47,10 +47,9 @@ def migrate_todo_annotation( todo_annotations: list[AbstractAnnotation] = [] for element in mapping.get_apiv2_elements(): - if ( - annotated_apiv1_element is None - or isinstance(element, type(annotated_apiv1_element)) - ) and not isinstance(element, (Attribute, Result)): + if isinstance(element, type(annotated_apiv1_element)) and not isinstance( + element, (Attribute, Result) + ): todo_annotations.append( TodoAnnotation( element.id, From 8eb7a598c9a22f3d87713b4b6d32707d15cb6a9c Mon Sep 17 00:00:00 2001 From: Aclrian <32142988+Aclrian@users.noreply.github.com> Date: Mon, 5 Dec 2022 19:44:01 +0100 Subject: [PATCH 13/13] keep reviewers and comments --- .../annotations/_migrate_enum_annotation.py | 15 ++++++++++----- .../annotations/_migrate_rename_annotation.py | 7 ++++++- .../annotations/_migrate_todo_annotation.py | 9 +++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py index 9301f7329..19c8c687b 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py @@ -95,7 +95,12 @@ def migrate_enum_annotation( return [enum_annotation] return [ TodoAnnotation( - parameter.id, authors, [], "", EnumReviewResult.NONE, migrate_text + parameter.id, + authors, + enum_annotation.reviewers, + enum_annotation.comment, + EnumReviewResult.NONE, + migrate_text, ) ] @@ -113,8 +118,8 @@ def migrate_enum_annotation( EnumAnnotation( parameter.id, authors, - [], - "", + enum_annotation.reviewers, + enum_annotation.comment, EnumReviewResult.NONE, enum_annotation.enumName, enum_annotation.pairs, @@ -127,8 +132,8 @@ def migrate_enum_annotation( TodoAnnotation( parameter.id, authors, - [], - "", + enum_annotation.reviewers, + enum_annotation.comment, EnumReviewResult.UNSURE, migrate_text, ) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py index bad401591..e5c51b51f 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py @@ -58,7 +58,12 @@ def migrate_rename_annotation( return [rename_annotation] todo_annotations.append( TodoAnnotation( - element.id, authors, [], "", EnumReviewResult.NONE, migrate_text + element.id, + authors, + rename_annotation.reviewers, + rename_annotation.comment, + EnumReviewResult.NONE, + migrate_text, ) ) return todo_annotations diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py index a5282f8bb..985d3851b 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -30,10 +30,6 @@ def migrate_todo_annotation( todo_annotation.target = element.id return [todo_annotation] - annotated_apiv1_element = None - for element in mapping.get_apiv1_elements(): - if not isinstance(element, (Attribute, Result)) and element.id: - annotated_apiv1_element = element migrate_text = ( "The @Todo Annotation with the todo '" + todo_annotation.newTodo @@ -45,6 +41,11 @@ def migrate_todo_annotation( ) ) + annotated_apiv1_element = None + for element in mapping.get_apiv1_elements(): + if not isinstance(element, (Attribute, Result)) and element.id: + annotated_apiv1_element = element + todo_annotations: list[AbstractAnnotation] = [] for element in mapping.get_apiv2_elements(): if isinstance(element, type(annotated_apiv1_element)) and not isinstance(