Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions test/support.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import print_function

import os
import shutil
import subprocess
import sys

import py
import pytest

try:
import fcntl
Expand All @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions test/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

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()
test_dct = str(currpath.join("cpp/example01Dict"))


def setup_module(mod):
setup_make("example01")
# only test03_add_library_path loads the dictionary
setup_make("example01", optional=True)


class TestBASICAPI:
Expand Down Expand Up @@ -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

Expand Down
Loading