mirror of https://gitlab.com/cppit/jucipp
17 changed files with 160 additions and 111 deletions
@ -0,0 +1,27 @@ |
|||||||
|
#include "python_module.h" |
||||||
|
#include "cmake.h" |
||||||
|
#include "compile_commands.h" |
||||||
|
#include "config.h" |
||||||
|
#include "ctags.h" |
||||||
|
#ifdef JUCI_ENABLE_DEBUG |
||||||
|
#include "debug_lldb.h" |
||||||
|
#endif |
||||||
|
#include "dialogs.h" |
||||||
|
#include "terminal.h" |
||||||
|
#include "git.h" |
||||||
|
|
||||||
|
PyObject *Module::init_jucipp_module() { |
||||||
|
auto api = py::module("Jucipp", "API"); |
||||||
|
CMake::init_module(api); |
||||||
|
CompileCommands::init_module(api); |
||||||
|
Config::init_module(api); |
||||||
|
Ctags::init_module(api); |
||||||
|
#ifdef JUCI_ENABLE_DEBUG |
||||||
|
Debug::LLDB::init_module(api); |
||||||
|
#endif |
||||||
|
Dialog::init_module(api); |
||||||
|
Dispatcher::init_module(api); |
||||||
|
Git::init_module(api); |
||||||
|
Terminal::init_module(api); |
||||||
|
return api.ptr(); |
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
#pragma once |
||||||
|
#include "python_bind.h" |
||||||
|
|
||||||
|
class Module { |
||||||
|
public: |
||||||
|
static PyObject *init_jucipp_module(); |
||||||
|
}; |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
|
||||||
|
add_library(test_suite test_suite.cc) |
||||||
|
target_link_libraries(test_suite juci_shared ${PYTHON_LIBRARIES}) |
||||||
|
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/tests/python_bindings) |
||||||
|
|
||||||
|
add_executable(pb_python_interpreter_test PythonInterpreter_tests/interpreter_test.cc) |
||||||
|
target_link_libraries(pb_python_interpreter_test juci_shared test_suite $<TARGET_OBJECTS:test_stubs>) |
||||||
|
add_test(pb_python_interpreter_test pb_python_interpreter_test) |
||||||
|
|
||||||
|
add_executable(pb_terminal_test Terminal_tests/terminal_test.cc) |
||||||
|
target_link_libraries(pb_terminal_test juci_shared test_suite $<TARGET_OBJECTS:test_stubs>) |
||||||
|
add_test(pb_terminal_test pb_terminal_test) |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
#include "python_type_casters.h" |
||||||
|
#include <test_suite.h> |
||||||
|
|
||||||
|
int main() { |
||||||
|
{ |
||||||
|
suite test_suite("PythonInterpreter_tests"); |
||||||
|
{ |
||||||
|
py::module::import("interpreter_test"); |
||||||
|
test_suite.has_assertion = true; |
||||||
|
} |
||||||
|
} |
||||||
|
{ |
||||||
|
suite test_suite("PythonInterpreter_tests"); |
||||||
|
{ |
||||||
|
try { |
||||||
|
py::module::import("exception_test"); |
||||||
|
} |
||||||
|
catch(const py::error_already_set &error) { |
||||||
|
test_suite.has_assertion = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
#include "test_suite.h" |
||||||
|
#include "terminal.h" |
||||||
|
|
||||||
|
int main() { |
||||||
|
const auto test_directory = "Terminal_tests"; |
||||||
|
{ |
||||||
|
suite test_suite(test_directory); |
||||||
|
{ |
||||||
|
auto &terminal = Terminal::get(); |
||||||
|
auto connection = terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { |
||||||
|
g_assert_cmpstr(msg.c_str(), ==, "Hello, World!\n"); |
||||||
|
test_suite.has_assertion = true; |
||||||
|
}); |
||||||
|
auto module = py::module::import("terminal_test"); |
||||||
|
module.attr("hello_world")(); |
||||||
|
connection.disconnect(); |
||||||
|
} |
||||||
|
} |
||||||
|
{ |
||||||
|
suite test_suite(test_directory); |
||||||
|
{ |
||||||
|
auto &terminal = Terminal::get(); |
||||||
|
auto connection = terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { |
||||||
|
g_assert_cmpstr(msg.c_str(), ==, "hello_world.txt\n"); |
||||||
|
test_suite.has_assertion = true; |
||||||
|
test_suite.app->release(); |
||||||
|
}); |
||||||
|
test_suite.app->hold(); |
||||||
|
std::thread thread([&] { |
||||||
|
const auto ls_dir = test_suite.test_file_path / test_directory / "ls"; |
||||||
|
auto module = py::module::import("terminal_test"); |
||||||
|
auto res = module.attr("process")(ls_dir).cast<int>(); |
||||||
|
g_assert_cmpint(res, ==, 0); |
||||||
|
}); |
||||||
|
test_suite.app->run(); |
||||||
|
thread.join(); |
||||||
|
connection.disconnect(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
#include "test_suite.h" |
||||||
|
#include "python_module.h" |
||||||
|
#include <iostream> |
||||||
|
|
||||||
|
suite::suite(const boost::filesystem::path &path) { |
||||||
|
auto sys = py::module::import("sys"); |
||||||
|
sys.attr("path").cast<py::list>().append((test_file_path / path).string()); |
||||||
|
config.terminal.history_size = 100; |
||||||
|
} |
||||||
|
suite::~suite() { |
||||||
|
g_assert_true(has_assertion); |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
#pragma once |
||||||
|
#include "config.h" |
||||||
|
#include "plugins.h" |
||||||
|
#include <gtkmm.h> |
||||||
|
|
||||||
|
class __attribute__((visibility("default"))) |
||||||
|
suite { |
||||||
|
public: |
||||||
|
suite(const boost::filesystem::path &path); |
||||||
|
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(); |
||||||
|
Config &config = Config::get(); |
||||||
|
boost::filesystem::path test_file_path = boost::filesystem::canonical(std::string(JUCI_TESTS_PATH) + "/python_bindings"); |
||||||
|
bool has_assertion = false; |
||||||
|
Plugins plugins; |
||||||
|
~suite(); |
||||||
|
}; |
||||||
@ -1,76 +0,0 @@ |
|||||||
#include "config.h" |
|
||||||
#include "plugins.h" |
|
||||||
#include "python_interpreter.h" |
|
||||||
#include "terminal.h" |
|
||||||
#include "config.h" |
|
||||||
#include "python_type_casters.h" |
|
||||||
|
|
||||||
|
|
||||||
class __attribute__((visibility("default"))) |
|
||||||
suite { |
|
||||||
public: |
|
||||||
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(); |
|
||||||
Plugins plugins; |
|
||||||
Terminal &terminal = Terminal::get(); |
|
||||||
Config &config = Config::get(); |
|
||||||
boost::filesystem::path test_file_path = boost::filesystem::canonical(std::string(JUCI_TESTS_PATH) + "/python_interpreter_test_files"); |
|
||||||
bool has_assertion = false; |
|
||||||
suite() { |
|
||||||
auto sys = plugins.interpreter.add_module("sys"); |
|
||||||
sys.attr("path").cast<py::list>().append(test_file_path.string()); |
|
||||||
config.terminal.history_size = 100; |
|
||||||
} |
|
||||||
~suite() { |
|
||||||
g_assert_true(has_assertion); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
int main() { |
|
||||||
{ |
|
||||||
suite test_suite; |
|
||||||
{ |
|
||||||
py::module::import("basic_test"); |
|
||||||
try { |
|
||||||
py::module::import("exception_test"); |
|
||||||
} |
|
||||||
catch(const py::error_already_set &error) { |
|
||||||
test_suite.has_assertion = true; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
{ |
|
||||||
suite test_suite; |
|
||||||
{ |
|
||||||
auto connection = test_suite.terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { |
|
||||||
g_assert_cmpstr(msg.c_str(), ==, "Hello, World!\n"); |
|
||||||
test_suite.has_assertion = true; |
|
||||||
}); |
|
||||||
auto module = py::module::import("terminal_test"); |
|
||||||
module.attr("hello_world")(); |
|
||||||
connection.disconnect(); |
|
||||||
} |
|
||||||
} |
|
||||||
{ |
|
||||||
suite test_suite; |
|
||||||
{ |
|
||||||
auto connection = test_suite.terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { |
|
||||||
g_assert_cmpstr(msg.c_str(), ==, "hello_world.txt\n"); |
|
||||||
test_suite.has_assertion = true; |
|
||||||
test_suite.app->release(); |
|
||||||
}); |
|
||||||
test_suite.app->hold(); |
|
||||||
std::thread thread([&] { |
|
||||||
const auto ls_dir = test_suite.test_file_path / "ls"; |
|
||||||
auto module = py::module::import("terminal_test"); |
|
||||||
auto res = module.attr("process")(ls_dir).cast<int>(); |
|
||||||
g_assert_cmpint(res, ==, 0); |
|
||||||
}); |
|
||||||
test_suite.app->run(); |
|
||||||
thread.join(); |
|
||||||
connection.disconnect(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return 0; |
|
||||||
} |
|
||||||
Loading…
Reference in new issue