diff options
author | tgingold <tgingold@users.noreply.github.com> | 2022-12-24 08:56:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 08:56:55 +0100 |
commit | 26bb3c572eaffafafd8de8ef09b8acc34f91656f (patch) | |
tree | 2d70696f4f8bb78f9a4fda7a6d596775fdf080cc /testsuite/pyunit/dom/Simple.py | |
parent | 8845f761ed2299e595afd5eee2444fed7fb79639 (diff) | |
parent | 5d9897770cb16494c6379cce85ed5935532c0cd1 (diff) | |
download | ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.gz ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.bz2 ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.zip |
Merge pull request #2265 from Paebbels/paebbels/DOM-with-documentation
pyGHDL.dom with Documentation
Diffstat (limited to 'testsuite/pyunit/dom/Simple.py')
-rw-r--r-- | testsuite/pyunit/dom/Simple.py | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/testsuite/pyunit/dom/Simple.py b/testsuite/pyunit/dom/Simple.py new file mode 100644 index 000000000..82dd8579e --- /dev/null +++ b/testsuite/pyunit/dom/Simple.py @@ -0,0 +1,148 @@ +# ============================================================================= +# ____ _ _ ____ _ _ +# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___ +# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \ +# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | | +# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_| +# |_| |___/ +# ============================================================================= +# Authors: +# Patrick Lehmann +# +# Testsuite: Check libghdl IIR translation with a simple entity. +# +# License: +# ============================================================================ +# Copyright (C) 2019-2021 Tristan Gingold +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-2.0-or-later +# ============================================================================ +from pathlib import Path +from typing import TypeVar, Dict +from unittest import TestCase + +from pyGHDL.dom.NonStandard import Design, Document + + +if __name__ == "__main__": + print("ERROR: you called a testcase declaration file as an executable module.") + print("Use: 'python -m unitest <testcase module>'") + exit(1) + + +_DictKey = TypeVar("_DictKey") +_DictValue = TypeVar("_DictValue") + +def firstValue(d: Dict[_DictKey, _DictValue]) -> _DictValue: + return next(iter(d.values())) + + +class SimpleEntity(TestCase): + _root = Path(__file__).resolve().parent.parent + _filename: Path = _root / "dom/examples/SimpleEntity.vhdl" + + def test_Design(self): + design = Design() + + self.assertIsNotNone(design) + + # def test_Library(self): + # library = Library() + + def test_Document(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents)) + print() + print(document.Documentation) + self.assertEqual(4, len(document.Documentation.splitlines())) + + def test_Entity(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents[0].Entities)) + + entity = firstValue(design.Documents[0].Entities) + self.assertEqual("Counter", entity.Identifier) + print() + print(entity.Documentation) + self.assertEqual(11, len(entity.Documentation.splitlines())) + + def test_Architecture(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents[0].Architectures)) + + architecture = firstValue(firstValue(design.Documents[0].Architectures)) + self.assertEqual("rtl", architecture.Identifier) + print() + print(architecture.Documentation) + self.assertEqual(1, len(architecture.Documentation.splitlines())) + + +class SimplePackage(TestCase): + _root = Path(__file__).resolve().parent.parent + _filename: Path = _root / "dom/examples/SimplePackage.vhdl" + + def test_Design(self): + design = Design() + + self.assertIsNotNone(design) + + # def test_Library(self): + # library = Library() + + def test_Document(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents)) + print() + print(document.Documentation) + self.assertEqual(4, len(document.Documentation.splitlines())) + + def test_Package(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents[0].Packages)) + + package = firstValue(design.Documents[0].Packages) + self.assertEqual("utilities", package.Identifier) + print() + print(package.Documentation) + self.assertEqual(1, len(package.Documentation.splitlines())) + + def test_PackageBody(self): + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(1, len(design.Documents[0].PackageBodies)) + + packageBodies = firstValue(design.Documents[0].PackageBodies) + self.assertEqual("utilities", packageBodies.Identifier) + print() + print(packageBodies.Documentation) + self.assertEqual(0, len(packageBodies.Documentation.splitlines())) |