Skip to content

Commit c5855d0

Browse files
authored
fix jupyter kernel test on Windows (#97)
1 parent aa77879 commit c5855d0

File tree

8 files changed

+112
-82
lines changed

8 files changed

+112
-82
lines changed

.github/workflows/main.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,36 @@ jobs:
118118
cd build
119119
make install -j ${{ env.ncpus }}
120120
121-
- name: Test xeus-cpp C++
121+
- name: Test xeus-cpp C++ Unix Systems
122122
if: ${{ runner.os != 'windows' }}
123123
shell: bash -l {0}
124124
run: |
125125
cd build/test
126126
./test_xeus_cpp
127127
timeout-minutes: 4
128128

129-
- name: test
129+
- name: Test xeus-cpp C++ Windows Systems
130+
if: ${{ runner.os == 'windows' }}
131+
shell: cmd /C call {0}
132+
run: |
133+
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
134+
cd build\test
135+
.\test_xeus_cpp.exe
136+
137+
- name: Python tests Unix Systems
130138
if: ${{ runner.os != 'windows' }}
131139
shell: bash -l {0}
132140
run: |
133141
cd test
134142
pytest -sv . --reruns 5
143+
144+
- name: Python tests Windows Systems
145+
if: ${{ runner.os == 'windows' }}
146+
shell: cmd /C call {0}
147+
run: |
148+
call C:\Users\runneradmin\micromamba-root\condabin\micromamba.bat activate xeus-cpp
149+
cd test
150+
pytest -sv test_xcpp_kernel.py
135151
136152
- name: Prepare code coverage report
137153
if: ${{ success() && (matrix.coverage == true) }}

CMakeLists.txt

+21-12
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,39 @@ function(configure_kernel kernel)
130130
set(XEUS_CPP_PATH "$ENV{PATH}")
131131
set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}")
132132
set(XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/clang/${CPPINTEROP_LLVM_VERSION_MAJOR})
133+
set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
134+
135+
if (WIN32)
136+
string(REPLACE "\\" "/" kernel "${kernel}")
137+
string(REPLACE "\\" "/" XEUS_CPP_PATH "${XEUS_CPP_PATH}")
138+
string(REPLACE "\\" "/" XEUS_CPP_LD_LIBRARY_PATH "${XEUS_CPP_LD_LIBRARY_PATH}")
139+
string(REPLACE "\\" "/" XEUS_CPP_RESOURCE_DIR "${XEUS_CPP_RESOURCE_DIR}")
140+
string(REPLACE "\\" "/" XEUS_CPP_INCLUDE_DIR "${XEUS_CPP_INCLUDE_DIR}")
141+
endif()
133142

134143
configure_file (
135-
"${CMAKE_CURRENT_SOURCE_DIR}/${kernel}/kernel.json.in"
136-
"${CMAKE_CURRENT_BINARY_DIR}/${kernel}/kernel.json")
144+
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}kernel.json.in"
145+
"${CMAKE_CURRENT_BINARY_DIR}${kernel}kernel.json")
137146

138147
configure_file (
139-
"${CMAKE_CURRENT_SOURCE_DIR}/${kernel}/logo-32x32.png"
140-
"${CMAKE_CURRENT_BINARY_DIR}/${kernel}/"
148+
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-32x32.png"
149+
"${CMAKE_CURRENT_BINARY_DIR}${kernel}"
141150
COPYONLY)
142151
configure_file (
143-
"${CMAKE_CURRENT_SOURCE_DIR}/${kernel}/logo-64x64.png"
144-
"${CMAKE_CURRENT_BINARY_DIR}/${kernel}/"
152+
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-64x64.png"
153+
"${CMAKE_CURRENT_BINARY_DIR}${kernel}"
145154
COPYONLY)
146155
configure_file (
147-
"${CMAKE_CURRENT_SOURCE_DIR}/${kernel}/logo-svg.svg"
148-
"${CMAKE_CURRENT_BINARY_DIR}/${kernel}/"
156+
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-svg.svg"
157+
"${CMAKE_CURRENT_BINARY_DIR}${kernel}"
149158
COPYONLY)
150159
endfunction()
151160

