Skip to content

Commit

Permalink
Added more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Aug 24, 2023
1 parent 2655010 commit 3d65107
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 5 deletions.
45 changes: 44 additions & 1 deletion tests/unit/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from pySVModel import SystemVerilogVersion
from pyVHDLModel import VHDLVersion

from pyEDAA.ProjectModel import Design, File, Project
from pyEDAA.ProjectModel import Design, File, Project, Attribute


if __name__ == "__main__": # pragma: no cover
Expand Down Expand Up @@ -145,3 +145,46 @@ def test_Design(self):
design = Design("design", directory=Path("designA"), project=project)

design.Validate()


class Attr(Attribute):
pass


class Attributes(TestCase):
def test_AddAttribute_WrongType(self):
design = Design("design")

with self.assertRaises(TypeError):
design["attr"] = 5

def test_AddAttribute_Normal(self):
design = Design("design")

design[Attr] = 5

def test_GetAttribute_WrongType(self):
design = Design("design")
design[Attr] = 5

with self.assertRaises(TypeError):
_ = design["attr"]

def test_GetAttribute_Normal(self):
design = Design("design")
design[Attr] = 5

_ = design[Attr]

def test_DelAttribute_WrongType(self):
design = Design("design")
design[Attr] = 5

with self.assertRaises(TypeError):
del design["attr"]

def test_DelAttribute_Normal(self):
design = Design("design")
design[Attr] = 5

del design[Attr]
47 changes: 45 additions & 2 deletions tests/unit/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pathlib import Path
from unittest import TestCase

from pyEDAA.ProjectModel import Design, FileSet, File, Project, FileTypes
from pyEDAA.ProjectModel import Design, FileSet, File, Project, FileTypes, Attribute
from pyEDAA.ProjectModel.Attributes import KeyValueAttribute


Expand Down Expand Up @@ -155,14 +155,57 @@ def test_File(self):
file.Validate()


class Attr(Attribute):
pass


class Attributes(TestCase):
def test_AddAttribute_WrongType(self):
file = File(Path("file.txt"))

with self.assertRaises(TypeError):
file["attr"] = 5

def test_AddAttribute_Normal(self):
file = File(Path("file.txt"))

file[Attr] = 5

def test_GetAttribute_WrongType(self):
file = File(Path("file.txt"))
file[Attr] = 5

with self.assertRaises(TypeError):
_ = file["attr"]

def test_GetAttribute_Normal(self):
file = File(Path("file.txt"))
file[Attr] = 5

_ = file[Attr]

def test_DelAttribute_WrongType(self):
file = File(Path("file.txt"))
file[Attr] = 5

with self.assertRaises(TypeError):
del file["attr"]

def test_DelAttribute_Normal(self):
file = File(Path("file.txt"))
file[Attr] = 5

del file[Attr]


class AttributeResolution(TestCase):
def test_AttachedToFile(self):
project = Project("project", rootDirectory=Path("project"))
design = Design("design", directory=Path("designA"), project=project)
fileSet = FileSet("fileset", design=design)
file = File(Path("file_A1.vhdl"), fileSet=fileSet)

file._attributes[KeyValueAttribute] = KeyValueAttribute()
file[KeyValueAttribute] = KeyValueAttribute()

attribute = file[KeyValueAttribute]
attribute["id1"] = "5"
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/FileSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
from pySVModel import SystemVerilogVersion
from pyVHDLModel import VHDLVersion

from pyEDAA.ProjectModel import Design, FileSet, File, FileTypes, TextFile, Project, VHDLLibrary, Attribute
from pyEDAA.ProjectModel import Design, FileSet, File, FileTypes, TextFile, Project, VHDLLibrary, Attribute
from pyEDAA.ProjectModel.Attributes import KeyValueAttribute


if __name__ == "__main__": # pragma: no cover
print("ERROR: you called a testcase declaration file as an executable module.")
Expand Down
45 changes: 44 additions & 1 deletion tests/unit/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from pySVModel import SystemVerilogVersion
from pyVHDLModel import VHDLVersion

from pyEDAA.ProjectModel import Project
from pyEDAA.ProjectModel import Project, Attribute


if __name__ == "__main__": # pragma: no cover
Expand Down Expand Up @@ -113,3 +113,46 @@ def test_Project(self):
project = Project("project", rootDirectory=Path("project"))

project.Validate()


class Attr(Attribute):
pass


class Attributes(TestCase):
def test_AddAttribute_WrongType(self):
project = Project("project")

with self.assertRaises(TypeError):
project["attr"] = 5

def test_AddAttribute_Normal(self):
project = Project("project")

project[Attr] = 5

def test_GetAttribute_WrongType(self):
project = Project("project")
project[Attr] = 5

with self.assertRaises(TypeError):
_ = project["attr"]

def test_GetAttribute_Normal(self):
project = Project("project")
project[Attr] = 5

_ = project[Attr]

def test_DelAttribute_WrongType(self):
project = Project("project")
project[Attr] = 5

with self.assertRaises(TypeError):
del project["attr"]

def test_DelAttribute_Normal(self):
project = Project("project")
project[Attr] = 5

del project[Attr]

0 comments on commit 3d65107

Please sign in to comment.