@@ -141,77 +141,17 @@ class XCppTests(jupyter_kernel_test.KernelTests):
141141 # language_info.name in a kernel_info_reply should match this
142142 language_name = 'C++'
143143
144- # Code that should write the exact string `hello, world` to STDOUT
145- code_hello_world = """
146- #include "stdafx.h"
144+ code_err = """
147145 #include <iostream>
148- std::cout << "hello, world " << std::endl;
146+ std::cerr << "oops " << std::endl;"
149147 """
150-
151- # Code that should cause (any) text to be written to STDERR
152- code_stderr = """
153- #include "stdafx.h"
154- #include <iostream>
155- std::cerr << "oops" << std::endl;"""
156-
157- # Pager: code that should display something (anything) in the pager
158- code_page_something = "?std::vector"
159-
160- # Exception throwing
161- # TODO: Remove 'if' when test work on MacOS/arm64. Throw Exceptions make
162- # kernel/test non-workable.
163- ###code_generate_error = 'throw std::runtime_error("Unknown exception");' if platform.system() != "Darwin" or platform.processor() != 'arm' else ''
164-
165- # Samples of code which generate a result value (ie, some text
166- # displayed as Out[n])
167- #code_execute_result = [
168- # {
169- # 'code': '6 * 7',
170- # 'result': '42'
171- # }
172- #]
173-
174- # Samples of code which should generate a rich display output, and
175- # the expected MIME type
176- code_display_data = [
177- {
178- 'code' : """
179- #include "stdafx.h"
180- #include <string>
181- #include "xcpp/xdisplay.hpp"
182- std::string test("foobar");
183- xcpp::display(test);
184- """ ,
185- 'mime' : 'text/plain'
186- },
187- {
188- 'code' : """
189- #include "stdafx.h"
190- #include <string>
191- #include <fstream>
192- #include "nlohmann/json.hpp"
193- #include "xtl/xbase64.hpp"
194- namespace im {
195- struct image {
196- inline image(const std::string& filename) {
197- std::ifstream fin(filename, std::ios::binary);
198- m_buffer << fin.rdbuf();
199- }
200- std::stringstream m_buffer;
201- };
202- nlohmann::json mime_bundle_repr(const image& i) {
203- auto bundle = nlohmann::json::object();
204- bundle["image/png"] = xtl::base64encode(i.m_buffer.str());
205- return bundle;
206- }
207- }
208- #include "xcpp/xdisplay.hpp"
209- im::image marie("../notebooks/images/marie.png");
210- xcpp::display(marie);
211- """ ,
212- 'mime' : 'image/png'
213- }
214- ]
148+
149+ def test_xcpp_err (self ):
150+ self .flush_channels ()
151+ reply , output_msgs = self .execute_helper (code = self .code_err ,timeout = 5 )
152+ self .assertEqual (output_msgs [0 ]['msg_type' ], 'stream' )
153+ self .assertEqual (output_msgs [0 ]['content' ]['name' ], 'stderr' )
154+ self .assertEqual (output_msgs [0 ]['content' ]['text' ], 'oops\n ' )
215155
216156class XCppTests2 (jupyter_kernel_test .KernelTests ):
217157
@@ -225,4 +165,4 @@ class XCppTests2(jupyter_kernel_test.KernelTests):
225165
226166
227167if __name__ == '__main__' :
228- unittest .main ()
168+ unittest .main ()
0 commit comments