diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-19 22:07:02 +0100 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-23 23:44:14 +0100 |
commit | 5853a37df7c9468a01d62f7b2eeee7d9773e72ca (patch) | |
tree | 8294b3c6850caa35070084c67d8c0d172981da85 /testsuite/pyunit/dom/Simple.py | |
parent | 09b985a65469e28d46cf05a3d7e4957be84f69c7 (diff) | |
download | ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.tar.gz ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.tar.bz2 ghdl-5853a37df7c9468a01d62f7b2eeee7d9773e72ca.zip |
Restructured test example sourcefiles.
Diffstat (limited to 'testsuite/pyunit/dom/Simple.py')
-rw-r--r-- | testsuite/pyunit/dom/Simple.py | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/testsuite/pyunit/dom/Simple.py b/testsuite/pyunit/dom/Simple.py new file mode 100644 index 000000000..32033609d --- /dev/null +++ b/testsuite/pyunit/dom/Simple.py @@ -0,0 +1,140 @@ +# ============================================================================= +# ____ _ _ ____ _ _ +# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___ +# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \ +# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | | +# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_| +# |_| |___/ +# ============================================================================= +# 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 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) + + +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 = design.Documents[0].Entities[0] + 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 = design.Documents[0].Architectures[0] + 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 = design.Documents[0].Packages[0] + 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 = design.Documents[0].PackageBodies[0] + self.assertEqual("utilities", packageBodies.Identifier) + print() + print(packageBodies.Documentation) + self.assertEqual(0, len(packageBodies.Documentation.splitlines())) |