Skip to content

Commit b23acbe

Browse files
committed
Rename pybind11_local_bindings to pybind11_cross_module_tests
1 parent 445a5ed commit b23acbe

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

tests/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ endif()
6868

6969
string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}")
7070

71+
# Contains the set of test files that require pybind11_cross_module_tests to be
72+
# built; if none of these are built (i.e. because TEST_OVERRIDE is used and
73+
# doesn't include them) the second module doesn't get built.
74+
set(PYBIND11_CROSS_MODULE_TESTS
75+
test_local_bindings.cpp
76+
)
77+
7178
# Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but
7279
# keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed"
7380
# skip message).
@@ -122,12 +129,15 @@ function(pybind11_enable_warnings target_name)
122129
endfunction()
123130

124131
set(test_targets pybind11_tests)
125-
# If test_local_bindings is being built in pybind11_tests.so we'll also build
126-
# a separate module pybind11_local_bindings.so for the test:
127-
list(FIND PYBIND11_TEST_FILES test_local_bindings.cpp test_local_i)
128-
if (test_local_i GREATER -1)
129-
list(APPEND test_targets pybind11_local_bindings)
130-
endif()
132+
133+
# If any tests are being built that require pybind11_cross_module_tests, add it
134+
# to test_targets:
135+
foreach(t ${PYBIND11_CROSS_MODULE_TESTS})
136+
list(FIND PYBIND11_TEST_FILES ${t} i)
137+
if (i GREATER -1)
138+
list(APPEND test_targets pybind11_cross_module_tests)
139+
endif()
140+
endforeach()
131141

132142
set(testdir ${CMAKE_CURRENT_SOURCE_DIR})
133143
foreach(tgt ${test_targets})

tests/pybind11_local_bindings.cpp renamed to tests/pybind11_cross_module_tests.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
tests/pybind11_local_bindings.cpp -- counterpart to test_local_bindings.cpp
2+
tests/pybind11_cross_module_tests.cpp -- contains tests that require multiple modules
33
44
Copyright (c) 2017 Jason Rhinelander <[email protected]>
55
@@ -11,9 +11,11 @@
1111
#include "local_bindings.h"
1212
#include <pybind11/stl_bind.h>
1313

14-
PYBIND11_MODULE(pybind11_local_bindings, m) {
15-
m.doc() = "pybind11 local bindings test module";
14+
PYBIND11_MODULE(pybind11_cross_module_tests, m) {
15+
m.doc() = "pybind11 cross-module test module";
1616

17+
// test_local_bindings.py tests:
18+
//
1719
// Definitions here are tested by importing both this module and the
1820
// pybind11_tests.local_bindings submodule from test_local_bindings.py
1921

tests/test_local_bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST_SUBMODULE(local_bindings, m) {
2424

2525
// test_nonlocal_failure
2626
// The main pybind11 test module is loaded first, so this registration will succeed (the second
27-
// one, in pybind11_local_bindings.cpp, is designed to fail):
27+
// one, in pybind11_cross_module_tests.cpp, is designed to fail):
2828
bind_local<NonLocalType, 0>(m, "NonLocalType")
2929
.def(py::init<int>())
3030
.def("get", [](LocalType &i) { return i.i; })

tests/test_local_bindings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_local_bindings():
77
"""Tests that duplicate py::local class bindings work across modules"""
88

99
# Make sure we can load the second module with the conflicting (but local) definition:
10-
import pybind11_local_bindings as m2
10+
import pybind11_cross_module_tests as m2
1111

1212
i1 = m1.LocalType(5)
1313

@@ -35,7 +35,7 @@ def test_local_bindings():
3535

3636
def test_nonlocal_failure():
3737
"""Tests that attempting to register a non-local type in multiple modules fails"""
38-
import pybind11_local_bindings as m2
38+
import pybind11_cross_module_tests as m2
3939

4040
with pytest.raises(RuntimeError) as excinfo:
4141
m2.register_nonlocal()
@@ -53,7 +53,7 @@ def test_duplicate_local():
5353

5454

5555
def test_stl_bind_local():
56-
import pybind11_local_bindings as m2
56+
import pybind11_cross_module_tests as m2
5757

5858
v1, v2 = m1.LocalVec(), m2.LocalVec()
5959
v1.append(m1.LocalType(1))
@@ -88,7 +88,7 @@ def test_stl_bind_local():
8888

8989

9090
def test_stl_bind_global():
91-
import pybind11_local_bindings as m2
91+
import pybind11_cross_module_tests as m2
9292

9393
with pytest.raises(RuntimeError) as excinfo:
9494
m2.register_nonlocal_map()
@@ -105,5 +105,5 @@ def test_stl_bind_global():
105105

106106
def test_internal_locals_differ():
107107
"""Makes sure the internal local type map differs across the two modules"""
108-
import pybind11_local_bindings as m2
108+
import pybind11_cross_module_tests as m2
109109
assert m1.local_cpp_types_addr() != m2.local_cpp_types_addr()

0 commit comments

Comments
 (0)