| 106 | |
| 107 | |
| 108 | def test_copied_schema(): |
| 109 | code = """ |
| 110 | import copy |
| 111 | |
| 112 | class ActionAPI(object): |
| 113 | schema = {"properties": {"action": {}}} |
| 114 | |
| 115 | class ActionCreateAPI(object): |
| 116 | schema = copy.deepcopy(ActionAPI.schema) |
| 117 | schema["properties"]["default_files"] = {} |
| 118 | """ |
| 119 | |
| 120 | res = parse(code) |
| 121 | |
| 122 | assert isinstance(res, nodes.Module) |
| 123 | |
| 124 | class1_node: nodes.ClassDef = res.body[1] |
| 125 | assert isinstance(class1_node, nodes.ClassDef) |
| 126 | |
| 127 | assert "schema" in class1_node.locals |
| 128 | |
| 129 | # action property added but not property from the other class |
| 130 | assert "action" in class1_node.locals |
| 131 | assert "default_files" not in class1_node.locals |
| 132 | |
| 133 | class2_node: nodes.ClassDef = res.body[2] |
| 134 | assert isinstance(class2_node, nodes.ClassDef) |
| 135 | |
| 136 | # action (copied) and default_files (added) properties added |
| 137 | assert "schema" in class2_node.locals |
| 138 | assert "action" in class2_node.locals |
| 139 | assert "default_files" in class2_node.locals |
| 140 | |
| 141 | |
| 142 | def test_copied_imported_schema(): |