From 8549f6ad90172a739b78415f8c58c1a8acd386f9 Mon Sep 17 00:00:00 2001 From: Emery Conrad Date: Tue, 1 Sep 2026 11:12:27 -0500 Subject: [PATCH] [test] Skip the dictionary tests without a host toolchain setup_make runs make and a C++ compiler. A host with neither now skips the module instead of failing it. Only test03_add_library_path loads a dictionary in test_basic_api. That test gets a skip marker, and the module makes the dictionary optional. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop) --- test/support.py | 24 ++++++++++++++++++++++-- test/test_basic_api.py | 6 ++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/test/support.py b/test/support.py index de2532d..36094cf 100644 --- a/test/support.py +++ b/test/support.py @@ -1,10 +1,12 @@ from __future__ import print_function import os +import shutil import subprocess import sys import py +import pytest try: import fcntl @@ -13,11 +15,29 @@ currpath = py.path.local(__file__).dirpath() +_NO_TOOLCHAIN = "no make and C++ compiler to build the test dictionaries" +# a build system that supplies the dictionaries itself sets CPPJIT_TEST_SKIP_MAKE +_PREBUILT = bool(os.getenv("CPPJIT_TEST_SKIP_MAKE", False)) +# otherwise test/Makefile builds them with make and its default $(CXX) +_HAS_TOOLCHAIN = bool( + shutil.which("make") and shutil.which(os.environ.get("CXX") or "g++") +) + +# for a test that loads a dictionary in a module whose other tests need none +needs_dictionary = pytest.mark.skipif( + not (_PREBUILT or _HAS_TOOLCHAIN), reason=_NO_TOOLCHAIN +) -def setup_make(targetname): - if os.getenv("CPPJIT_TEST_SKIP_MAKE", False): + +def setup_make(targetname, optional=False): + if _PREBUILT: return + if not _HAS_TOOLCHAIN: + if optional: + return + pytest.skip(_NO_TOOLCHAIN, allow_module_level=True) + # several files share a dictionary, so workers race make for it; the lock # is per target to keep unrelated builds parallel lockf = open(str(currpath.join("cpp", targetname + "Dict.lock")), "a") diff --git a/test/test_basic_api.py b/test/test_basic_api.py index 10e2e81..9f9e7ba 100644 --- a/test/test_basic_api.py +++ b/test/test_basic_api.py @@ -3,7 +3,7 @@ import py from pytest import raises -from support import setup_make +from support import needs_dictionary, setup_make # reuse the example01 currpath = py.path.local(__file__).dirpath() @@ -11,7 +11,8 @@ def setup_module(mod): - setup_make("example01") + # only test03_add_library_path loads the dictionary + setup_make("example01", optional=True) class TestBASICAPI: @@ -39,6 +40,7 @@ def test02_cppdef(self): assert cppjit.cppdef("namespace test02_NS { int x = 42; }") assert cppjit.gbl.test02_NS.x == 42 + @needs_dictionary def test03_add_library_path(self): import cppjit