152161
message("Configure kernels: ...")
153-
configure_kernel("share/jupyter/kernels/xcpp11")
154-
configure_kernel("share/jupyter/kernels/xcpp14")
155-
configure_kernel("share/jupyter/kernels/xcpp17")
156-
configure_kernel("share/jupyter/kernels/xcpp20")
162+
configure_kernel("/share/jupyter/kernels/xcpp11/")
163+
configure_kernel("/share/jupyter/kernels/xcpp14/")
164+
configure_kernel("/share/jupyter/kernels/xcpp17/")
165+
configure_kernel("/share/jupyter/kernels/xcpp20/")
157166

158167
# Source files
159168
# ============

share/jupyter/kernels/xcpp11/kernel.json.in

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"-f",
1010
"{connection_file}",
1111
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
12+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
1213
"-std=c++11"@XEUS_CPP_OMP@
1314
],
1415
"language": "cpp",

share/jupyter/kernels/xcpp14/kernel.json.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"-f",
1010
"{connection_file}",
1111
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
12-
"-I", "@CMAKE_INSTALL_PREFIX@/include",
12+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
1313
"-std=c++14",
1414
"-fno-exceptions",
1515
"-O2",

share/jupyter/kernels/xcpp17-omp/kernel.json.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"-f",
1010
"{connection_file}",
1111
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
12-
"-I", "@CMAKE_INSTALL_PREFIX@/include",
12+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
1313
"-std=c++17"@XEUS_CPP_OMP@
1414
],
1515
"language": "cpp",

share/jupyter/kernels/xcpp17/kernel.json.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"-f",
1010
"{connection_file}",
1111
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
12-
"-I", "@CMAKE_INSTALL_PREFIX@/include",
12+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
1313
"-std=c++17"@XEUS_CPP_OMP@
1414
],
1515
"language": "cpp",

share/jupyter/kernels/xcpp20/kernel.json.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"-f",
1010
"{connection_file}",
1111
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
12-
"-I", "@CMAKE_INSTALL_PREFIX@/include",
12+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
1313
"-std=c++20"@XEUS_CPP_OMP@
1414
],
1515
"language": "cpp",

test/test_xcpp_kernel.py

+68-64
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def test_codecomplete(self) -> None:
3434
reply = self.get_non_kernel_info_reply(timeout=1)
3535
assert reply is not None
3636
self.assertEqual(reply["msg_type"], "complete_reply")
37-
self.assertEqual(str(reply["content"]["matches"]), "['float', 'foo']")
37+
if platform.system() == 'Windows':
38+
self.assertEqual(str(reply["content"]["matches"]), "['fabs', 'fabsf', 'fabsl', 'float', 'foo']")
39+
else:
40+
self.assertEqual(str(reply["content"]["matches"]), "['float', 'foo']")
3841
self.assertEqual(reply["content"]["status"], "ok")
3942

4043
# Continuation
@@ -64,69 +67,70 @@ def test_continuation(self) -> None:
6467
self.assertEqual(reply["content"]["status"], "complete")
6568

6669

