Skip to content

Commit

Permalink
Support assert reporting from test helper module
Browse files Browse the repository at this point in the history
edalize_common is a helper module that contains the asserts used
in most tests. pytest however normally only support asserts used
in the actual test module.

This patch adds an __init__.py for the tests that enables pytest
asserts in edalize_common, together with related changes.
  • Loading branch information
olofk committed Jul 11, 2022
1 parent ef4e9b0 commit 0be41b9
Show file tree
Hide file tree
Showing 34 changed files with 51 additions and 48 deletions.
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.register_assert_rewrite("tests.edalize_common")
2 changes: 1 addition & 1 deletion tests/test_apicula.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_apicula_test(tf):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ascentlint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_ascentlint_defaults(make_edalize_test):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_diamond.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_diamond(make_edalize_test):
Expand Down Expand Up @@ -26,9 +26,8 @@ def test_diamond_minimal(tmpdir):

from edalize import get_edatool

from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

ref_dir = os.path.join(tests_dir, __name__, "minimal")
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand All @@ -44,6 +43,7 @@ def test_diamond_minimal(tmpdir):
backend = get_edatool(tool)(edam=edam, work_root=work_root)
backend.configure()

ref_dir = os.path.join(tests_dir, "test_" + tool, "minimal")
compare_files(
ref_dir,
work_root,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gatemate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_gatemate_test(tf):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ghdl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_ghdl_01(make_edalize_test):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_icarus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_icarus(make_edalize_test):
Expand Down Expand Up @@ -28,9 +28,8 @@ def test_icarus_minimal(tmpdir):

from edalize import get_edatool

from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

ref_dir = os.path.join(tests_dir, __name__, "minimal")
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand All @@ -43,6 +42,7 @@ def test_icarus_minimal(tmpdir):
backend = get_edatool(tool)(edam=edam, work_root=work_root)
backend.configure()

ref_dir = os.path.join(tests_dir, "test_" + tool, "minimal")
compare_files(
ref_dir,
work_root,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_icestorm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_icestorm_test(tf, pnr_cmdfile="nextpnr-ice40.cmd"):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test
import pytest


Expand Down
2 changes: 1 addition & 1 deletion tests/test_isim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_isim(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_libero.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_libero(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest


from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_mistral_test(tf):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_modelsim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import filecmp
import os
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def test_modelsim(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_morty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test
import os


Expand Down
2 changes: 1 addition & 1 deletion tests/test_openfpga.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def test_openfpga(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_openlane.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test
import os


Expand Down
2 changes: 1 addition & 1 deletion tests/test_oxide.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_oxide_test(tf):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_quartus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test

qsys_file = """<?xml version="1.0" encoding="UTF-8"?>
<system name="test">
Expand Down
6 changes: 3 additions & 3 deletions tests/test_radiant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_radiant(make_edalize_test):
Expand Down Expand Up @@ -26,9 +26,8 @@ def test_radiant_minimal(tmpdir):

from edalize import get_edatool

from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

ref_dir = os.path.join(tests_dir, __name__, "minimal")
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand All @@ -44,6 +43,7 @@ def test_radiant_minimal(tmpdir):
backend = get_edatool(tool)(edam=edam, work_root=work_root)
backend.configure()

ref_dir = os.path.join(tests_dir, "test_" + tool, "minimal")
compare_files(
ref_dir,
work_root,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import pandas as pd

from edalize_common import tests_dir
from .edalize_common import tests_dir


def check_types(s, allowed=[int, float]):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rivierapro.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import filecmp
import os
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def test_rivierapro(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spyglass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def run_spyglass_test(tf):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_symbiflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def run_symbiflow_test(tf, config_files=list()):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_symbiyosys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_symbiyosys(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_trellis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_trellis_test(tf, pnr_cmdfile="nextpnr-ice40.cmd"):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_vcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def run_vcs_test(tf):
Expand Down Expand Up @@ -37,9 +37,8 @@ def test_vcs_minimal(tmpdir):

from edalize import get_edatool

from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

ref_dir = os.path.join(tests_dir, __name__, "minimal")
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand All @@ -52,6 +51,7 @@ def test_vcs_minimal(tmpdir):
backend = get_edatool(tool)(edam=edam, work_root=work_root)
backend.configure()

ref_dir = os.path.join(tests_dir, "test_" + tool, "minimal")
compare_files(ref_dir, work_root, ["Makefile", name + ".scr"])

backend.build()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_veribleformat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_veribleformat_default(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_veriblelint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_veriblelint_default(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_verilator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_verilator_cc(make_edalize_test):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_vivado.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


def test_vivado(make_edalize_test):
Expand Down Expand Up @@ -28,11 +28,10 @@ def test_vivado_minimal(params, tmpdir, make_edalize_test):
import os

import edalize
from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

test_name, synth_tool = params

ref_dir = os.path.join(tests_dir, __name__, test_name)
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand Down Expand Up @@ -63,6 +62,7 @@ def test_vivado_minimal(params, tmpdir, make_edalize_test):
else:
config_file_list.append(name + "_synth.tcl")

ref_dir = os.path.join(tests_dir, "test_" + tool, test_name)
compare_files(ref_dir, work_root, config_file_list)

build_file_list = ["vivado.cmd"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_vpr.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
import pytest
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test


@pytest.mark.parametrize("params", [("minimal", "vpr")])
def test_vpr(params, tmpdir):
import os
import edalize
from edalize_common import compare_files, tests_dir
from .edalize_common import compare_files, tests_dir

test_name = "vpr"
ref_dir = os.path.join(tests_dir, __name__, test_name)
os.environ["PATH"] = (
os.path.join(tests_dir, "mock_commands") + ":" + os.environ["PATH"]
)
Expand All @@ -33,4 +32,5 @@ def test_vpr(params, tmpdir):
config_file_list = [
"Makefile",
]
ref_dir = os.path.join(tests_dir, "test_" + tool, test_name)
compare_files(ref_dir, work_root, config_file_list)
8 changes: 4 additions & 4 deletions tests/test_vunit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import os.path
from unittest.mock import patch, MagicMock
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test
import edalize.edatool


Expand All @@ -12,17 +12,17 @@ def test_vunit_codegen(make_edalize_test):


def test_vunit_hooks(tmpdir):
from edalize_common import tests_dir
from .edalize_common import tests_dir

import subprocess
import sys
import importlib.util
from unittest import mock
from edalize import get_edatool

sys.path = [os.path.join(tests_dir, __name__, "vunit_mock")] + sys.path
sys.path = [os.path.join(tests_dir, "test_vunit", "vunit_mock")] + sys.path

ref_dir = os.path.join(tests_dir, __name__, "minimal")
ref_dir = os.path.join(tests_dir, "test_vunit", "minimal")
tool = "vunit"
name = "test_" + tool + "_minimal_0"
work_root = str(tmpdir)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xcelium.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from edalize_common import make_edalize_test, tests_dir
from .edalize_common import make_edalize_test, tests_dir


def test_xcelium(make_edalize_test):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xsim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from edalize_common import make_edalize_test
from .edalize_common import make_edalize_test
import os


Expand Down

0 comments on commit 0be41b9

Please sign in to comment.