Skip to content

Add test numpy.cpp #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 1, 2024
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(NOT SHOW_XTENSOR_WARNINGS)
endif()
endif()

add_executable(${PROJECT_NAME} test_main.cpp numpy/src/numpy.cpp)
add_executable(${PROJECT_NAME} numpy/tests/test_numpy.cpp numpy/src/numpy.cpp)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY CMAKE_CURRENT_LIST_DIR)

Expand Down
2 changes: 1 addition & 1 deletion numpy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
test_arange(100)
```

2. Read the script and execute it in `test_main.cpp`.
2. Read the script and execute it in `test_numpy.cpp`.
```cpp
#include <pybind11/embed.h>
#include <fstream>
Expand Down
18 changes: 18 additions & 0 deletions numpy/tests/test_numpy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <pybind11/embed.h>
#include <fstream>
#include <sstream>
#include <string>

namespace py = pybind11;
using namespace pybind11;

int main() {
py::scoped_interpreter guard{};
std::ifstream file("numpy/tests/test_numpy.py");
std::stringstream buffer;
buffer << file.rdbuf();
std::string script = buffer.str();
py::exec(script);

return 0;
}
Loading