Browse Source

add test for terminal bindings

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
0be5d31d13
  1. 26
      src/CMakeLists.txt
  2. 9
      tests/CMakeLists.txt
  3. 76
      tests/python_interpreter_test.cc
  4. 1
      tests/python_interpreter_test_files/basic_test.py
  5. 1
      tests/python_interpreter_test_files/exception_test.py
  6. 0
      tests/python_interpreter_test_files/ls/hello_world.txt
  7. 15
      tests/python_interpreter_test_files/terminal_test.py

26
src/CMakeLists.txt

@ -12,6 +12,7 @@ set(JUCI_SHARED_FILES
menu.cpp menu.cpp
meson.cpp meson.cpp
project_build.cpp project_build.cpp
python_interpreter.cc
snippets.cpp snippets.cpp
source.cpp source.cpp
source_base.cpp source_base.cpp
@ -42,19 +43,18 @@ target_link_libraries(juci_shared
) )
set(JUCI_SOURCES set(JUCI_SOURCES
config.cc config.cpp
dialogs.cc dialogs.cpp
dialogs_unix.cc dialogs_unix.cpp
directories.cc directories.cpp
entrybox.cc entrybox.cpp
info.cc info.cpp
juci.cc juci.cpp
notebook.cc notebook.cpp
project.cc project.cpp
selection_dialog.cc selection_dialog.cpp
tooltips.cc tooltips.cpp
window.cc window.cpp
python_interpreter.cc
) )
if(APPLE) if(APPLE)

9
tests/CMakeLists.txt

@ -121,3 +121,12 @@ if(BUILD_FUZZING)
target_link_options(markdown_fuzzer PRIVATE -fsanitize=address,fuzzer) target_link_options(markdown_fuzzer PRIVATE -fsanitize=address,fuzzer)
target_link_libraries(markdown_fuzzer juci_shared) target_link_libraries(markdown_fuzzer juci_shared)
endif() endif()
add_executable(git_test git_test.cc $<TARGET_OBJECTS:test_stubs>)
target_link_libraries(git_test juci_shared)
add_test(git_test git_test)
add_executable(python_interpreter_test python_interpreter_test.cc $<TARGET_OBJECTS:test_stubs>)
target_link_libraries(python_interpreter_test juci_shared ${PYTHON_LIBRARIES})
add_test(python_interpreter_test python_interpreter_test)

76
tests/python_interpreter_test.cc

@ -0,0 +1,76 @@
#include "config.h"
#include "plugins.h"
#include "python_interpreter.h"
#include "python_module.h"
#include "terminal.h"
class __attribute__((visibility("default")))
suite {
public:
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create();
py::detail::embedded_module jucipp = py::detail::embedded_module("Jucipp", Module::init_jucipp_module);
Python::Interpreter interpreter;
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 = 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;
}

1
tests/python_interpreter_test_files/basic_test.py

@ -0,0 +1 @@
import Jucipp

1
tests/python_interpreter_test_files/exception_test.py

@ -0,0 +1 @@
invalid code

0
tests/python_interpreter_test_files/ls/hello_world.txt

15
tests/python_interpreter_test_files/terminal_test.py

@ -0,0 +1,15 @@
from Jucipp import Terminal
t = Terminal();
def hello_world():
t.print("Hello, World!\n")
def clear():
t.clear()
def process(path):
return t.process("ls", path, True)
def async_print():
return t.async_print("Hello, World!")
Loading…
Cancel
Save