Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
358ba459
Unverified
Commit
358ba459
authored
Dec 01, 2022
by
Ralf W. Grosse-Kunstleve
Committed by
GitHub
Dec 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test added with PR #4330 (#4372)
parent
b14d58b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
22 deletions
+25
-22
tests/test_embed/test_interpreter.cpp
+25
-22
No files found.
tests/test_embed/test_interpreter.cpp
View file @
358ba459
...
...
@@ -14,6 +14,11 @@ PYBIND11_WARNING_DISABLE_MSVC(4996)
namespace
py
=
pybind11
;
using
namespace
py
::
literals
;
size_t
get_sys_path_size
()
{
auto
sys_path
=
py
::
module
::
import
(
"sys"
).
attr
(
"path"
);
return
py
::
len
(
sys_path
);
}
class
Widget
{
public
:
explicit
Widget
(
std
::
string
message
)
:
message
(
std
::
move
(
message
))
{}
...
...
@@ -196,41 +201,39 @@ TEST_CASE("Custom PyConfig with argv") {
}
#endif
TEST_CASE
(
"Add program dir to path"
)
{
static
auto
get_sys_path_size
=
[]()
->
size_t
{
auto
sys_path
=
py
::
module
::
import
(
"sys"
).
attr
(
"path"
);
return
py
::
len
(
sys_path
);
};
static
auto
validate_path_len
=
[](
size_t
default_len
)
{
#if PY_VERSION_HEX < 0x030A0000
// It seems a value remains in sys.path
// left by the previous call of scoped_interpreter ctor.
REQUIRE
(
get_sys_path_size
()
>
default_len
);
#else
REQUIRE
(
get_sys_path_size
()
==
default_len
+
1
);
#endif
};
TEST_CASE
(
"Add program dir to path pre-PyConfig"
)
{
py
::
finalize_interpreter
();
size_t
sys_path_default_size
=
0
;
size_t
path_size_add_program_dir_to_path_false
=
0
;
{
py
::
scoped_interpreter
scoped_interp
{
true
,
0
,
nullptr
,
false
};
sys_path_default_siz
e
=
get_sys_path_size
();
path_size_add_program_dir_to_path_fals
e
=
get_sys_path_size
();
}
{
py
::
scoped_interpreter
scoped_interp
{};
// expected to append some to sys.path
validate_path_len
(
sys_path_default_size
);
py
::
scoped_interpreter
scoped_interp
{};
REQUIRE
(
get_sys_path_size
()
==
path_size_add_program_dir_to_path_false
+
1
);
}
py
::
initialize_interpreter
();
}
#if PY_VERSION_HEX >= PYBIND11_PYCONFIG_SUPPORT_PY_VERSION_HEX
TEST_CASE
(
"Add program dir to path using PyConfig"
)
{
py
::
finalize_interpreter
();
size_t
path_size_add_program_dir_to_path_false
=
0
;
{
PyConfig
config
;
PyConfig_InitPythonConfig
(
&
config
);
py
::
scoped_interpreter
scoped_interp
{
&
config
};
// expected to append some to sys.path
validate_path_len
(
sys_path_default_size
);
py
::
scoped_interpreter
scoped_interp
{
&
config
,
0
,
nullptr
,
false
};
path_size_add_program_dir_to_path_false
=
get_sys_path_size
();
}
{
PyConfig
config
;
PyConfig_InitPythonConfig
(
&
config
);
py
::
scoped_interpreter
scoped_interp
{
&
config
};
REQUIRE
(
get_sys_path_size
()
==
path_size_add_program_dir_to_path_false
+
1
);
}
#endif
py
::
initialize_interpreter
();
}
#endif
bool
has_pybind11_internals_builtin
()
{
auto
builtins
=
py
::
handle
(
PyEval_GetBuiltins
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment