|
32 | 32 | from pathlib import Path |
33 | 33 | from unittest import TestCase |
34 | 34 |
|
35 | | -from pyEDAA.ProjectModel import Design, FileSet, File, Project, FileTypes |
| 35 | +from pyEDAA.ProjectModel import Design, FileSet, File, Project, FileTypes, Attribute |
36 | 36 | from pyEDAA.ProjectModel.Attributes import KeyValueAttribute |
37 | 37 |
|
38 | 38 |
|
@@ -155,14 +155,57 @@ def test_File(self): |
155 | 155 | file.Validate() |
156 | 156 |
|
157 | 157 |
|
| 158 | +class Attr(Attribute): |
| 159 | + pass |
| 160 | + |
| 161 | + |
158 | 162 | class Attributes(TestCase): |
| 163 | + def test_AddAttribute_WrongType(self): |
| 164 | + file = File(Path("file.txt")) |
| 165 | + |
| 166 | + with self.assertRaises(TypeError): |
| 167 | + file["attr"] = 5 |
| 168 | + |
| 169 | + def test_AddAttribute_Normal(self): |
| 170 | + file = File(Path("file.txt")) |
| 171 | + |
| 172 | + file[Attr] = 5 |
| 173 | + |
| 174 | + def test_GetAttribute_WrongType(self): |
| 175 | + file = File(Path("file.txt")) |
| 176 | + file[Attr] = 5 |
| 177 | + |
| 178 | + with self.assertRaises(TypeError): |
| 179 | + _ = file["attr"] |
| 180 | + |
| 181 | + def test_GetAttribute_Normal(self): |
| 182 | + file = File(Path("file.txt")) |
| 183 | + file[Attr] = 5 |
| 184 | + |
| 185 | + _ = file[Attr] |
| 186 | + |
| 187 | + def test_DelAttribute_WrongType(self): |
| 188 | + file = File(Path("file.txt")) |
| 189 | + file[Attr] = 5 |
| 190 | + |
| 191 | + with self.assertRaises(TypeError): |
| 192 | + del file["attr"] |
| 193 | + |
| 194 | + def test_DelAttribute_Normal(self): |
| 195 | + file = File(Path("file.txt")) |
| 196 | + file[Attr] = 5 |
| 197 | + |
| 198 | + del file[Attr] |
| 199 | + |
| 200 | + |
| 201 | +class AttributeResolution(TestCase): |
159 | 202 | def test_AttachedToFile(self): |
160 | 203 | project = Project("project", rootDirectory=Path("project")) |
161 | 204 | design = Design("design", directory=Path("designA"), project=project) |
162 | 205 | fileSet = FileSet("fileset", design=design) |
163 | 206 | file = File(Path("file_A1.vhdl"), fileSet=fileSet) |
164 | 207 |
|
165 | | - file._attributes[KeyValueAttribute] = KeyValueAttribute() |
| 208 | + file[KeyValueAttribute] = KeyValueAttribute() |
166 | 209 |
|
167 | 210 | attribute = file[KeyValueAttribute] |
168 | 211 | attribute["id1"] = "5" |
|
0 commit comments