|
| 1 | +from typing import Tuple |
| 2 | + |
| 3 | +from package_parser.processing.annotations.model import ( |
| 4 | + AbstractAnnotation, |
| 5 | + EnumAnnotation, |
| 6 | + EnumPair, |
| 7 | + EnumReviewResult, |
| 8 | + TodoAnnotation, |
| 9 | +) |
| 10 | +from package_parser.processing.api.model import ( |
| 11 | + Parameter, |
| 12 | + ParameterAssignment, |
| 13 | + ParameterDocumentation, |
| 14 | +) |
| 15 | +from package_parser.processing.migration import ( |
| 16 | + Mapping, |
| 17 | + OneToManyMapping, |
| 18 | + OneToOneMapping, |
| 19 | +) |
| 20 | +from package_parser.processing.migration.annotations import migration_author |
| 21 | + |
| 22 | + |
| 23 | +def migrate_enum_annotation_data_one_to_one_mapping() -> Tuple[ |
| 24 | + Mapping, |
| 25 | + AbstractAnnotation, |
| 26 | + list[AbstractAnnotation], |
| 27 | +]: |
| 28 | + parameterv1 = Parameter( |
| 29 | + id_="test/test.enum.test1.TestA", |
| 30 | + name="TestA", |
| 31 | + qname="test.enum.test1.TestA", |
| 32 | + default_value="value", |
| 33 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 34 | + is_public=True, |
| 35 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 36 | + ) |
| 37 | + parameterv2 = Parameter( |
| 38 | + id_="test/test.enum.test1.TestB", |
| 39 | + name="TestB", |
| 40 | + qname="test.enum.test1.TestB", |
| 41 | + default_value="value", |
| 42 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 43 | + is_public=True, |
| 44 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 45 | + ) |
| 46 | + mapping = OneToOneMapping(1.0, parameterv1, parameterv2) |
| 47 | + enum_annotation = EnumAnnotation( |
| 48 | + target="test/test.enum.test1.TestA", |
| 49 | + authors=["testauthor"], |
| 50 | + reviewers=[], |
| 51 | + comment="", |
| 52 | + reviewResult=EnumReviewResult.NONE, |
| 53 | + enumName="EnumName", |
| 54 | + pairs=[EnumPair("value", "name")], |
| 55 | + ) |
| 56 | + migrated_enum_annotation = EnumAnnotation( |
| 57 | + target="test/test.enum.test1.TestB", |
| 58 | + authors=["testauthor", migration_author], |
| 59 | + reviewers=[], |
| 60 | + comment="", |
| 61 | + reviewResult=EnumReviewResult.NONE, |
| 62 | + enumName="EnumName", |
| 63 | + pairs=[EnumPair("value", "name")], |
| 64 | + ) |
| 65 | + return mapping, enum_annotation, [migrated_enum_annotation] |
| 66 | + |
| 67 | + |
| 68 | +def migrate_enum_annotation_data_one_to_many_mapping() -> Tuple[ |
| 69 | + Mapping, |
| 70 | + AbstractAnnotation, |
| 71 | + list[AbstractAnnotation], |
| 72 | +]: |
| 73 | + parameterv1 = Parameter( |
| 74 | + id_="test/test.enum.test2.Test", |
| 75 | + name="Test", |
| 76 | + qname="test.enum.test2.Test", |
| 77 | + default_value="value", |
| 78 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 79 | + is_public=True, |
| 80 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 81 | + ) |
| 82 | + parameterv2_a = Parameter( |
| 83 | + id_="test/test.enum.test2.TestA", |
| 84 | + name="TestA", |
| 85 | + qname="test.enum.test2.TestA", |
| 86 | + default_value="value", |
| 87 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 88 | + is_public=True, |
| 89 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 90 | + ) |
| 91 | + parameterv2_b = Parameter( |
| 92 | + id_="test/test.enum.test2.TestB", |
| 93 | + name="TestB", |
| 94 | + qname="test.enum.test2.TestB", |
| 95 | + default_value="value", |
| 96 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 97 | + is_public=True, |
| 98 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 99 | + ) |
| 100 | + mapping = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) |
| 101 | + enum_annotation = EnumAnnotation( |
| 102 | + target="test/test.enum.test2.Test", |
| 103 | + authors=["testauthor"], |
| 104 | + reviewers=[], |
| 105 | + comment="", |
| 106 | + reviewResult=EnumReviewResult.NONE, |
| 107 | + enumName="EnumName", |
| 108 | + pairs=[EnumPair("value", "name")], |
| 109 | + ) |
| 110 | + migrated_enum_annotation = EnumAnnotation( |
| 111 | + target="test/test.enum.test2.TestA", |
| 112 | + authors=["testauthor", migration_author], |
| 113 | + reviewers=[], |
| 114 | + comment="", |
| 115 | + reviewResult=EnumReviewResult.NONE, |
| 116 | + enumName="EnumName", |
| 117 | + pairs=[EnumPair("value", "name")], |
| 118 | + ) |
| 119 | + migrated_enum_annotation_2 = EnumAnnotation( |
| 120 | + target="test/test.enum.test2.TestB", |
| 121 | + authors=["testauthor", migration_author], |
| 122 | + reviewers=[], |
| 123 | + comment="", |
| 124 | + reviewResult=EnumReviewResult.NONE, |
| 125 | + enumName="EnumName", |
| 126 | + pairs=[EnumPair("value", "name")], |
| 127 | + ) |
| 128 | + return ( |
| 129 | + mapping, |
| 130 | + enum_annotation, |
| 131 | + [migrated_enum_annotation, migrated_enum_annotation_2], |
| 132 | + ) |
| 133 | + |
| 134 | + |
| 135 | +def migrate_enum_annotation_data_one_to_many_mapping__only_one_relevant_mapping() -> Tuple[ |
| 136 | + Mapping, |
| 137 | + AbstractAnnotation, |
| 138 | + list[AbstractAnnotation], |
| 139 | +]: |
| 140 | + parameterv1 = Parameter( |
| 141 | + id_="test/test.enum.test3.Test", |
| 142 | + name="Test", |
| 143 | + qname="test.enum.test3.Test", |
| 144 | + default_value="value", |
| 145 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 146 | + is_public=True, |
| 147 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 148 | + ) |
| 149 | + parameterv2_a = Parameter( |
| 150 | + id_="test/test.enum.test3.TestA", |
| 151 | + name="TestA", |
| 152 | + qname="test.enum.test3.TestA", |
| 153 | + default_value="", |
| 154 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 155 | + is_public=True, |
| 156 | + documentation=ParameterDocumentation("", "", ""), |
| 157 | + ) |
| 158 | + parameterv2_b = Parameter( |
| 159 | + id_="test/test.enum.test3.TestB", |
| 160 | + name="TestB", |
| 161 | + qname="test.enum.test3.TestB", |
| 162 | + default_value="value", |
| 163 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 164 | + is_public=True, |
| 165 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 166 | + ) |
| 167 | + parameterv2_c = Parameter( |
| 168 | + id_="test/test.enum.test3.TestC", |
| 169 | + name="TestC", |
| 170 | + qname="test.enum.test3.TestC", |
| 171 | + default_value="0", |
| 172 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 173 | + is_public=True, |
| 174 | + documentation=ParameterDocumentation("int", "0", "docstring"), |
| 175 | + ) |
| 176 | + mapping = OneToManyMapping( |
| 177 | + 1.0, parameterv1, [parameterv2_a, parameterv2_b, parameterv2_c] |
| 178 | + ) |
| 179 | + enum_annotation = EnumAnnotation( |
| 180 | + target="test/test.enum.test3.Test", |
| 181 | + authors=["testauthor"], |
| 182 | + reviewers=[], |
| 183 | + comment="", |
| 184 | + reviewResult=EnumReviewResult.NONE, |
| 185 | + enumName="EnumName", |
| 186 | + pairs=[EnumPair("value", "name")], |
| 187 | + ) |
| 188 | + migrated_enum_annotation = EnumAnnotation( |
| 189 | + target="test/test.enum.test3.TestB", |
| 190 | + authors=["testauthor", migration_author], |
| 191 | + reviewers=[], |
| 192 | + reviewResult=EnumReviewResult.NONE, |
| 193 | + comment="", |
| 194 | + enumName="EnumName", |
| 195 | + pairs=[EnumPair("value", "name")], |
| 196 | + ) |
| 197 | + migrated_todo_annotation = TodoAnnotation( |
| 198 | + target="test/test.enum.test3.TestA", |
| 199 | + authors=["testauthor", migration_author], |
| 200 | + reviewers=[], |
| 201 | + reviewResult=EnumReviewResult.UNSURE, |
| 202 | + comment="", |
| 203 | + newTodo="The @Enum Annotation with the new name 'EnumName " |
| 204 | + "(value, name)' from the previous version was at " |
| 205 | + "'test/test.enum.test3.Test' and the possible " |
| 206 | + "alternatives in the new version of the api are: " |
| 207 | + "TestA, TestB, TestC", |
| 208 | + ) |
| 209 | + return ( |
| 210 | + mapping, |
| 211 | + enum_annotation, |
| 212 | + [migrated_enum_annotation, migrated_todo_annotation], |
| 213 | + ) |
0 commit comments