Compare commits
22 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14b64b75af | ||
|
|
8353711aec | ||
|
|
d778415115 | ||
|
|
715eb251d6 | ||
|
|
b47ecc8029 | ||
|
|
6ff579c6fc | ||
|
|
d13ae02137 | ||
|
|
f292f75025 | ||
|
|
f70e25b5d6 | ||
|
|
c7b6f0e334 | ||
|
|
98e922d83b | ||
|
|
ed77e0db6b | ||
|
|
8b4af5d04a | ||
|
|
abb5eb002f | ||
|
|
cf06ac4f13 | ||
|
|
468f62bc99 | ||
|
|
14b0072979 | ||
|
|
def077ae50 | ||
|
|
ae40bd3eac | ||
|
|
4bff22283c | ||
|
|
83fd7dd20d | ||
|
|
7388acfbdb |
8 changed files with 39 additions and 1316 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -19,3 +19,12 @@
|
|||
/xeus-1.0.3.tar.gz
|
||||
/xeus-1.0.4.tar.gz
|
||||
/xeus-2.0.0.tar.gz
|
||||
/xeus-3.0.5.tar.gz
|
||||
/xeus-3.1.1.tar.gz
|
||||
/xeus-3.1.3.tar.gz
|
||||
/xeus-3.1.4.tar.gz
|
||||
/xeus-3.1.5.tar.gz
|
||||
/xeus-5.1.1.tar.gz
|
||||
/xeus-5.2.3.tar.gz
|
||||
/xeus-5.2.4.tar.gz
|
||||
/xeus-5.2.6.tar.gz
|
||||
|
|
|
|||
18
.packit.yaml
Normal file
18
.packit.yaml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# See the documentation for more information:
|
||||
# https://packit.dev/docs/configuration/
|
||||
---
|
||||
jobs:
|
||||
- job: pull_from_upstream
|
||||
trigger: release
|
||||
dist_git_branches:
|
||||
rawhide:
|
||||
fast_forward_merge_into:
|
||||
- fedora-branched
|
||||
- job: koji_build
|
||||
trigger: commit
|
||||
dist_git_branches:
|
||||
- fedora-all
|
||||
- job: bodhi_update
|
||||
trigger: commit
|
||||
dist_git_branches:
|
||||
- fedora-all
|
||||
|
|
@ -1,523 +0,0 @@
|
|||
From 8964ef30354f59c19ed5f723c579350eb249c0ba Mon Sep 17 00:00:00 2001
|
||||
From: Thorsten Beier <derthorstenbeier@gmail.com>
|
||||
Date: Tue, 21 Sep 2021 13:33:39 +0200
|
||||
Subject: [PATCH 1/3] switched from gtest to doctest (#292)
|
||||
|
||||
Switchted to doctest
|
||||
|
||||
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
---
|
||||
.appveyor.yml | 4 +-
|
||||
.azure-pipelines/unix-build.yml | 2 +-
|
||||
CMakeLists.txt | 3 +-
|
||||
environment-dev.yml | 1 +
|
||||
test/CMakeLists.txt | 55 +---------
|
||||
test/copyGTest.cmake.in | 23 ----
|
||||
test/downloadGTest.cmake.in | 24 -----
|
||||
test/test_main.cpp | 2 +
|
||||
test/test_unit_kernel.cpp | 36 ++++---
|
||||
test/test_xin_memory_history_manager.cpp | 130 ++++++++++++-----------
|
||||
10 files changed, 98 insertions(+), 182 deletions(-)
|
||||
delete mode 100644 test/copyGTest.cmake.in
|
||||
delete mode 100644 test/downloadGTest.cmake.in
|
||||
create mode 100644 test/test_main.cpp
|
||||
|
||||
diff --git a/.appveyor.yml b/.appveyor.yml
|
||||
index e6596e8..a4d8393 100644
|
||||
--- a/.appveyor.yml
|
||||
+++ b/.appveyor.yml
|
||||
@@ -29,12 +29,12 @@ install:
|
||||
- conda update -q conda
|
||||
- conda info -a
|
||||
- conda install mamba -c conda-forge
|
||||
- - mamba install cmake cppzmq=4.7.1 zeromq=4.3.2 xtl=0.7 nlohmann_json OpenSSL=1 -c conda-forge
|
||||
+ - mamba install cmake cppzmq=4.7.1 zeromq=4.3.2 xtl=0.7 nlohmann_json OpenSSL=1 doctest -c conda-forge
|
||||
- mamba install pytest jupyter_kernel_test=0.3.0 -c conda-forge
|
||||
# Build
|
||||
- mkdir build
|
||||
- cd build
|
||||
- - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -D XEUS_DOWNLOAD_GTEST=ON -Dgtest_force_shared_crt=ON ..
|
||||
+ - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -D XEUS_BUILD_TESTS=ON ..
|
||||
- nmake install
|
||||
# Build example
|
||||
- cd ..\example
|
||||
diff --git a/.azure-pipelines/unix-build.yml b/.azure-pipelines/unix-build.yml
|
||||
index 733972b..cfe556b 100644
|
||||
--- a/.azure-pipelines/unix-build.yml
|
||||
+++ b/.azure-pipelines/unix-build.yml
|
||||
@@ -25,7 +25,7 @@ steps:
|
||||
if [[ $(xeus_build_shared_lib) == '0' ]]; then
|
||||
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXEUS_BUILD_SHARED_LIBS=OFF";
|
||||
fi
|
||||
- cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DXEUS_DOWNLOAD_GTEST=ON -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX $CMAKE_EXTRA_ARGS $(Build.SourcesDirectory)
|
||||
+ cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DXEUS_BUILD_TESTS=ON -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX $CMAKE_EXTRA_ARGS $(Build.SourcesDirectory)
|
||||
displayName: Configure xeus
|
||||
workingDirectory: $(Build.BinariesDirectory)
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 41e6692..5cd2aab 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -55,7 +55,6 @@ option(XEUS_STATIC_DEPENDENCIES "link statically with xeus dependencies" OFF)
|
||||
|
||||
# Test options
|
||||
option(XEUS_BUILD_TESTS "xeus test suite" OFF)
|
||||
-option(XEUS_DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
|
||||
|
||||
# Static build configuration
|
||||
# ==========================
|
||||
@@ -352,7 +351,7 @@ endif ()
|
||||
|
||||
include(CTest)
|
||||
|
||||
-if(XEUS_DOWNLOAD_GTEST OR GTEST_SRC_DIR OR XEUS_BUILD_TESTS)
|
||||
+if(XEUS_BUILD_TESTS)
|
||||
set(BUILD_TESTING ON)
|
||||
message(STATUS "tests enabled")
|
||||
else ()
|
||||
diff --git a/environment-dev.yml b/environment-dev.yml
|
||||
index a6c688a..d109add 100644
|
||||
--- a/environment-dev.yml
|
||||
+++ b/environment-dev.yml
|
||||
@@ -14,5 +14,6 @@ dependencies:
|
||||
- libopenssl-static=1
|
||||
- nlohmann_json
|
||||
# Test dependencies
|
||||
+ - doctest >= 2.4.6
|
||||
- pytest
|
||||
- jupyter_kernel_test=0.3.0
|
||||
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||
index 61aaade..b24a3e5 100644
|
||||
--- a/test/CMakeLists.txt
|
||||
+++ b/test/CMakeLists.txt
|
||||
@@ -48,44 +48,15 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
|
||||
endif()
|
||||
|
||||
-if(XEUS_DOWNLOAD_GTEST OR GTEST_SRC_DIR)
|
||||
- if(XEUS_DOWNLOAD_GTEST)
|
||||
- # Download and unpack googletest at configure time
|
||||
- configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt)
|
||||
- else()
|
||||
- # Copy local source of googletest at configure time
|
||||
- configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt)
|
||||
- endif()
|
||||
- execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
- RESULT_VARIABLE result
|
||||
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
- if(result)
|
||||
- message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
- endif()
|
||||
- execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
- RESULT_VARIABLE result
|
||||
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
- if(result)
|
||||
- message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
||||
- endif()
|
||||
|
||||
- # Add googletest directly to our build. This defines
|
||||
- # the gtest and gtest_main targets.
|
||||
- add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
- ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
|
||||
+find_package(doctest REQUIRED)
|
||||
|
||||
- set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
|
||||
- set(GTEST_BOTH_LIBRARIES gtest_main gtest)
|
||||
-else()
|
||||
- find_package(GTest REQUIRED)
|
||||
-endif()
|
||||
|
||||
find_package(Threads)
|
||||
|
||||
-find_program(PYTEST
|
||||
- NAMES pytest-3 pytest py.test-3 py.test)
|
||||
+find_program(PYTEST
|
||||
+ NAMES pytest-3 pytest py.test-3 py.test REQUIRED)
|
||||
|
||||
-include_directories(${GTEST_INCLUDE_DIRS})
|
||||
|
||||
set(XEUS_TESTS
|
||||
test_xin_memory_history_manager.cpp
|
||||
@@ -113,27 +84,11 @@ endif ()
|
||||
foreach(filename IN LISTS XEUS_TESTS)
|
||||
get_filename_component(targetname ${filename} NAME_WE)
|
||||
|
||||
- add_executable(${targetname} ${filename})
|
||||
- target_link_libraries(${targetname} PRIVATE ${xeus_TARGET} ${GTEST_BOTH_LIBRARIES} Threads::Threads ${nlohmann_json_TARGET})
|
||||
-
|
||||
+ add_executable(${targetname} test_main.cpp ${filename})
|
||||
+ target_link_libraries(${targetname} PRIVATE ${xeus_TARGET} doctest::doctest Threads::Threads ${nlohmann_json_TARGET})
|
||||
add_test(NAME ${targetname} COMMAND ${targetname})
|
||||
endforeach()
|
||||
|
||||
-if(XEUS_DOWNLOAD_GTEST OR GTEST_SRC_DIR)
|
||||
- # https://github.com/jupyter-xeus/xeus/pull/126
|
||||
- # This should really just be post gtest and gtest_main targets, but CMake
|
||||
- # won't allow us to do that. So do it after the last test (which depends on
|
||||
- # those anyway.)
|
||||
- if (XEUS_BUILD_SHARED_LIBS)
|
||||
- add_custom_command(
|
||||
- TARGET ${targetname} POST_BUILD
|
||||
- COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:gtest>" "${CMAKE_CURRENT_BINARY_DIR}/")
|
||||
-
|
||||
- add_custom_command(
|
||||
- TARGET ${targetname} POST_BUILD
|
||||
- COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:gtest_main>" "${CMAKE_CURRENT_BINARY_DIR}/")
|
||||
- endif ()
|
||||
-endif()
|
||||
|
||||
# Test_kernel tests
|
||||
# =================
|
||||
diff --git a/test/copyGTest.cmake.in b/test/copyGTest.cmake.in
|
||||
deleted file mode 100644
|
||||
index 1e5d3ed..0000000
|
||||
--- a/test/copyGTest.cmake.in
|
||||
+++ /dev/null
|
||||
@@ -1,23 +0,0 @@
|
||||
-############################################################################
|
||||
-# Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht #
|
||||
-# #
|
||||
-# Distributed under the terms of the BSD 3-Clause License. #
|
||||
-# #
|
||||
-# The full license is in the file LICENSE, distributed with this software. #
|
||||
-############################################################################
|
||||
-
|
||||
-cmake_minimum_required(VERSION 2.8.2)
|
||||
-
|
||||
-project(googletest-download NONE)
|
||||
-
|
||||
-include(ExternalProject)
|
||||
-ExternalProject_Add(googletest
|
||||
- URL "${GTEST_SRC_DIR}"
|
||||
- SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
- BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
- CONFIGURE_COMMAND ""
|
||||
- BUILD_COMMAND ""
|
||||
- INSTALL_COMMAND ""
|
||||
- TEST_COMMAND ""
|
||||
-)
|
||||
-
|
||||
diff --git a/test/downloadGTest.cmake.in b/test/downloadGTest.cmake.in
|
||||
deleted file mode 100644
|
||||
index 852d43c..0000000
|
||||
--- a/test/downloadGTest.cmake.in
|
||||
+++ /dev/null
|
||||
@@ -1,24 +0,0 @@
|
||||
-############################################################################
|
||||
-# Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht #
|
||||
-# #
|
||||
-# Distributed under the terms of the BSD 3-Clause License. #
|
||||
-# #
|
||||
-# The full license is in the file LICENSE, distributed with this software. #
|
||||
-############################################################################
|
||||
-
|
||||
-cmake_minimum_required(VERSION 2.8.2)
|
||||
-
|
||||
-project(googletest-download NONE)
|
||||
-
|
||||
-include(ExternalProject)
|
||||
-ExternalProject_Add(googletest
|
||||
- GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
- GIT_TAG release-1.10.0
|
||||
- SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
- BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
- CONFIGURE_COMMAND ""
|
||||
- BUILD_COMMAND ""
|
||||
- INSTALL_COMMAND ""
|
||||
- TEST_COMMAND ""
|
||||
-)
|
||||
-
|
||||
diff --git a/test/test_main.cpp b/test/test_main.cpp
|
||||
new file mode 100644
|
||||
index 0000000..84684c0
|
||||
--- /dev/null
|
||||
+++ b/test/test_main.cpp
|
||||
@@ -0,0 +1,2 @@
|
||||
+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
+#include "doctest/doctest.h"
|
||||
\ No newline at end of file
|
||||
diff --git a/test/test_unit_kernel.cpp b/test/test_unit_kernel.cpp
|
||||
index 74b9f07..ee8709b 100644
|
||||
--- a/test/test_unit_kernel.cpp
|
||||
+++ b/test/test_unit_kernel.cpp
|
||||
@@ -6,9 +6,10 @@
|
||||
* The full license is in the file LICENSE, distributed with this software. *
|
||||
****************************************************************************/
|
||||
|
||||
-#include "gtest/gtest.h"
|
||||
+#include "doctest/doctest.h"
|
||||
|
||||
#include <string>
|
||||
+#include <iostream>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
@@ -20,48 +21,51 @@ namespace nl = nlohmann;
|
||||
|
||||
namespace xeus
|
||||
{
|
||||
- TEST(kernel, get_username)
|
||||
+ TEST_SUITE("kernel") {
|
||||
+
|
||||
+ TEST_CASE("get_username")
|
||||
{
|
||||
std::string username;
|
||||
username = get_user_name();
|
||||
- EXPECT_NE(username, "unspecified user");
|
||||
+ REQUIRE_NE(username, "unspecified user");
|
||||
}
|
||||
|
||||
- TEST(kernel, find_free_port)
|
||||
+ TEST_CASE("find_free_port")
|
||||
{
|
||||
std::string port = find_free_port();
|
||||
- EXPECT_NE(port, "");
|
||||
- EXPECT_EQ(port.length(), std::size_t(5));
|
||||
+ REQUIRE_NE(port, "");
|
||||
+ REQUIRE_EQ(port.length(), std::size_t(5));
|
||||
}
|
||||
|
||||
- TEST(kernel, temp_directory_path)
|
||||
+ TEST_CASE("temp_directory_path")
|
||||
{
|
||||
std::string path = get_temp_directory_path();
|
||||
std::cout << "Temporary directory path: " << path << std::endl;
|
||||
- EXPECT_NE(path, "");
|
||||
- EXPECT_NE(path.back(), '/');
|
||||
- EXPECT_NE(path.back(), '\\');
|
||||
+ REQUIRE_NE(path, "");
|
||||
+ REQUIRE_NE(path.back(), '/');
|
||||
+ REQUIRE_NE(path.back(), '\\');
|
||||
}
|
||||
|
||||
- TEST(kernel, create_directory)
|
||||
+ TEST_CASE("create_directory")
|
||||
{
|
||||
std::string temp_path = get_temp_directory_path();
|
||||
std::string path = temp_path + "/intermediate/logs";
|
||||
bool res = create_directory(path);
|
||||
- EXPECT_TRUE(res);
|
||||
+ REQUIRE_UNARY(res);
|
||||
}
|
||||
|
||||
- TEST(kernel, get_current_pid)
|
||||
+ TEST_CASE("get_current_pid")
|
||||
{
|
||||
int pid = get_current_pid();
|
||||
- EXPECT_NE(pid, -1);
|
||||
+ REQUIRE_NE(pid, -1);
|
||||
}
|
||||
|
||||
- TEST(kernel, get_tmp_hash_seed)
|
||||
+ TEST_CASE("get_tmp_hash_seed")
|
||||
{
|
||||
size_t hs = get_tmp_hash_seed();
|
||||
size_t expected = static_cast<std::size_t>(0xc70f6907UL);
|
||||
- EXPECT_EQ(hs, expected);
|
||||
+ REQUIRE_EQ(hs, expected);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/test/test_xin_memory_history_manager.cpp b/test/test_xin_memory_history_manager.cpp
|
||||
index df2275a..a204ca1 100644
|
||||
--- a/test/test_xin_memory_history_manager.cpp
|
||||
+++ b/test/test_xin_memory_history_manager.cpp
|
||||
@@ -6,7 +6,7 @@
|
||||
* The full license is in the file LICENSE, distributed with this software. *
|
||||
****************************************************************************/
|
||||
|
||||
-#include "gtest/gtest.h"
|
||||
+#include "doctest/doctest.h"
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
@@ -23,7 +23,8 @@ namespace xeus
|
||||
using history_manager_ptr = std::unique_ptr<xhistory_manager>;
|
||||
using history_type = std::vector<std::array<std::string, 3>>;
|
||||
|
||||
- TEST(xin_memory_history_manager, get_tail)
|
||||
+ TEST_SUITE("xin_memory_history_manager"){
|
||||
+ TEST_CASE("get_tail")
|
||||
{
|
||||
history_manager_ptr hist = xeus::make_in_memory_history_manager();
|
||||
hist->store_inputs(0, 1, "print(3)");
|
||||
@@ -32,29 +33,29 @@ namespace xeus
|
||||
hist->store_inputs(0, 4, "a");
|
||||
|
||||
nl::json tail1 = hist->get_tail(1000, true, false);
|
||||
- ASSERT_EQ(tail1["status"], "ok");
|
||||
+ REQUIRE_EQ(tail1["status"], "ok");
|
||||
auto history1 = tail1["history"].get<history_type>();
|
||||
- ASSERT_EQ(history1.size(), std::size_t(4));
|
||||
- ASSERT_EQ(history1[0][1], "1");
|
||||
- ASSERT_EQ(history1[0][2], "print(3)");
|
||||
- ASSERT_EQ(history1[1][1], "2");
|
||||
- ASSERT_EQ(history1[1][2], "a = 3");
|
||||
- ASSERT_EQ(history1[2][1], "3");
|
||||
- ASSERT_EQ(history1[2][2], "print(a)");
|
||||
- ASSERT_EQ(history1[3][1], "4");
|
||||
- ASSERT_EQ(history1[3][2], "a");
|
||||
+ REQUIRE_EQ(history1.size(), std::size_t(4));
|
||||
+ REQUIRE_EQ(history1[0][1], "1");
|
||||
+ REQUIRE_EQ(history1[0][2], "print(3)");
|
||||
+ REQUIRE_EQ(history1[1][1], "2");
|
||||
+ REQUIRE_EQ(history1[1][2], "a = 3");
|
||||
+ REQUIRE_EQ(history1[2][1], "3");
|
||||
+ REQUIRE_EQ(history1[2][2], "print(a)");
|
||||
+ REQUIRE_EQ(history1[3][1], "4");
|
||||
+ REQUIRE_EQ(history1[3][2], "a");
|
||||
|
||||
nl::json tail2 = hist->get_tail(2, true, false);
|
||||
- ASSERT_EQ(tail2["status"], "ok");
|
||||
+ REQUIRE_EQ(tail2["status"], "ok");
|
||||
auto history2 = tail2["history"].get<history_type>();
|
||||
- ASSERT_EQ(history2.size(), std::size_t(2));
|
||||
- ASSERT_EQ(history2[0][1], "3");
|
||||
- ASSERT_EQ(history2[0][2], "print(a)");
|
||||
- ASSERT_EQ(history2[1][1], "4");
|
||||
- ASSERT_EQ(history2[1][2], "a");
|
||||
+ REQUIRE_EQ(history2.size(), std::size_t(2));
|
||||
+ REQUIRE_EQ(history2[0][1], "3");
|
||||
+ REQUIRE_EQ(history2[0][2], "print(a)");
|
||||
+ REQUIRE_EQ(history2[1][1], "4");
|
||||
+ REQUIRE_EQ(history2[1][2], "a");
|
||||
}
|
||||
|
||||
- TEST(xin_memory_history_manager, get_range)
|
||||
+ TEST_CASE("get_range")
|
||||
{
|
||||
history_manager_ptr hist = xeus::make_in_memory_history_manager();
|
||||
hist->store_inputs(0, 1, "print(3)");
|
||||
@@ -63,26 +64,26 @@ namespace xeus
|
||||
hist->store_inputs(0, 4, "a");
|
||||
|
||||
nl::json range1 = hist->get_range(0, 1, 2, true, false);
|
||||
- ASSERT_EQ(range1["status"], "ok");
|
||||
+ REQUIRE_EQ(range1["status"], "ok");
|
||||
auto history1 = range1["history"].get<history_type>();
|
||||
- ASSERT_EQ(history1.size(), std::size_t(1));
|
||||
- ASSERT_EQ(history1[0][1], "2");
|
||||
- ASSERT_EQ(history1[0][2], "a = 3");
|
||||
+ REQUIRE_EQ(history1.size(), std::size_t(1));
|
||||
+ REQUIRE_EQ(history1[0][1], "2");
|
||||
+ REQUIRE_EQ(history1[0][2], "a = 3");
|
||||
|
||||
nl::json range2 = hist->get_range(0, 1, 3, true, false);
|
||||
- ASSERT_EQ(range2["status"], "ok");
|
||||
+ REQUIRE_EQ(range2["status"], "ok");
|
||||
auto history2 = range2["history"].get<history_type>();
|
||||
- ASSERT_EQ(history2.size(), std::size_t(2));
|
||||
- ASSERT_EQ(history2[0][1], "2");
|
||||
- ASSERT_EQ(history2[0][2], "a = 3");
|
||||
- ASSERT_EQ(history2[1][1], "3");
|
||||
- ASSERT_EQ(history2[1][2], "print(a)");
|
||||
+ REQUIRE_EQ(history2.size(), std::size_t(2));
|
||||
+ REQUIRE_EQ(history2[0][1], "2");
|
||||
+ REQUIRE_EQ(history2[0][2], "a = 3");
|
||||
+ REQUIRE_EQ(history2[1][1], "3");
|
||||
+ REQUIRE_EQ(history2[1][2], "print(a)");
|
||||
|
||||
nl::json range3 = hist->get_range(0, 1000, 2, true, false);
|
||||
- ASSERT_EQ(range3["status"], "error");
|
||||
+ REQUIRE_EQ(range3["status"], "error");
|
||||
}
|
||||
|
||||
- TEST(xin_memory_history_manager, search)
|
||||
+ TEST_CASE("search")
|
||||
{
|
||||
history_manager_ptr hist = xeus::make_in_memory_history_manager();
|
||||
hist->store_inputs(0, 1, "print(36)");
|
||||
@@ -91,55 +92,56 @@ namespace xeus
|
||||
hist->store_inputs(0, 4, "a");
|
||||
|
||||
nl::json search1 = hist->search("print*", true, false, 10, false);
|
||||
- ASSERT_EQ(search1["status"], "ok");
|
||||
+ REQUIRE_EQ(search1["status"], "ok");
|
||||
auto history1 = search1["history"].get<history_type>();
|
||||
- ASSERT_EQ(history1.size(), std::size_t(2));
|
||||
- ASSERT_EQ(history1[0][1], "1");
|
||||
- ASSERT_EQ(history1[0][2], "print(36)");
|
||||
- ASSERT_EQ(history1[1][1], "3");
|
||||
- ASSERT_EQ(history1[1][2], "print(a)");
|
||||
+ REQUIRE_EQ(history1.size(), std::size_t(2));
|
||||
+ REQUIRE_EQ(history1[0][1], "1");
|
||||
+ REQUIRE_EQ(history1[0][2], "print(36)");
|
||||
+ REQUIRE_EQ(history1[1][1], "3");
|
||||
+ REQUIRE_EQ(history1[1][2], "print(a)");
|
||||
|
||||
nl::json search2 = hist->search("print(*)", true, false, 10, false);
|
||||
- ASSERT_EQ(search2["status"], "ok");
|
||||
+ REQUIRE_EQ(search2["status"], "ok");
|
||||
auto history2 = search2["history"].get<history_type>();
|
||||
- ASSERT_EQ(history2.size(), std::size_t(2));
|
||||
- ASSERT_EQ(history2[0][1], "1");
|
||||
- ASSERT_EQ(history2[0][2], "print(36)");
|
||||
- ASSERT_EQ(history2[1][1], "3");
|
||||
- ASSERT_EQ(history2[1][2], "print(a)");
|
||||
+ REQUIRE_EQ(history2.size(), std::size_t(2));
|
||||
+ REQUIRE_EQ(history2[0][1], "1");
|
||||
+ REQUIRE_EQ(history2[0][2], "print(36)");
|
||||
+ REQUIRE_EQ(history2[1][1], "3");
|
||||
+ REQUIRE_EQ(history2[1][2], "print(a)");
|
||||
|
||||
nl::json search3 = hist->search("print(?)", true, false, 10, false);
|
||||
- ASSERT_EQ(search3["status"], "ok");
|
||||
+ REQUIRE_EQ(search3["status"], "ok");
|
||||
auto history3 = search3["history"].get<history_type>();
|
||||
- ASSERT_EQ(history3.size(), std::size_t(1));
|
||||
- ASSERT_EQ(history3[0][1], "3");
|
||||
- ASSERT_EQ(history3[0][2], "print(a)");
|
||||
+ REQUIRE_EQ(history3.size(), std::size_t(1));
|
||||
+ REQUIRE_EQ(history3[0][1], "3");
|
||||
+ REQUIRE_EQ(history3[0][2], "print(a)");
|
||||
|
||||
nl::json search4 = hist->search("print*", true, false, 1, false);
|
||||
- ASSERT_EQ(search4["status"], "ok");
|
||||
+ REQUIRE_EQ(search4["status"], "ok");
|
||||
auto history4 = search4["history"].get<history_type>();
|
||||
- ASSERT_EQ(history4.size(), std::size_t(1));
|
||||
- ASSERT_EQ(history4[0][1], "3");
|
||||
- ASSERT_EQ(history4[0][2], "print(a)");
|
||||
+ REQUIRE_EQ(history4.size(), std::size_t(1));
|
||||
+ REQUIRE_EQ(history4[0][1], "3");
|
||||
+ REQUIRE_EQ(history4[0][2], "print(a)");
|
||||
|
||||
hist->store_inputs(0, 3, "print(a)");
|
||||
nl::json search5 = hist->search("print*", true, false, 10, false);
|
||||
- ASSERT_EQ(search5["status"], "ok");
|
||||
+ REQUIRE_EQ(search5["status"], "ok");
|
||||
auto history5 = search5["history"].get<history_type>();
|
||||
- ASSERT_EQ(history5.size(), std::size_t(3));
|
||||
- ASSERT_EQ(history2[0][1], "1");
|
||||
- ASSERT_EQ(history2[0][2], "print(36)");
|
||||
- ASSERT_EQ(history5[1][1], "3");
|
||||
- ASSERT_EQ(history5[1][2], "print(a)");
|
||||
- ASSERT_EQ(history5[2][1], "3");
|
||||
- ASSERT_EQ(history5[2][2], "print(a)");
|
||||
+ REQUIRE_EQ(history5.size(), std::size_t(3));
|
||||
+ REQUIRE_EQ(history2[0][1], "1");
|
||||
+ REQUIRE_EQ(history2[0][2], "print(36)");
|
||||
+ REQUIRE_EQ(history5[1][1], "3");
|
||||
+ REQUIRE_EQ(history5[1][2], "print(a)");
|
||||
+ REQUIRE_EQ(history5[2][1], "3");
|
||||
+ REQUIRE_EQ(history5[2][2], "print(a)");
|
||||
|
||||
nl::json search6 = hist->search("print*", true, false, 10, true);
|
||||
- ASSERT_EQ(search6["status"], "ok");
|
||||
+ REQUIRE_EQ(search6["status"], "ok");
|
||||
auto history6 = search6["history"].get<history_type>();
|
||||
- ASSERT_EQ(history2[0][1], "1");
|
||||
- ASSERT_EQ(history2[0][2], "print(36)");
|
||||
- ASSERT_EQ(history5[1][1], "3");
|
||||
- ASSERT_EQ(history5[1][2], "print(a)");
|
||||
+ REQUIRE_EQ(history2[0][1], "1");
|
||||
+ REQUIRE_EQ(history2[0][2], "print(36)");
|
||||
+ REQUIRE_EQ(history5[1][1], "3");
|
||||
+ REQUIRE_EQ(history5[1][2], "print(a)");
|
||||
+ }
|
||||
}
|
||||
}
|
||||
--
|
||||
2.36.1
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
From 206f54ea54c0a5355adb1531e0d523501aa9c2b9 Mon Sep 17 00:00:00 2001
|
||||
From: Johan Mabille <johan.mabille@gmail.com>
|
||||
Date: Fri, 24 Sep 2021 00:48:26 +0200
|
||||
Subject: [PATCH 2/3] Never delete context before sockets
|
||||
|
||||
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
---
|
||||
include/xeus/xkernel.hpp | 5 ++++-
|
||||
src/xkernel.cpp | 4 ++--
|
||||
2 files changed, 6 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/include/xeus/xkernel.hpp b/include/xeus/xkernel.hpp
|
||||
index 4ef0dd3..d32c07e 100644
|
||||
--- a/include/xeus/xkernel.hpp
|
||||
+++ b/include/xeus/xkernel.hpp
|
||||
@@ -84,13 +84,16 @@ namespace xeus
|
||||
std::string m_kernel_id;
|
||||
std::string m_session_id;
|
||||
std::string m_user_name;
|
||||
+ // The context must be declared before any other
|
||||
+ // middleware component since it must be destroyed
|
||||
+ // last
|
||||
+ context_ptr p_context;
|
||||
interpreter_ptr p_interpreter;
|
||||
history_manager_ptr p_history_manager;
|
||||
logger_ptr p_logger;
|
||||
server_ptr p_server;
|
||||
debugger_builder m_debugger_builder;
|
||||
debugger_ptr p_debugger;
|
||||
- context_ptr p_context;
|
||||
kernel_core_ptr p_core;
|
||||
nl::json m_debugger_config;
|
||||
nl::json::error_handler_t m_error_handler;
|
||||
diff --git a/src/xkernel.cpp b/src/xkernel.cpp
|
||||
index 2bda8af..c8e263a 100644
|
||||
--- a/src/xkernel.cpp
|
||||
+++ b/src/xkernel.cpp
|
||||
@@ -82,11 +82,11 @@ namespace xeus
|
||||
nl::json::error_handler_t eh)
|
||||
: m_config(config)
|
||||
, m_user_name(user_name)
|
||||
+ , p_context(std::move(context))
|
||||
, p_interpreter(std::move(interpreter))
|
||||
, p_history_manager(std::move(history_manager))
|
||||
, p_logger(std::move(logger))
|
||||
, m_debugger_builder(dbuilder)
|
||||
- , p_context(std::move(context))
|
||||
, m_debugger_config(debugger_config)
|
||||
, m_error_handler(eh)
|
||||
{
|
||||
@@ -103,11 +103,11 @@ namespace xeus
|
||||
nl::json debugger_config,
|
||||
nl::json::error_handler_t eh)
|
||||
: m_user_name(user_name)
|
||||
+ , p_context(std::move(context))
|
||||
, p_interpreter(std::move(interpreter))
|
||||
, p_history_manager(std::move(history_manager))
|
||||
, p_logger(std::move(logger))
|
||||
, m_debugger_builder(dbuilder)
|
||||
- , p_context(std::move(context))
|
||||
, m_debugger_config(debugger_config)
|
||||
, m_error_handler(eh)
|
||||
{
|
||||
--
|
||||
2.36.1
|
||||
|
||||
|
|
@ -1,707 +0,0 @@
|
|||
From 271c3e1c4c134336323b979b6b0d5d702e0baa38 Mon Sep 17 00:00:00 2001
|
||||
From: Mariana Meireles <mariana@psychonautgirl.space>
|
||||
Date: Fri, 24 Sep 2021 07:30:56 +0000
|
||||
Subject: [PATCH 3/3] Fix non-standard messages
|
||||
|
||||
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
||||
---
|
||||
CMakeLists.txt | 4 +-
|
||||
example/src/custom_interpreter.cpp | 61 ++++--------
|
||||
include/xeus/xhelper.hpp | 72 ++++++++++++++
|
||||
src/xhelper.cpp | 155 +++++++++++++++++++++++++++++
|
||||
test/CMakeLists.txt | 3 +-
|
||||
test/test_interpreter.cpp | 78 ++++++---------
|
||||
test/test_unit_kernel.cpp | 127 +++++++++++++++--------
|
||||
7 files changed, 367 insertions(+), 133 deletions(-)
|
||||
create mode 100644 include/xeus/xhelper.hpp
|
||||
create mode 100644 src/xhelper.cpp
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 5cd2aab..b968abb 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -133,6 +133,7 @@ set(XEUS_HEADERS
|
||||
${XEUS_INCLUDE_DIR}/xeus/xkernel_configuration.hpp
|
||||
${XEUS_INCLUDE_DIR}/xeus/xlogger.hpp
|
||||
${XEUS_INCLUDE_DIR}/xeus/xmessage.hpp
|
||||
+ ${XEUS_INCLUDE_DIR}/xeus/xhelper.hpp
|
||||
${XEUS_INCLUDE_DIR}/xeus/xmiddleware.hpp
|
||||
${XEUS_INCLUDE_DIR}/xeus/xserver.hpp
|
||||
${XEUS_INCLUDE_DIR}/xeus/xserver_control_main.hpp
|
||||
@@ -168,6 +169,7 @@ set(XEUS_SOURCES
|
||||
${XEUS_SOURCE_DIR}/xlogger_impl.hpp
|
||||
${XEUS_SOURCE_DIR}/xlogger_impl.cpp
|
||||
${XEUS_SOURCE_DIR}/xmessage.cpp
|
||||
+ ${XEUS_SOURCE_DIR}/xhelper.cpp
|
||||
${XEUS_SOURCE_DIR}/xmock_interpreter.cpp
|
||||
${XEUS_SOURCE_DIR}/xmock_interpreter.hpp
|
||||
${XEUS_SOURCE_DIR}/xmiddleware.cpp
|
||||
@@ -351,7 +353,7 @@ endif ()
|
||||
|
||||
include(CTest)
|
||||
|
||||
-if(XEUS_BUILD_TESTS)
|
||||
+if(XEUS_DOWNLOAD_GTEST OR GTEST_SRC_DIR OR XEUS_BUILD_TESTS)
|
||||
set(BUILD_TESTING ON)
|
||||
message(STATUS "tests enabled")
|
||||
else ()
|
||||
diff --git a/example/src/custom_interpreter.cpp b/example/src/custom_interpreter.cpp
|
||||
index caad375..e2dbfca 100644
|
||||
--- a/example/src/custom_interpreter.cpp
|
||||
+++ b/example/src/custom_interpreter.cpp
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
-
|
||||
+#include "xeus/xhelper.hpp"
|
||||
#include "custom_interpreter.hpp"
|
||||
|
||||
namespace nl = nlohmann;
|
||||
@@ -44,9 +44,7 @@ namespace custom
|
||||
// publish_execution_error(error_name, error_value, error_traceback);
|
||||
publish_execution_error("TypeError", "123", {"!@#$", "*(*"});
|
||||
|
||||
- nl::json result;
|
||||
- result["status"] = "ok";
|
||||
- return result;
|
||||
+ return xeus::create_successful_reply();
|
||||
}
|
||||
|
||||
void custom_interpreter::configure_impl()
|
||||
@@ -57,26 +55,16 @@ namespace custom
|
||||
nl::json custom_interpreter::complete_request_impl(const std::string& code,
|
||||
int cursor_pos)
|
||||
{
|
||||
- nl::json result;
|
||||
-
|
||||
// Code starts with 'H', it could be the following completion
|
||||
if (code[0] == 'H')
|
||||
{
|
||||
- result["status"] = "ok";
|
||||
- result["matches"] = {"Hello", "Hey", "Howdy"};
|
||||
- result["cursor_start"] = 5;
|
||||
- result["cursor_end"] = cursor_pos;
|
||||
+ return xeus::create_complete_reply({"Hello", "Hey", "Howdy"}, 5, cursor_pos);
|
||||
}
|
||||
// No completion result
|
||||
else
|
||||
{
|
||||
- result["status"] = "ok";
|
||||
- result["matches"] = nl::json::array();
|
||||
- result["cursor_start"] = cursor_pos;
|
||||
- result["cursor_end"] = cursor_pos;
|
||||
+ return xeus::create_complete_reply({}, cursor_pos, cursor_pos);
|
||||
}
|
||||
-
|
||||
- return result;
|
||||
}
|
||||
|
||||
nl::json custom_interpreter::inspect_request_impl(const std::string& code,
|
||||
@@ -87,48 +75,33 @@ namespace custom
|
||||
|
||||
if (code.compare("print") == 0)
|
||||
{
|
||||
- result["found"] = true;
|
||||
- result["text/plain"] = "Print objects to the text stream file, [...]";
|
||||
+ return xeus::create_inspect_reply(true,
|
||||
+ {"text/plain", "Print objects to the text stream file, [...]"});
|
||||
}
|
||||
else
|
||||
{
|
||||
- result["found"] = false;
|
||||
+ return xeus::create_inspect_reply();
|
||||
}
|
||||
-
|
||||
- result["status"] = "ok";
|
||||
- return result;
|
||||
}
|
||||
|
||||
nl::json custom_interpreter::is_complete_request_impl(const std::string& /*code*/)
|
||||
{
|
||||
- nl::json result;
|
||||
-
|
||||
- // if (is_complete(code))
|
||||
- // {
|
||||
- result["status"] = "complete";
|
||||
- // }
|
||||
- // else
|
||||
- // {
|
||||
- // result["status"] = "incomplete";
|
||||
- // result["indent"] = 4;
|
||||
- //}
|
||||
-
|
||||
- return result;
|
||||
+ return xeus::create_is_complete_reply("complete");
|
||||
}
|
||||
|
||||
nl::json custom_interpreter::kernel_info_request_impl()
|
||||
{
|
||||
- nl::json result;
|
||||
- result["implementation"] = "my_kernel";
|
||||
- result["implementation_version"] = "0.1.0";
|
||||
- result["language_info"]["name"] = "python";
|
||||
- result["language_info"]["version"] = "3.7";
|
||||
- result["language_info"]["mimetype"] = "text/x-python";
|
||||
- result["language_info"]["file_extension"] = ".py";
|
||||
- return result;
|
||||
+ return xeus::create_info_reply("",
|
||||
+ "my_kernel",
|
||||
+ "0.1.0",
|
||||
+ "python",
|
||||
+ "3.7",
|
||||
+ "text/x-python",
|
||||
+ ".py");
|
||||
}
|
||||
|
||||
- void custom_interpreter::shutdown_request_impl() {
|
||||
+ void custom_interpreter::shutdown_request_impl()
|
||||
+ {
|
||||
std::cout << "Bye!!" << std::endl;
|
||||
}
|
||||
|
||||
diff --git a/include/xeus/xhelper.hpp b/include/xeus/xhelper.hpp
|
||||
new file mode 100644
|
||||
index 0000000..584c150
|
||||
--- /dev/null
|
||||
+++ b/include/xeus/xhelper.hpp
|
||||
@@ -0,0 +1,72 @@
|
||||
+/***************************************************************************
|
||||
+* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou *
|
||||
+* Copyright (c) 2016, QuantStack *
|
||||
+* *
|
||||
+* Distributed under the terms of the BSD 3-Clause License. *
|
||||
+* *
|
||||
+* The full license is in the file LICENSE, distributed with this software. *
|
||||
+****************************************************************************/
|
||||
+
|
||||
+#ifndef XEUS_HELPER_HPP
|
||||
+#define XEUS_HELPER_HPP
|
||||
+
|
||||
+#include <iostream>
|
||||
+#include <string>
|
||||
+#include <vector>
|
||||
+
|
||||
+#include "xeus/xeus.hpp"
|
||||
+#include "xeus/xkernel_configuration.hpp"
|
||||
+
|
||||
+#include "nlohmann/json.hpp"
|
||||
+
|
||||
+namespace nl = nlohmann;
|
||||
+
|
||||
+namespace xeus
|
||||
+{
|
||||
+ XEUS_API std::string print_starting_message(const xconfiguration& config);
|
||||
+
|
||||
+ XEUS_API std::string extract_filename(int argc, char* argv[]);
|
||||
+
|
||||
+ XEUS_API bool should_print_version(int argc, char* argv[]);
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_error_reply(const std::string& ename = std::string(),
|
||||
+ const std::string& evalue = std::string(),
|
||||
+ const nl::json& trace_back = nl::json::array());
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_successful_reply(const nl::json& payload = nl::json::array(),
|
||||
+ const nl::json& user_expressions = nl::json::object());
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_complete_reply(const nl::json& matches,
|
||||
+ const int& cursor_start,
|
||||
+ const int& cursor_end,
|
||||
+ const nl::json& metadata = nl::json::object());
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_inspect_reply(const bool found = false,
|
||||
+ const nl::json& data = nl::json::object(),
|
||||
+ const nl::json& metadata = nl::json::object());
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_is_complete_reply(const std::string& status = std::string(),
|
||||
+ const std::string& indent = std::string(""));
|
||||
+
|
||||
+ XEUS_API
|
||||
+ nl::json create_info_reply(const std::string& protocol_version = std::string(),
|
||||
+ const std::string& implementation = std::string(),
|
||||
+ const std::string& implementation_version = std::string(),
|
||||
+ const std::string& language_name = std::string(),
|
||||
+ const std::string& language_version = std::string(),
|
||||
+ const std::string& language_mimetype = std::string(),
|
||||
+ const std::string& language_file_extension = std::string(),
|
||||
+ const std::string& pygments_lexer = std::string(),
|
||||
+ const std::string& language_codemirror_mode = std::string(),
|
||||
+ const std::string& language_nbconvert_exporter = std::string(),
|
||||
+ const std::string& banner = std::string(),
|
||||
+ const bool debugger = false,
|
||||
+ const nl::json& help_links = nl::json::array());
|
||||
+}
|
||||
+
|
||||
+#endif
|
||||
diff --git a/src/xhelper.cpp b/src/xhelper.cpp
|
||||
new file mode 100644
|
||||
index 0000000..7526f0d
|
||||
--- /dev/null
|
||||
+++ b/src/xhelper.cpp
|
||||
@@ -0,0 +1,155 @@
|
||||
+#include <string>
|
||||
+#include <vector>
|
||||
+
|
||||
+#include "nlohmann/json.hpp"
|
||||
+
|
||||
+#include "xeus/xhelper.hpp"
|
||||
+
|
||||
+namespace nl = nlohmann;
|
||||
+
|
||||
+namespace xeus
|
||||
+{
|
||||
+ std::string print_starting_message(const xconfiguration& config)
|
||||
+ {
|
||||
+ std::string kernel_info;
|
||||
+ kernel_info = "Starting kernel...\n\n"
|
||||
+ "If you want to connect to this kernel from an other client, just copy"
|
||||
+ " and paste the following content inside of a `kernel.json` file. And then run for example:\n\n"
|
||||
+ "# jupyter console --existing kernel.json\n\n"
|
||||
+ "kernel.json\n```\n{\n"
|
||||
+ " \"transport\": \"" + config.m_transport + "\",\n"
|
||||
+ " \"ip\": \"" + config.m_ip + "\",\n"
|
||||
+ " \"control_port\": " + config.m_control_port + ",\n"
|
||||
+ " \"shell_port\": " + config.m_shell_port + ",\n"
|
||||
+ " \"stdin_port\": " + config.m_stdin_port + ",\n"
|
||||
+ " \"iopub_port\": " + config.m_iopub_port + ",\n"
|
||||
+ " \"hb_port\": " + config.m_hb_port + ",\n"
|
||||
+ " \"signature_scheme\": \"" + config.m_signature_scheme + "\",\n"
|
||||
+ " \"key\": \"" + config.m_key + "\"\n"
|
||||
+ "}\n```";
|
||||
+ return kernel_info;
|
||||
+ }
|
||||
+
|
||||
+ std::string extract_filename(int argc, char* argv[])
|
||||
+ {
|
||||
+ std::string res = "";
|
||||
+ for (int i = 0; i < argc; ++i)
|
||||
+ {
|
||||
+ if ((std::string(argv[i]) == "-f") && (i + 1 < argc))
|
||||
+ {
|
||||
+ res = argv[i + 1];
|
||||
+ for(int j = i; j < argc - 2; ++j)
|
||||
+ {
|
||||
+ argv[j] = argv[j + 2];
|
||||
+ }
|
||||
+ argc -= 2;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ return res;
|
||||
+ }
|
||||
+
|
||||
+ bool should_print_version(int argc, char* argv[])
|
||||
+ {
|
||||
+ for (int i = 0; i < argc; ++i)
|
||||
+ {
|
||||
+ if (std::string(argv[i]) == "--version")
|
||||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ // Helpers that create replies to the server
|
||||
+ nl::json create_error_reply(const std::string& evalue,
|
||||
+ const std::string& ename,
|
||||
+ const nl::json& trace_back)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = "error";
|
||||
+ kernel_res["ename"] = ename;
|
||||
+ kernel_res["evalue"] = evalue;
|
||||
+ kernel_res["traceback"] = trace_back;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+ nl::json create_successful_reply(const nl::json& payload,
|
||||
+ const nl::json& user_expressions)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = "ok";
|
||||
+ kernel_res["payload"] = payload;
|
||||
+ kernel_res["user_expressions"] = user_expressions;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+ nl::json create_complete_reply(const nl::json& matches,
|
||||
+ const int& cursor_start,
|
||||
+ const int& cursor_end,
|
||||
+ const nl::json& metadata)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = "ok";
|
||||
+ kernel_res["matches"] = matches;
|
||||
+ kernel_res["cursor_start"] = cursor_start;
|
||||
+ kernel_res["cursor_end"] = cursor_end;
|
||||
+ kernel_res["metadata"] = metadata;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+ nl::json create_inspect_reply(const bool found,
|
||||
+ const nl::json& data,
|
||||
+ const nl::json& metadata)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = "ok";
|
||||
+ kernel_res["found"] = found;
|
||||
+ kernel_res["data"] = data;
|
||||
+ kernel_res["metadata"] = metadata;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+ nl::json create_is_complete_reply(const std::string& status,
|
||||
+ const std::string& indent)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = status;
|
||||
+ kernel_res["indent"] = indent;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+ nl::json create_info_reply(const std::string& protocol_version,
|
||||
+ const std::string& implementation,
|
||||
+ const std::string& implementation_version,
|
||||
+ const std::string& language_name,
|
||||
+ const std::string& language_version,
|
||||
+ const std::string& language_mimetype,
|
||||
+ const std::string& language_file_extension,
|
||||
+ const std::string& language_pygments_lexer,
|
||||
+ const std::string& language_codemirror_mode,
|
||||
+ const std::string& language_nbconvert_exporter,
|
||||
+ const std::string& banner,
|
||||
+ const bool debugger,
|
||||
+ const nl::json& help_links)
|
||||
+ {
|
||||
+ nl::json kernel_res;
|
||||
+ kernel_res["status"] = "ok";
|
||||
+ kernel_res["protocol_version"] = protocol_version;
|
||||
+ kernel_res["implementation"] = implementation;
|
||||
+ kernel_res["implementation_version"] = implementation_version;
|
||||
+ kernel_res["language_info"]["name"] = language_name;
|
||||
+ kernel_res["language_info"]["version"] = language_version;
|
||||
+ kernel_res["language_info"]["mimetype"] = language_mimetype;
|
||||
+ kernel_res["language_info"]["file_extension"] = language_file_extension;
|
||||
+ kernel_res["language_info"]["pygments_lexer"] = language_pygments_lexer;
|
||||
+ kernel_res["language_info"]["codemirror_mode"] = language_codemirror_mode;
|
||||
+ kernel_res["language_info"]["nbconvert_exporter"] = language_nbconvert_exporter;
|
||||
+ kernel_res["banner"] = banner;
|
||||
+ kernel_res["debugger"] = debugger;
|
||||
+ kernel_res["help_links"] = help_links;
|
||||
+ return kernel_res;
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
+
|
||||
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||
index b24a3e5..176ef2a 100644
|
||||
--- a/test/CMakeLists.txt
|
||||
+++ b/test/CMakeLists.txt
|
||||
@@ -84,7 +84,7 @@ endif ()
|
||||
foreach(filename IN LISTS XEUS_TESTS)
|
||||
get_filename_component(targetname ${filename} NAME_WE)
|
||||
|
||||
- add_executable(${targetname} test_main.cpp ${filename})
|
||||
+ add_executable(${targetname} test_main.cpp ${filename} test_interpreter.cpp)
|
||||
target_link_libraries(${targetname} PRIVATE ${xeus_TARGET} doctest::doctest Threads::Threads ${nlohmann_json_TARGET})
|
||||
add_test(NAME ${targetname} COMMAND ${targetname})
|
||||
endforeach()
|
||||
@@ -179,3 +179,4 @@ add_test(NAME test_kernel_shell
|
||||
set_tests_properties(test_kernel_shell
|
||||
PROPERTIES
|
||||
ENVIRONMENT "JUPYTER_PATH=${CMAKE_CURRENT_BINARY_DIR}")
|
||||
+
|
||||
diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp
|
||||
index dd7491e..f01aac9 100644
|
||||
--- a/test/test_interpreter.cpp
|
||||
+++ b/test/test_interpreter.cpp
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "test_interpreter.hpp"
|
||||
+
|
||||
+#include "xeus/xhelper.hpp"
|
||||
#include "xeus/xguid.hpp"
|
||||
|
||||
namespace nl = nlohmann;
|
||||
@@ -34,8 +36,6 @@ namespace test_kernel
|
||||
nl::json /* user_expressions */,
|
||||
bool /* allow_stdin */)
|
||||
{
|
||||
- nl::json kernel_res;
|
||||
-
|
||||
if (code.compare("hello, world") == 0)
|
||||
{
|
||||
publish_stream("stdout", code);
|
||||
@@ -49,62 +49,44 @@ namespace test_kernel
|
||||
if (code.compare("?") == 0)
|
||||
{
|
||||
std::string html_content = R"(<iframe class="xpyt-iframe-pager" src="
|
||||
- https://xeus.readthedocs.io"></iframe>)";
|
||||
-
|
||||
- kernel_res["status"] = "ok";
|
||||
- kernel_res["payload"] = nl::json::array();
|
||||
- kernel_res["payload"][0] = nl::json::object({
|
||||
- {"data", {
|
||||
- {"text/plain", "https://xeus.readthedocs.io"},
|
||||
- {"text/html", html_content}}
|
||||
- },
|
||||
- {"source", "page"},
|
||||
- {"start", 0}
|
||||
- });
|
||||
- kernel_res["user_expressions"] = nl::json::object();
|
||||
-
|
||||
- return kernel_res;
|
||||
+ https://xeus.readthedocs.io"></iframe>)";
|
||||
+
|
||||
+ auto payload = nl::json::array();
|
||||
+ payload[0] = nl::json::object({
|
||||
+ {"data", {
|
||||
+ {"text/plain", "https://xeus.readthedocs.io"},
|
||||
+ {"text/html", html_content}}
|
||||
+ },
|
||||
+ {"source", "page"},
|
||||
+ {"start", 0}
|
||||
+ });
|
||||
+
|
||||
+ return xeus::create_successful_reply(payload);
|
||||
}
|
||||
|
||||
nl::json pub_data;
|
||||
pub_data["text/plain"] = code;
|
||||
- publish_execution_result(execution_counter, std::move(pub_data), nl::json());
|
||||
+ publish_execution_result(execution_counter, std::move(pub_data), nl::json::object());
|
||||
|
||||
- kernel_res["status"] = "ok";
|
||||
- kernel_res["payload"] = nl::json::array();
|
||||
- kernel_res["user_expressions"] = nl::json::object();
|
||||
-
|
||||
- return kernel_res;
|
||||
+ return xeus::create_successful_reply();
|
||||
}
|
||||
|
||||
nl::json test_interpreter::complete_request_impl(const std::string& /* code */,
|
||||
int /* cursor_pos */)
|
||||
{
|
||||
- nl::json result;
|
||||
- result["status"] = "ok";
|
||||
- result["matches"] = {"a.test1", "a.test2"};
|
||||
- result["cursor_start"] = 2;
|
||||
- result["cursor_end"] = 6;
|
||||
-
|
||||
- return result;
|
||||
+ return xeus::create_complete_reply({"a.test1", "a.test2"}, 2, 6);
|
||||
}
|
||||
|
||||
nl::json test_interpreter::inspect_request_impl(const std::string& /* code */,
|
||||
int /* cursor_pos */,
|
||||
int /* detail_level */)
|
||||
{
|
||||
- nl::json result;
|
||||
- result["status"] = "ok";
|
||||
- result["found"] = true;
|
||||
- result["data"] = {{"text/plain", ""}};
|
||||
- result["metadata"] = {{"text/plain", ""}};
|
||||
- return result;
|
||||
+ return xeus::create_inspect_reply(true, {{"text/plain", ""}}, {{"text/plain", ""}});
|
||||
}
|
||||
|
||||
nl::json test_interpreter::is_complete_request_impl(const std::string& code)
|
||||
{
|
||||
- nl::json result;
|
||||
- result["status"] = code;
|
||||
+ nl::json result = xeus::create_is_complete_reply(code);
|
||||
if (code.compare("incomplete") == 0)
|
||||
{
|
||||
result["indent"] = " ";
|
||||
@@ -114,15 +96,17 @@ namespace test_kernel
|
||||
|
||||
nl::json test_interpreter::kernel_info_request_impl()
|
||||
{
|
||||
- nl::json result;
|
||||
- result["implementation"] = "cpp_test";
|
||||
- result["implementation_version"] = "1.0.0";
|
||||
- result["banner"] = "test_kernel";
|
||||
- result["language_info"]["name"] = "cpp";
|
||||
- result["language_info"]["version"] = "14.0.0";
|
||||
- result["language_info"]["mimetype"] = "text/x-c++src";
|
||||
- result["language_info"]["file_extension"] = ".cpp";
|
||||
- return result;
|
||||
+ return xeus::create_info_reply("",
|
||||
+ "cpp_test",
|
||||
+ "1.0.0",
|
||||
+ "cpp",
|
||||
+ "14.0.0",
|
||||
+ "text/x-c++src",
|
||||
+ ".cpp",
|
||||
+ "",
|
||||
+ "",
|
||||
+ "",
|
||||
+ "test_kernel");
|
||||
}
|
||||
|
||||
void test_interpreter::shutdown_request_impl()
|
||||
diff --git a/test/test_unit_kernel.cpp b/test/test_unit_kernel.cpp
|
||||
index ee8709b..789bbc9 100644
|
||||
--- a/test/test_unit_kernel.cpp
|
||||
+++ b/test/test_unit_kernel.cpp
|
||||
@@ -9,63 +9,110 @@
|
||||
#include "doctest/doctest.h"
|
||||
|
||||
#include <string>
|
||||
-#include <iostream>
|
||||
+#include <memory>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
+#include "test_interpreter.hpp"
|
||||
+
|
||||
#include "xeus/xkernel.hpp"
|
||||
#include "xeus/xmiddleware.hpp"
|
||||
#include "xeus/xsystem.hpp"
|
||||
+#include "xeus/xeus_context.hpp"
|
||||
+#include "xeus/xhelper.hpp"
|
||||
+#include "xeus/xkernel_configuration.hpp"
|
||||
+#include "xeus/xserver_zmq.hpp"
|
||||
|
||||
namespace nl = nlohmann;
|
||||
|
||||
namespace xeus
|
||||
{
|
||||
- TEST_SUITE("kernel") {
|
||||
-
|
||||
- TEST_CASE("get_username")
|
||||
+ TEST_SUITE("kernel")
|
||||
{
|
||||
- std::string username;
|
||||
- username = get_user_name();
|
||||
- REQUIRE_NE(username, "unspecified user");
|
||||
- }
|
||||
+ TEST_CASE("print_starting_message")
|
||||
+ {
|
||||
+ auto context = make_context<zmq::context_t>();
|
||||
|
||||
- TEST_CASE("find_free_port")
|
||||
- {
|
||||
- std::string port = find_free_port();
|
||||
- REQUIRE_NE(port, "");
|
||||
- REQUIRE_EQ(port.length(), std::size_t(5));
|
||||
- }
|
||||
+ using interpreter_ptr = std::unique_ptr<test_kernel::test_interpreter>;
|
||||
+ interpreter_ptr interpreter = interpreter_ptr(new test_kernel::test_interpreter());
|
||||
+ xkernel kernel(get_user_name(),
|
||||
+ std::move(context),
|
||||
+ std::move(interpreter),
|
||||
+ make_xserver_zmq);
|
||||
+ std::string kernel_config = print_starting_message(kernel.get_config());
|
||||
+ std::cout << kernel_config << std::endl;
|
||||
+ size_t pos = kernel_config.find("Starting kernel...\n"
|
||||
+ "\n"
|
||||
+ "If you want to connect to this kernel from an other client, just copy and paste the following content inside of a `kernel.json` file. And then run for example:\n"
|
||||
+ "\n"
|
||||
+ "# jupyter console --existing kernel.json\n"
|
||||
+ "\n"
|
||||
+ "kernel.json\n"
|
||||
+ "```\n"
|
||||
+ "{\n"
|
||||
+ " \"transport\": \"tcp\",\n");
|
||||
+ REQUIRE_NE(pos, std::string::npos);
|
||||
+ }
|
||||
|
||||
- TEST_CASE("temp_directory_path")
|
||||
- {
|
||||
- std::string path = get_temp_directory_path();
|
||||
- std::cout << "Temporary directory path: " << path << std::endl;
|
||||
- REQUIRE_NE(path, "");
|
||||
- REQUIRE_NE(path.back(), '/');
|
||||
- REQUIRE_NE(path.back(), '\\');
|
||||
- }
|
||||
+ TEST_CASE("extract_filename")
|
||||
+ {
|
||||
+ char* argv[2];
|
||||
+ argv[0] = (char*)"-f";
|
||||
+ argv[1] = (char*)"connection.json";
|
||||
+ std::string file_name = extract_filename(3, argv);
|
||||
+ REQUIRE_EQ(file_name, "connection.json");
|
||||
+ }
|
||||
|
||||
- TEST_CASE("create_directory")
|
||||
- {
|
||||
- std::string temp_path = get_temp_directory_path();
|
||||
- std::string path = temp_path + "/intermediate/logs";
|
||||
- bool res = create_directory(path);
|
||||
- REQUIRE_UNARY(res);
|
||||
- }
|
||||
+ TEST_CASE("should_print_version")
|
||||
+ {
|
||||
+ char* argv[2];
|
||||
+ argv[0] = (char*)"--version";
|
||||
+ REQUIRE_EQ(should_print_version(1, argv), true);
|
||||
+ }
|
||||
|
||||
- TEST_CASE("get_current_pid")
|
||||
- {
|
||||
- int pid = get_current_pid();
|
||||
- REQUIRE_NE(pid, -1);
|
||||
- }
|
||||
+ TEST_CASE("get_username")
|
||||
+ {
|
||||
+ std::string username;
|
||||
+ username = get_user_name();
|
||||
+ REQUIRE_NE(username, "unspecified user");
|
||||
+ }
|
||||
|
||||
- TEST_CASE("get_tmp_hash_seed")
|
||||
- {
|
||||
- size_t hs = get_tmp_hash_seed();
|
||||
- size_t expected = static_cast<std::size_t>(0xc70f6907UL);
|
||||
- REQUIRE_EQ(hs, expected);
|
||||
- }
|
||||
+ TEST_CASE("find_free_port")
|
||||
+ {
|
||||
+ std::string port = find_free_port();
|
||||
+ REQUIRE_NE(port, "");
|
||||
+ REQUIRE_EQ(port.length(), std::size_t(5));
|
||||
+ }
|
||||
+
|
||||
+ TEST_CASE("temp_directory_path")
|
||||
+ {
|
||||
+ std::string path = get_temp_directory_path();
|
||||
+ std::cout << "Temporary directory path: " << path << std::endl;
|
||||
+ REQUIRE_NE(path, "");
|
||||
+ REQUIRE_NE(path.back(), '/');
|
||||
+ REQUIRE_NE(path.back(), '\\');
|
||||
+ }
|
||||
+
|
||||
+ TEST_CASE("create_directory")
|
||||
+ {
|
||||
+ std::string temp_path = get_temp_directory_path();
|
||||
+ std::string path = temp_path + "/intermediate/logs";
|
||||
+ bool res = create_directory(path);
|
||||
+ REQUIRE_EQ(res, true);
|
||||
+ }
|
||||
+
|
||||
+ TEST_CASE("get_current_pid")
|
||||
+ {
|
||||
+ int pid = get_current_pid();
|
||||
+ REQUIRE_NE(pid, -1);
|
||||
+ }
|
||||
+
|
||||
+ TEST_CASE("get_tmp_hash_seed")
|
||||
+ {
|
||||
+ size_t hs = get_tmp_hash_seed();
|
||||
+ size_t expected = static_cast<std::size_t>(0xc70f6907UL);
|
||||
+ REQUIRE_EQ(hs, expected);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.36.1
|
||||
|
||||
3
README.packit
Normal file
3
README.packit
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
This repository is maintained by packit.
|
||||
https://packit.dev/
|
||||
The file was generated using packit 1.12.0.post1.dev18+gc39b0e7d4.
|
||||
2
sources
2
sources
|
|
@ -1 +1 @@
|
|||
SHA512 (xeus-2.0.0.tar.gz) = a1897dda5416e202351a1afce7e2ebb4427ed06feb9edd8bb526df293999a021726b6214068a92203adbc533439f39a710279bfa4e4e485f168e79e9fca27b3a
|
||||
SHA512 (xeus-5.2.6.tar.gz) = f931ed1ba0122ee3855f4ce6bb3e30506a3fd56011c9594679baad7382372aa39e2088d1e84c6c730334e27c94080fc3b381073e987afd68186d64626abb32f6
|
||||
|
|
|
|||
27
xeus.spec
27
xeus.spec
|
|
@ -1,34 +1,23 @@
|
|||
Name: xeus
|
||||
Version: 2.0.0
|
||||
Version: 5.2.6
|
||||
Release: %autorelease
|
||||
Summary: C++ implementation of the Jupyter kernel protocol
|
||||
|
||||
License: BSD
|
||||
License: BSD-3-Clause
|
||||
URL: https://github.com/jupyter-xeus/xeus
|
||||
Source0: https://github.com/jupyter-xeus/xeus/archive/%{version}/%{name}-%{version}.tar.gz
|
||||
# Backport to make further backports easier
|
||||
# https://github.com/jupyter-xeus/xeus/pull/292
|
||||
Patch: 0001-switched-from-gtest-to-doctest-292.patch
|
||||
# https://github.com/jupyter-xeus/xeus/pull/298
|
||||
Patch: 0002-Never-delete-context-before-sockets.patch
|
||||
# Backport a refactor that only adds API, but leave out the documentation
|
||||
# changes, plus a few later bug fixes.
|
||||
# https://github.com/jupyter-xeus/xeus/pull/285
|
||||
# https://github.com/jupyter-xeus/xeus/pull/314
|
||||
# https://github.com/jupyter-xeus/xeus/pull/315
|
||||
Patch: 0003-Fix-non-standard-messages.patch
|
||||
|
||||
# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
|
||||
ExcludeArch: %{ix86}
|
||||
|
||||
BuildRequires: cmake >= 3.8
|
||||
BuildRequires: cmake(cppzmq) >= 4.3.0
|
||||
BuildRequires: cmake(nlohmann_json) >= 3.2.0
|
||||
BuildRequires: cmake(xtl) >= 0.7
|
||||
BuildRequires: cmake(nlohmann_json) >= 3.11.0
|
||||
BuildRequires: doctest-devel
|
||||
BuildRequires: doxygen
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: libuuid-devel
|
||||
BuildRequires: make
|
||||
BuildRequires: openssl-devel >= 1.0.1
|
||||
BuildRequires: pkgconfig(libzmq) >= 4.2.5
|
||||
BuildRequires: pkgconfig(uuid)
|
||||
BuildRequires: python3dist(breathe)
|
||||
BuildRequires: python3dist(jupyter-kernel-test)
|
||||
BuildRequires: python3dist(pytest)
|
||||
|
|
@ -72,7 +61,7 @@ rm docs/build/html/.buildinfo
|
|||
%files
|
||||
%doc README.md docs/build/html
|
||||
%license LICENSE
|
||||
%{_libdir}/libxeus.so.5*
|
||||
%{_libdir}/libxeus.so.13{,.*}
|
||||
|
||||
%files devel
|
||||
%{_includedir}/xeus/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue