From 67b957d4f41226fdfc787434c2ebb2738229d0f3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 27 Aug 2020 00:33:31 +0000 Subject: [PATCH] tests: move out of the main package. Compared to tests in the repository root, tests in the package have many downsides: * Unless explicitly excluded in find_packages(), tests and their support code effectively become a part of public API. This, unfortunately, happened with FHDLTestCase, which was never intended for downstream use. * Even if explicitly excluded from the setuptools package, using an editable install, or setting PYTHONPATH still allows accessing the tests. * Having a sub-package that is present in the source tree but not exported (or, worse, exported only sometimes) is confusing. * The name `nmigen.test` cannot be used for anything else, such as testing utilities that *are* intended for downstream use. --- .gitignore | 2 +- setup.py | 2 +- {nmigen/test => tests}/__init__.py | 0 {nmigen/test => tests}/compat/__init__.py | 0 {nmigen/test => tests}/compat/support.py | 6 +++--- {nmigen/test => tests}/compat/test_coding.py | 4 ++-- {nmigen/test => tests}/compat/test_constant.py | 3 ++- {nmigen/test => tests}/compat/test_fifo.py | 4 ++-- {nmigen/test => tests}/compat/test_fsm.py | 4 ++-- {nmigen/test => tests}/compat/test_passive.py | 2 +- .../compat/test_run_simulation.py | 4 +++- {nmigen/test => tests}/compat/test_signed.py | 3 ++- {nmigen/test => tests}/compat/test_size.py | 4 ++-- {nmigen/test => tests}/test_build_dsl.py | 3 ++- {nmigen/test => tests}/test_build_plat.py | 5 +++-- {nmigen/test => tests}/test_build_res.py | 11 ++++++----- {nmigen/test => tests}/test_compat.py | 5 +++-- {nmigen/test => tests}/test_examples.py | 9 ++++----- {nmigen/test => tests}/test_hdl_ast.py | 3 ++- {nmigen/test => tests}/test_hdl_cd.py | 3 ++- {nmigen/test => tests}/test_hdl_dsl.py | 7 ++++--- {nmigen/test => tests}/test_hdl_ir.py | 9 +++++---- {nmigen/test => tests}/test_hdl_mem.py | 5 +++-- {nmigen/test => tests}/test_hdl_rec.py | 5 +++-- {nmigen/test => tests}/test_hdl_xfrm.py | 11 ++++++----- {nmigen/test => tests}/test_lib_cdc.py | 7 ++++--- {nmigen/test => tests}/test_lib_coding.py | 9 +++++---- {nmigen/test => tests}/test_lib_fifo.py | 9 +++++---- {nmigen/test => tests}/test_lib_io.py | 9 +++++---- {nmigen/test => tests}/test_lib_scheduler.py | 11 +++++++---- {nmigen/test => tests}/test_sim.py | 17 +++++++++-------- {nmigen/test => tests}/utils.py | 9 ++++----- 32 files changed, 103 insertions(+), 82 deletions(-) rename {nmigen/test => tests}/__init__.py (100%) rename {nmigen/test => tests}/compat/__init__.py (100%) rename {nmigen/test => tests}/compat/support.py (74%) rename {nmigen/test => tests}/compat/test_coding.py (98%) rename {nmigen/test => tests}/compat/test_constant.py (96%) rename {nmigen/test => tests}/compat/test_fifo.py (94%) rename {nmigen/test => tests}/compat/test_fsm.py (97%) rename {nmigen/test => tests}/compat/test_passive.py (94%) rename {nmigen/test => tests}/compat/test_run_simulation.py (92%) rename {nmigen/test => tests}/compat/test_signed.py (97%) rename {nmigen/test => tests}/compat/test_size.py (86%) rename {nmigen/test => tests}/test_build_dsl.py (99%) rename {nmigen/test => tests}/test_build_plat.py (96%) rename {nmigen/test => tests}/test_build_res.py (98%) rename {nmigen/test => tests}/test_compat.py (70%) rename {nmigen/test => tests}/test_examples.py (74%) rename {nmigen/test => tests}/test_hdl_ast.py (99%) rename {nmigen/test => tests}/test_hdl_cd.py (98%) rename {nmigen/test => tests}/test_hdl_dsl.py (99%) rename {nmigen/test => tests}/test_hdl_ir.py (99%) rename {nmigen/test => tests}/test_hdl_mem.py (98%) rename {nmigen/test => tests}/test_hdl_rec.py (99%) rename {nmigen/test => tests}/test_hdl_xfrm.py (99%) rename {nmigen/test => tests}/test_lib_cdc.py (98%) rename {nmigen/test => tests}/test_lib_coding.py (96%) rename {nmigen/test => tests}/test_lib_fifo.py (98%) rename {nmigen/test => tests}/test_lib_io.py (98%) rename {nmigen/test => tests}/test_lib_scheduler.py (96%) rename {nmigen/test => tests}/test_sim.py (99%) rename {nmigen/test => tests}/utils.py (94%) diff --git a/.gitignore b/.gitignore index 7c2e9bc..d11a3eb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ __pycache__/ /htmlcov # tests -**/test/spec_*/ +/tests/spec_*/ *.vcd *.gtkw diff --git a/setup.py b/setup.py index d08cddd..69b3d04 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ setup( "builtin-yosys": ["nmigen-yosys>=0.9.*"], "remote-build": ["paramiko~=2.7"], }, - packages=find_packages(exclude=["*.test*"]), + packages=find_packages(), entry_points={ "console_scripts": [ "nmigen-rpc = nmigen.rpc:main", diff --git a/nmigen/test/__init__.py b/tests/__init__.py similarity index 100% rename from nmigen/test/__init__.py rename to tests/__init__.py diff --git a/nmigen/test/compat/__init__.py b/tests/compat/__init__.py similarity index 100% rename from nmigen/test/compat/__init__.py rename to tests/compat/__init__.py diff --git a/nmigen/test/compat/support.py b/tests/compat/support.py similarity index 74% rename from nmigen/test/compat/support.py rename to tests/compat/support.py index 8491652..05923f8 100644 --- a/nmigen/test/compat/support.py +++ b/tests/compat/support.py @@ -1,6 +1,6 @@ -from ..._utils import _ignore_deprecated -from ...compat import * -from ...compat.fhdl import verilog +from nmigen.compat import * +from nmigen.compat.fhdl import verilog +from nmigen._utils import _ignore_deprecated class SimCase: diff --git a/nmigen/test/compat/test_coding.py b/tests/compat/test_coding.py similarity index 98% rename from nmigen/test/compat/test_coding.py rename to tests/compat/test_coding.py index 452a048..a65dea6 100644 --- a/nmigen/test/compat/test_coding.py +++ b/tests/compat/test_coding.py @@ -2,8 +2,8 @@ import unittest -from ...compat import * -from ...compat.genlib.coding import * +from nmigen.compat import * +from nmigen.compat.genlib.coding import * from .support import SimCase diff --git a/nmigen/test/compat/test_constant.py b/tests/compat/test_constant.py similarity index 96% rename from nmigen/test/compat/test_constant.py rename to tests/compat/test_constant.py index e18c207..238c723 100644 --- a/nmigen/test/compat/test_constant.py +++ b/tests/compat/test_constant.py @@ -1,6 +1,7 @@ import unittest -from ...compat import * +from nmigen.compat import * + from .support import SimCase diff --git a/nmigen/test/compat/test_fifo.py b/tests/compat/test_fifo.py similarity index 94% rename from nmigen/test/compat/test_fifo.py rename to tests/compat/test_fifo.py index bc6b81c..6cff7dc 100644 --- a/nmigen/test/compat/test_fifo.py +++ b/tests/compat/test_fifo.py @@ -1,8 +1,8 @@ import unittest from itertools import count -from ...compat import * -from ...compat.genlib.fifo import SyncFIFO +from nmigen.compat import * +from nmigen.compat.genlib.fifo import SyncFIFO from .support import SimCase diff --git a/nmigen/test/compat/test_fsm.py b/tests/compat/test_fsm.py similarity index 97% rename from nmigen/test/compat/test_fsm.py rename to tests/compat/test_fsm.py index 58de5be..8fbf47b 100644 --- a/nmigen/test/compat/test_fsm.py +++ b/tests/compat/test_fsm.py @@ -1,8 +1,8 @@ import unittest from itertools import count -from ...compat import * -from ...compat.genlib.fsm import FSM +from nmigen.compat import * +from nmigen.compat.genlib.fsm import FSM from .support import SimCase diff --git a/nmigen/test/compat/test_passive.py b/tests/compat/test_passive.py similarity index 94% rename from nmigen/test/compat/test_passive.py rename to tests/compat/test_passive.py index da3483b..c030f70 100644 --- a/nmigen/test/compat/test_passive.py +++ b/tests/compat/test_passive.py @@ -1,6 +1,6 @@ import unittest -from ...compat import * +from nmigen.compat import * class PassiveCase(unittest.TestCase): diff --git a/nmigen/test/compat/test_run_simulation.py b/tests/compat/test_run_simulation.py similarity index 92% rename from nmigen/test/compat/test_run_simulation.py rename to tests/compat/test_run_simulation.py index 0c33413..0857e75 100644 --- a/nmigen/test/compat/test_run_simulation.py +++ b/tests/compat/test_run_simulation.py @@ -1,5 +1,7 @@ import unittest -from ... import Signal, Module, Elaboratable + +from nmigen import Signal, Module, Elaboratable + from .support import SimCase diff --git a/nmigen/test/compat/test_signed.py b/tests/compat/test_signed.py similarity index 97% rename from nmigen/test/compat/test_signed.py rename to tests/compat/test_signed.py index 0eaaea0..f0a8c61 100644 --- a/nmigen/test/compat/test_signed.py +++ b/tests/compat/test_signed.py @@ -1,6 +1,7 @@ import unittest -from ...compat import * +from nmigen.compat import * + from .support import SimCase diff --git a/nmigen/test/compat/test_size.py b/tests/compat/test_size.py similarity index 86% rename from nmigen/test/compat/test_size.py rename to tests/compat/test_size.py index e3864f9..8211aa9 100644 --- a/nmigen/test/compat/test_size.py +++ b/tests/compat/test_size.py @@ -1,7 +1,7 @@ import unittest -from ..._utils import _ignore_deprecated -from ...compat import * +from nmigen._utils import _ignore_deprecated +from nmigen.compat import * def _same_slices(a, b): diff --git a/nmigen/test/test_build_dsl.py b/tests/test_build_dsl.py similarity index 99% rename from nmigen/test/test_build_dsl.py rename to tests/test_build_dsl.py index 87f082a..76cd2e9 100644 --- a/nmigen/test/test_build_dsl.py +++ b/tests/test_build_dsl.py @@ -1,6 +1,7 @@ from collections import OrderedDict -from ..build.dsl import * +from nmigen.build.dsl import * + from .utils import * diff --git a/nmigen/test/test_build_plat.py b/tests/test_build_plat.py similarity index 96% rename from nmigen/test/test_build_plat.py rename to tests/test_build_plat.py index 1342501..31dc5c9 100644 --- a/nmigen/test/test_build_plat.py +++ b/tests/test_build_plat.py @@ -1,5 +1,6 @@ -from .. import * -from ..build.plat import * +from nmigen import * +from nmigen.build.plat import * + from .utils import * diff --git a/nmigen/test/test_build_res.py b/tests/test_build_res.py similarity index 98% rename from nmigen/test/test_build_res.py rename to tests/test_build_res.py index 740d468..ac8f7bd 100644 --- a/nmigen/test/test_build_res.py +++ b/tests/test_build_res.py @@ -1,10 +1,11 @@ # nmigen: UnusedElaboratable=no -from .. import * -from ..hdl.rec import * -from ..lib.io import * -from ..build.dsl import * -from ..build.res import * +from nmigen import * +from nmigen.hdl.rec import * +from nmigen.lib.io import * +from nmigen.build.dsl import * +from nmigen.build.res import * + from .utils import * diff --git a/nmigen/test/test_compat.py b/tests/test_compat.py similarity index 70% rename from nmigen/test/test_compat.py rename to tests/test_compat.py index 62e2d92..aeb1617 100644 --- a/nmigen/test/test_compat.py +++ b/tests/test_compat.py @@ -1,5 +1,6 @@ -from ..hdl.ir import Fragment -from ..compat import * +from nmigen.hdl.ir import Fragment +from nmigen.compat import * + from .utils import * diff --git a/nmigen/test/test_examples.py b/tests/test_examples.py similarity index 74% rename from nmigen/test/test_examples.py rename to tests/test_examples.py index 44211d3..7bc1198 100644 --- a/nmigen/test/test_examples.py +++ b/tests/test_examples.py @@ -6,7 +6,7 @@ from .utils import * def example_test(name): - path = (Path(__file__).parent / ".." / ".." / "examples" / name).resolve() + path = (Path(__file__).parent / ".." / "examples" / name).resolve() def test_function(self): subprocess.check_call([sys.executable, str(path), "generate", "-t", "v"], stdout=subprocess.DEVNULL) @@ -28,7 +28,6 @@ class ExamplesTestCase(FHDLTestCase): test_por = example_test("basic/por.py") def test_uart(self): - path = (Path(__file__).parent / ".." / ".." / "examples" / "basic" / "uart.py").resolve() - def test_function(self): - subprocess.check_call([sys.executable, str(path), "generate"], - stdout=subprocess.DEVNULL) + path = (Path(__file__).parent / ".." / "examples" / "basic" / "uart.py").resolve() + subprocess.check_call([sys.executable, str(path), "generate"], + stdout=subprocess.DEVNULL) diff --git a/nmigen/test/test_hdl_ast.py b/tests/test_hdl_ast.py similarity index 99% rename from nmigen/test/test_hdl_ast.py rename to tests/test_hdl_ast.py index af96e16..f14c07b 100644 --- a/nmigen/test/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -1,7 +1,8 @@ import warnings from enum import Enum -from ..hdl.ast import * +from nmigen.hdl.ast import * + from .utils import * diff --git a/nmigen/test/test_hdl_cd.py b/tests/test_hdl_cd.py similarity index 98% rename from nmigen/test/test_hdl_cd.py rename to tests/test_hdl_cd.py index 8927e08..4e93fbc 100644 --- a/nmigen/test/test_hdl_cd.py +++ b/tests/test_hdl_cd.py @@ -1,4 +1,5 @@ -from ..hdl.cd import * +from nmigen.hdl.cd import * + from .utils import * diff --git a/nmigen/test/test_hdl_dsl.py b/tests/test_hdl_dsl.py similarity index 99% rename from nmigen/test/test_hdl_dsl.py rename to tests/test_hdl_dsl.py index 454415d..8ec1be7 100644 --- a/nmigen/test/test_hdl_dsl.py +++ b/tests/test_hdl_dsl.py @@ -3,9 +3,10 @@ from collections import OrderedDict from enum import Enum -from ..hdl.ast import * -from ..hdl.cd import * -from ..hdl.dsl import * +from nmigen.hdl.ast import * +from nmigen.hdl.cd import * +from nmigen.hdl.dsl import * + from .utils import * diff --git a/nmigen/test/test_hdl_ir.py b/tests/test_hdl_ir.py similarity index 99% rename from nmigen/test/test_hdl_ir.py rename to tests/test_hdl_ir.py index ab8bdd8..dc3b730 100644 --- a/nmigen/test/test_hdl_ir.py +++ b/tests/test_hdl_ir.py @@ -2,10 +2,11 @@ from collections import OrderedDict -from ..hdl.ast import * -from ..hdl.cd import * -from ..hdl.ir import * -from ..hdl.mem import * +from nmigen.hdl.ast import * +from nmigen.hdl.cd import * +from nmigen.hdl.ir import * +from nmigen.hdl.mem import * + from .utils import * diff --git a/nmigen/test/test_hdl_mem.py b/tests/test_hdl_mem.py similarity index 98% rename from nmigen/test/test_hdl_mem.py rename to tests/test_hdl_mem.py index ed87aec..ef0a885 100644 --- a/nmigen/test/test_hdl_mem.py +++ b/tests/test_hdl_mem.py @@ -1,7 +1,8 @@ # nmigen: UnusedElaboratable=no -from ..hdl.ast import * -from ..hdl.mem import * +from nmigen.hdl.ast import * +from nmigen.hdl.mem import * + from .utils import * diff --git a/nmigen/test/test_hdl_rec.py b/tests/test_hdl_rec.py similarity index 99% rename from nmigen/test/test_hdl_rec.py rename to tests/test_hdl_rec.py index dfcadf7..718fa4a 100644 --- a/nmigen/test/test_hdl_rec.py +++ b/tests/test_hdl_rec.py @@ -1,7 +1,8 @@ from enum import Enum -from ..hdl.ast import * -from ..hdl.rec import * +from nmigen.hdl.ast import * +from nmigen.hdl.rec import * + from .utils import * diff --git a/nmigen/test/test_hdl_xfrm.py b/tests/test_hdl_xfrm.py similarity index 99% rename from nmigen/test/test_hdl_xfrm.py rename to tests/test_hdl_xfrm.py index 9ec6e1b..c8b885f 100644 --- a/nmigen/test/test_hdl_xfrm.py +++ b/tests/test_hdl_xfrm.py @@ -1,10 +1,11 @@ # nmigen: UnusedElaboratable=no -from ..hdl.ast import * -from ..hdl.cd import * -from ..hdl.ir import * -from ..hdl.xfrm import * -from ..hdl.mem import * +from nmigen.hdl.ast import * +from nmigen.hdl.cd import * +from nmigen.hdl.ir import * +from nmigen.hdl.xfrm import * +from nmigen.hdl.mem import * + from .utils import * diff --git a/nmigen/test/test_lib_cdc.py b/tests/test_lib_cdc.py similarity index 98% rename from nmigen/test/test_lib_cdc.py rename to tests/test_lib_cdc.py index 3647bfa..f29052a 100644 --- a/nmigen/test/test_lib_cdc.py +++ b/tests/test_lib_cdc.py @@ -1,9 +1,10 @@ # nmigen: UnusedElaboratable=no +from nmigen.hdl import * +from nmigen.back.pysim import * +from nmigen.lib.cdc import * + from .utils import * -from ..hdl import * -from ..back.pysim import * -from ..lib.cdc import * class FFSynchronizerTestCase(FHDLTestCase): diff --git a/nmigen/test/test_lib_coding.py b/tests/test_lib_coding.py similarity index 96% rename from nmigen/test/test_lib_coding.py rename to tests/test_lib_coding.py index cf582e3..c914e9e 100644 --- a/nmigen/test/test_lib_coding.py +++ b/tests/test_lib_coding.py @@ -1,8 +1,9 @@ +from nmigen.hdl import * +from nmigen.asserts import * +from nmigen.back.pysim import * +from nmigen.lib.coding import * + from .utils import * -from ..hdl import * -from ..asserts import * -from ..back.pysim import * -from ..lib.coding import * class EncoderTestCase(FHDLTestCase): diff --git a/nmigen/test/test_lib_fifo.py b/tests/test_lib_fifo.py similarity index 98% rename from nmigen/test/test_lib_fifo.py rename to tests/test_lib_fifo.py index e76c0b0..83dc825 100644 --- a/nmigen/test/test_lib_fifo.py +++ b/tests/test_lib_fifo.py @@ -1,10 +1,11 @@ # nmigen: UnusedElaboratable=no +from nmigen.hdl import * +from nmigen.asserts import * +from nmigen.back.pysim import * +from nmigen.lib.fifo import * + from .utils import * -from ..hdl import * -from ..asserts import * -from ..back.pysim import * -from ..lib.fifo import * class FIFOTestCase(FHDLTestCase): diff --git a/nmigen/test/test_lib_io.py b/tests/test_lib_io.py similarity index 98% rename from nmigen/test/test_lib_io.py rename to tests/test_lib_io.py index 156150e..234df1d 100644 --- a/nmigen/test/test_lib_io.py +++ b/tests/test_lib_io.py @@ -1,8 +1,9 @@ +from nmigen.hdl import * +from nmigen.hdl.rec import * +from nmigen.back.pysim import * +from nmigen.lib.io import * + from .utils import * -from ..hdl import * -from ..hdl.rec import * -from ..back.pysim import * -from ..lib.io import * class PinLayoutTestCase(FHDLTestCase): diff --git a/nmigen/test/test_lib_scheduler.py b/tests/test_lib_scheduler.py similarity index 96% rename from nmigen/test/test_lib_scheduler.py rename to tests/test_lib_scheduler.py index 9ae4cbb..3128ad1 100644 --- a/nmigen/test/test_lib_scheduler.py +++ b/tests/test_lib_scheduler.py @@ -1,10 +1,13 @@ # nmigen: UnusedElaboratable=no + import unittest + +from nmigen.hdl import * +from nmigen.asserts import * +from nmigen.sim.pysim import * +from nmigen.lib.scheduler import * + from .utils import * -from ..hdl import * -from ..asserts import * -from ..sim.pysim import * -from ..lib.scheduler import * class RoundRobinTestCase(unittest.TestCase): diff --git a/nmigen/test/test_sim.py b/tests/test_sim.py similarity index 99% rename from nmigen/test/test_sim.py rename to tests/test_sim.py index 94424f7..6c125ba 100644 --- a/nmigen/test/test_sim.py +++ b/tests/test_sim.py @@ -1,15 +1,16 @@ import os from contextlib import contextmanager +from nmigen._utils import flatten, union +from nmigen.hdl.ast import * +from nmigen.hdl.cd import * +from nmigen.hdl.mem import * +from nmigen.hdl.rec import * +from nmigen.hdl.dsl import * +from nmigen.hdl.ir import * +from nmigen.back.pysim import * + from .utils import * -from .._utils import flatten, union -from ..hdl.ast import * -from ..hdl.cd import * -from ..hdl.mem import * -from ..hdl.rec import * -from ..hdl.dsl import * -from ..hdl.ir import * -from ..back.pysim import * class SimulatorUnitTestCase(FHDLTestCase): diff --git a/nmigen/test/utils.py b/tests/utils.py similarity index 94% rename from nmigen/test/utils.py rename to tests/utils.py index 3c88403..c165cf9 100644 --- a/nmigen/test/utils.py +++ b/tests/utils.py @@ -5,13 +5,12 @@ import subprocess import textwrap import traceback import unittest -import warnings from contextlib import contextmanager -from ..hdl.ast import * -from ..hdl.ir import * -from ..back import rtlil -from .._toolchain import require_tool +from nmigen.hdl.ast import * +from nmigen.hdl.ir import * +from nmigen.back import rtlil +from nmigen._toolchain import require_tool __all__ = ["FHDLTestCase"] -- 2.30.2