|
| 1 | +from typing import Tuple |
| 2 | + |
| 3 | +from package_parser.processing.annotations.model import ( |
| 4 | + AbstractAnnotation, |
| 5 | + DescriptionAnnotation, |
| 6 | + EnumReviewResult, |
| 7 | + TodoAnnotation, |
| 8 | +) |
| 9 | +from package_parser.processing.api.model import ( |
| 10 | + Class, |
| 11 | + ClassDocumentation, |
| 12 | + Function, |
| 13 | + FunctionDocumentation, |
| 14 | + Parameter, |
| 15 | + ParameterAssignment, |
| 16 | + ParameterDocumentation, |
| 17 | +) |
| 18 | +from package_parser.processing.migration import ( |
| 19 | + Mapping, |
| 20 | + OneToManyMapping, |
| 21 | + OneToOneMapping, |
| 22 | +) |
| 23 | +from package_parser.processing.migration.annotations import ( |
| 24 | + get_migration_text, |
| 25 | + migration_author, |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +# pylint: disable=duplicate-code |
| 30 | +def migrate_description_annotation_data_one_to_one_mapping__function() -> Tuple[ |
| 31 | + Mapping, |
| 32 | + AbstractAnnotation, |
| 33 | + list[AbstractAnnotation], |
| 34 | +]: |
| 35 | + functionv1 = Function( |
| 36 | + id="test/test.description.test1.test/test", |
| 37 | + qname="test.description.test1.test.test", |
| 38 | + decorators=[], |
| 39 | + parameters=[], |
| 40 | + results=[], |
| 41 | + is_public=True, |
| 42 | + reexported_by=[], |
| 43 | + documentation=FunctionDocumentation("", ""), |
| 44 | + code="", |
| 45 | + ) |
| 46 | + |
| 47 | + functionv2 = Function( |
| 48 | + id="test/test.description.test1.test/new_test", |
| 49 | + qname="test.description.test1.test.new_test", |
| 50 | + decorators=[], |
| 51 | + parameters=[], |
| 52 | + results=[], |
| 53 | + is_public=True, |
| 54 | + reexported_by=[], |
| 55 | + documentation=FunctionDocumentation("", ""), |
| 56 | + code="", |
| 57 | + ) |
| 58 | + |
| 59 | + mapping = OneToOneMapping(1.0, functionv1, functionv2) |
| 60 | + |
| 61 | + annotationv1 = DescriptionAnnotation( |
| 62 | + target="test/test.description.test1.test/test", |
| 63 | + authors=["testauthor"], |
| 64 | + reviewers=[], |
| 65 | + comment="", |
| 66 | + reviewResult=EnumReviewResult.NONE, |
| 67 | + newDescription="lightbringer", |
| 68 | + ) |
| 69 | + annotationv2 = DescriptionAnnotation( |
| 70 | + target="test/test.description.test1.test/new_test", |
| 71 | + authors=["testauthor", migration_author], |
| 72 | + reviewers=[], |
| 73 | + comment="", |
| 74 | + reviewResult=EnumReviewResult.NONE, |
| 75 | + newDescription="lightbringer", |
| 76 | + ) |
| 77 | + return mapping, annotationv1, [annotationv2] |
| 78 | + |
| 79 | + |
| 80 | +# pylint: disable=duplicate-code |
| 81 | +def migrate_description_annotation_data_one_to_many_mapping__class() -> Tuple[ |
| 82 | + Mapping, |
| 83 | + AbstractAnnotation, |
| 84 | + list[AbstractAnnotation], |
| 85 | +]: |
| 86 | + |
| 87 | + classv1 = Class( |
| 88 | + id_="test/test.description.test2.test/DescriptionTestClass", |
| 89 | + qname="test.description.test2.test.DescriptionTestClass", |
| 90 | + decorators=[], |
| 91 | + superclasses=[], |
| 92 | + is_public=True, |
| 93 | + reexported_by=[], |
| 94 | + documentation=ClassDocumentation("", ""), |
| 95 | + code="class DescriptionTestClass:\n pass", |
| 96 | + instance_attributes=[], |
| 97 | + ) |
| 98 | + classv2_a = Class( |
| 99 | + id_="test/test.description.test2.test/NewDescriptionTestClass", |
| 100 | + qname="test.description.test2.test.NewDescriptionTestClass", |
| 101 | + decorators=[], |
| 102 | + superclasses=[], |
| 103 | + is_public=True, |
| 104 | + reexported_by=[], |
| 105 | + documentation=ClassDocumentation("", ""), |
| 106 | + code="class NewDescriptionTestClass:\n pass", |
| 107 | + instance_attributes=[], |
| 108 | + ) |
| 109 | + classv2_b = Class( |
| 110 | + id_="test/test.description.test2.test/NewDescriptionTestClass2", |
| 111 | + qname="test.description.test2.test.NewDescriptionTestClass2", |
| 112 | + decorators=[], |
| 113 | + superclasses=[], |
| 114 | + is_public=True, |
| 115 | + reexported_by=[], |
| 116 | + documentation=ClassDocumentation("", ""), |
| 117 | + code="class NewDescriptionTestClass2:\n pass", |
| 118 | + instance_attributes=[], |
| 119 | + ) |
| 120 | + functionv2 = Function( |
| 121 | + id="test/test.description.test2.test/TestClass/new_test", |
| 122 | + qname="test.description.test2.test.TestClass.new_test", |
| 123 | + decorators=[], |
| 124 | + parameters=[], |
| 125 | + results=[], |
| 126 | + is_public=True, |
| 127 | + reexported_by=[], |
| 128 | + documentation=FunctionDocumentation("", ""), |
| 129 | + code="", |
| 130 | + ) |
| 131 | + |
| 132 | + mapping = OneToManyMapping(1.0, classv1, [classv2_a, classv2_b, functionv2]) |
| 133 | + |
| 134 | + annotationv1 = DescriptionAnnotation( |
| 135 | + target="test/test.description.test2.test/DescriptionTestClass", |
| 136 | + authors=["testauthor"], |
| 137 | + reviewers=[], |
| 138 | + comment="", |
| 139 | + reviewResult=EnumReviewResult.NONE, |
| 140 | + newDescription="42", |
| 141 | + ) |
| 142 | + annotationv2_a = DescriptionAnnotation( |
| 143 | + target="test/test.description.test2.test/NewDescriptionTestClass", |
| 144 | + authors=["testauthor", migration_author], |
| 145 | + reviewers=[], |
| 146 | + comment="", |
| 147 | + reviewResult=EnumReviewResult.NONE, |
| 148 | + newDescription="42", |
| 149 | + ) |
| 150 | + annotationv2_b = DescriptionAnnotation( |
| 151 | + target="test/test.description.test2.test/NewDescriptionTestClass2", |
| 152 | + authors=["testauthor", migration_author], |
| 153 | + reviewers=[], |
| 154 | + comment="", |
| 155 | + reviewResult=EnumReviewResult.NONE, |
| 156 | + newDescription="42", |
| 157 | + ) |
| 158 | + annotationv2_c = TodoAnnotation( |
| 159 | + target="test/test.description.test2.test/TestClass/new_test", |
| 160 | + authors=["testauthor", migration_author], |
| 161 | + reviewers=[], |
| 162 | + comment="", |
| 163 | + reviewResult=EnumReviewResult.NONE, |
| 164 | + newTodo=get_migration_text(annotationv1, mapping), |
| 165 | + ) |
| 166 | + return mapping, annotationv1, [annotationv2_a, annotationv2_b, annotationv2_c] |
| 167 | + |
| 168 | + |
| 169 | +def migrate_description_annotation_data_one_to_one_mapping__parameter() -> Tuple[ |
| 170 | + Mapping, |
| 171 | + AbstractAnnotation, |
| 172 | + list[AbstractAnnotation], |
| 173 | +]: |
| 174 | + parameterv1 = Parameter( |
| 175 | + id_="test/test.description.test3/test.test", |
| 176 | + qname="test.description.test3.test.test", |
| 177 | + name="test", |
| 178 | + default_value="value", |
| 179 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 180 | + is_public=True, |
| 181 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 182 | + ) |
| 183 | + |
| 184 | + parameterv2 = Parameter( |
| 185 | + id_="test/test.description.test3/test.new_test", |
| 186 | + qname="test.description.test3.test.new_test", |
| 187 | + name="new_test", |
| 188 | + default_value="value", |
| 189 | + assigned_by=ParameterAssignment.POSITION_OR_NAME, |
| 190 | + is_public=True, |
| 191 | + documentation=ParameterDocumentation("str", "value", "docstring"), |
| 192 | + ) |
| 193 | + |
| 194 | + mapping = OneToOneMapping(1.0, parameterv1, parameterv2) |
| 195 | + |
| 196 | + annotationv1 = DescriptionAnnotation( |
| 197 | + target="test/test.description.test3/test.test", |
| 198 | + authors=["testauthor"], |
| 199 | + reviewers=[], |
| 200 | + comment="", |
| 201 | + reviewResult=EnumReviewResult.NONE, |
| 202 | + newDescription="test description", |
| 203 | + ) |
| 204 | + annotationv2 = DescriptionAnnotation( |
| 205 | + target="test/test.description.test3/test.new_test", |
| 206 | + authors=["testauthor", migration_author], |
| 207 | + reviewers=[], |
| 208 | + comment="", |
| 209 | + reviewResult=EnumReviewResult.NONE, |
| 210 | + newDescription="test description", |
| 211 | + ) |
| 212 | + return mapping, annotationv1, [annotationv2] |
0 commit comments