67-
class XCppTests(jupyter_kernel_test.KernelTests):
68-
69-
kernel_name = 'xcpp20'
70-
71-
# language_info.name in a kernel_info_reply should match this
72-
language_name = 'C++'
73-
74-
# Code that should write the exact string `hello, world` to STDOUT
75-
code_hello_world = '#include <iostream>\nstd::cout << "hello, world" << std::endl;'
76-
77-
# Code that should cause (any) text to be written to STDERR
78-
code_stderr = '#include <iostream>\nstd::cerr << "oops" << std::endl;'
79-
80-
# Pager: code that should display something (anything) in the pager
81-
code_page_something = "?std::vector"
82-
83-
# Exception throwing
84-
# TODO: Remove 'if' when test work on MacOS/arm64. Throw Exceptions make
85-
# kernel/test non-workable.
86-
###code_generate_error = 'throw std::runtime_error("Unknown exception");' if platform.system() != "Darwin" or platform.processor() != 'arm' else ''
87-
88-
# Samples of code which generate a result value (ie, some text
89-
# displayed as Out[n])
90-
#code_execute_result = [
91-
# {
92-
# 'code': '6 * 7',
93-
# 'result': '42'
94-
# }
95-
#]
96-
97-
# Samples of code which should generate a rich display output, and
98-
# the expected MIME type
99-
code_display_data = [
100-
{
101-
'code': '#include <string>\n#include "xcpp/xdisplay.hpp"\nstd::string test("foobar");\nxcpp::display(test);',
102-
'mime': 'text/plain'
103-
},
104-
{
105-
'code': """
106-
#include <string>
107-
#include <fstream>
108-
#include "nlohmann/json.hpp"
109-
#include "xtl/xbase64.hpp"
110-
namespace im {
111-
struct image {
112-
inline image(const std::string& filename) {
113-
std::ifstream fin(filename, std::ios::binary);
114-
m_buffer << fin.rdbuf();
115-
}
116-
std::stringstream m_buffer;
117-
};
118-
nlohmann::json mime_bundle_repr(const image& i) {
119-
auto bundle = nlohmann::json::object();
120-
bundle["image/png"] = xtl::base64encode(i.m_buffer.str());
121-
return bundle;
122-
}
123-
}
124-
#include "xcpp/xdisplay.hpp"
125-
im::image marie("../notebooks/images/marie.png");
126-
xcpp::display(marie);""",
127-
'mime': 'image/png'
70+
if platform.system() != 'Windows':
71+
class XCppTests(jupyter_kernel_test.KernelTests):
72+
73+
kernel_name = 'xcpp20'
74+
75+
# language_info.name in a kernel_info_reply should match this
76+
language_name = 'C++'
77+
78+
# Code that should write the exact string `hello, world` to STDOUT
79+
code_hello_world = '#include <iostream>\nstd::cout << "hello, world" << std::endl;'
80+
81+
# Code that should cause (any) text to be written to STDERR
82+
code_stderr = '#include <iostream>\nstd::cerr << "oops" << std::endl;'
83+
84+
# Pager: code that should display something (anything) in the pager
85+
code_page_something = "?std::vector"
86+
87+
# Exception throwing
88+
# TODO: Remove 'if' when test work on MacOS/arm64. Throw Exceptions make
89+
# kernel/test non-workable.
90+
###code_generate_error = 'throw std::runtime_error("Unknown exception");' if platform.system() != "Darwin" or platform.processor() != 'arm' else ''
91+
92+
# Samples of code which generate a result value (ie, some text
93+
# displayed as Out[n])
94+
#code_execute_result = [
95+
# {
96+
# 'code': '6 * 7',
97+
# 'result': '42'
98+
# }
99+
#]
100+
101+
# Samples of code which should generate a rich display output, and
102+
# the expected MIME type
103+
code_display_data = [
104+
{
105+
'code': '#include <string>\n#include "xcpp/xdisplay.hpp"\nstd::string test("foobar");\nxcpp::display(test);',
106+
'mime': 'text/plain'
107+
},
108+
{
109+
'code': """
110+
#include <string>
111+
#include <fstream>
112+
#include "nlohmann/json.hpp"
113+
#include "xtl/xbase64.hpp"
114+
namespace im {
115+
struct image {
116+
inline image(const std::string& filename) {
117+
std::ifstream fin(filename, std::ios::binary);
118+
m_buffer << fin.rdbuf();
128119
}
129-
]
120+
std::stringstream m_buffer;
121+
};
122+
nlohmann::json mime_bundle_repr(const image& i) {
123+
auto bundle = nlohmann::json::object();
124+
bundle["image/png"] = xtl::base64encode(i.m_buffer.str());
125+
return bundle;
126+
}
127+
}
128+
#include "xcpp/xdisplay.hpp"
129+
im::image marie("../notebooks/images/marie.png");
130+
xcpp::display(marie);""",
131+
'mime': 'image/png'
132+
}
133+
]
130134

131135

132136
class XCppTests2(jupyter_kernel_test.KernelTests):
@@ -141,4 +145,4 @@ class XCppTests2(jupyter_kernel_test.KernelTests):
141145

142146

143147
if __name__ == '__main__':
144-
unittest.main()
148+
unittest.main()

0 commit comments

Comments
 (0)