Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/python-unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
pip cache purge
python -m pip install --upgrade pip
pip install .[dev]
python tests/compile.py
python tools/compile_tests.py

- name: Test with unittest
run: python -m unittest discover -v -s tests
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.13)

project(amulet_test_utils LANGUAGES CXX)

# Set C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Set platform variables
if (WIN32)
# set windows 7 as the minimum version
add_definitions(-D_WIN32_WINNT=0x0601)
elseif(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
else()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

if (MSVC)
add_definitions("/MP")
endif()

# Find C++ files
file(REAL_PATH src SOURCE_PATH)
file(GLOB_RECURSE HEADERS LIST_DIRECTORIES false ${SOURCE_PATH}/amulet/*.hpp)

# Add implementation
add_library(amulet_test_utils INTERFACE)
target_include_directories(amulet_test_utils INTERFACE "src")
target_sources(amulet_test_utils PRIVATE ${HEADERS})
foreach(FILE ${HEADERS})
file(RELATIVE_PATH REL_PATH ${SOURCE_PATH} ${FILE})
get_filename_component(GROUP ${REL_PATH} DIRECTORY)
string(REPLACE "/" "\\" GROUP ${GROUP})
source_group(${GROUP} FILES ${FILE})
endforeach()

if (TEST_AMULET_TEST_UTILS_DIR)
add_subdirectory(tests)
endif()
14 changes: 2 additions & 12 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,9 @@ endif()
find_package(pybind11 CONFIG REQUIRED)
find_package(amulet_test_utils CONFIG REQUIRED)

# Find sources
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES false "${CMAKE_CURRENT_LIST_DIR}/*.py.cpp")

pybind11_add_module(_test_test_utils)
pybind11_add_module(_test_test_utils "test_amulet_test_utils/_test_test_utils.py.cpp")
target_compile_definitions(_test_test_utils PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES)
target_link_libraries(_test_test_utils PRIVATE amulet_test_utils)
target_sources(_test_test_utils PRIVATE ${SOURCES})
foreach(FILE ${SOURCES})
file(RELATIVE_PATH REL_PATH ${CMAKE_CURRENT_LIST_DIR} ${FILE})
get_filename_component(GROUP ${REL_PATH} DIRECTORY)
string(REPLACE "/" "\\" GROUP "${GROUP}")
source_group(${GROUP} FILES ${FILE})
endforeach()

# Install
install(TARGETS _test_test_utils DESTINATION ".")
install(TARGETS _test_test_utils DESTINATION ${TEST_AMULET_TEST_UTILS_DIR})
65 changes: 0 additions & 65 deletions tests/compile.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class TestUtilsTestCase(TestCase):
def test_assert_equal(self) -> None:
from _test_test_utils import (
from test_amulet_test_utils._test_test_utils import (
test_assert_equal_1,
test_assert_equal_2,
test_assert_equal_3,
Expand All @@ -23,7 +23,11 @@ def test_assert_equal(self) -> None:
test_assert_equal_6()

def test_assert_raises(self) -> None:
from _test_test_utils import test_assert_raises_1, test_assert_raises_2, test_assert_raises_3
from test_amulet_test_utils._test_test_utils import (
test_assert_raises_1,
test_assert_raises_2,
test_assert_raises_3,
)

test_assert_raises_1()
test_assert_raises_2()
Expand Down
47 changes: 47 additions & 0 deletions tools/cmake_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
import subprocess
import os
import shutil

import pybind11


def fix_path(path: str) -> str:
return os.path.realpath(path).replace(os.sep, "/")


RootDir = fix_path(os.path.dirname(os.path.dirname(__file__)))


def main():
platform_args = []
if sys.platform == "win32":
platform_args.extend(["-G", "Visual Studio 17 2022"])
if sys.maxsize > 2**32:
platform_args.extend(["-A", "x64"])
else:
platform_args.extend(["-A", "Win32"])
platform_args.extend(["-T", "v143"])

os.chdir(RootDir)
shutil.rmtree(os.path.join(RootDir, "build", "CMakeFiles"), ignore_errors=True)

if subprocess.run(
[
"cmake",
*platform_args,
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-Dpybind11_DIR={fix_path(pybind11.get_cmake_dir())}",
f"-DCMAKE_INSTALL_PREFIX=install",
# test args
f"-Damulet_test_utils_DIR={os.path.join(RootDir, 'src', 'amulet', 'test_utils')}",
f"-DTEST_AMULET_TEST_UTILS_DIR={os.path.join(RootDir, 'tests', 'test_amulet_test_utils')}",
"-B",
"build",
]
).returncode:
raise RuntimeError("Error configuring amulet_utils")


if __name__ == "__main__":
main()
57 changes: 57 additions & 0 deletions tools/compile_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import subprocess
import sys
import shutil
import os

import pybind11
import amulet.test_utils


def fix_path(path: str) -> str:
return os.path.realpath(path).replace(os.sep, "/")


RootDir = os.path.dirname(os.path.dirname(__file__))
TestsDir = os.path.join(RootDir, "tests")


def main() -> None:
platform_args = []
if sys.platform == "win32":
platform_args.extend(["-G", "Visual Studio 17 2022"])
if sys.maxsize > 2**32:
platform_args.extend(["-A", "x64"])
else:
platform_args.extend(["-A", "Win32"])
platform_args.extend(["-T", "v143"])

os.chdir(TestsDir)
shutil.rmtree(os.path.join(TestsDir, "build", "CMakeFiles"), ignore_errors=True)

if subprocess.run(
[
"cmake",
*platform_args,
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-Dpybind11_DIR={fix_path(pybind11.get_cmake_dir())}",
f"-DCMAKE_INSTALL_PREFIX=install",
# test args
f"-Damulet_test_utils_DIR={fix_path(amulet.test_utils.__path__[0])}",
f"-DTEST_AMULET_TEST_UTILS_DIR={fix_path(os.path.join(TestsDir, 'test_amulet_test_utils'))}",
"-B",
"build",
]
).returncode:
raise RuntimeError("Error configuring test_amulet_test_utils")
if subprocess.run(
["cmake", "--build", "build", "--config", "RelWithDebInfo"]
).returncode:
raise RuntimeError("Error installing test_amulet_test_utils")
if subprocess.run(
["cmake", "--install", "build", "--config", "RelWithDebInfo"]
).returncode:
raise RuntimeError("Error installing test_amulet_test_utils")


if __name__ == "__main__":
main()