From bc1de925340dbc9b6e3bea300889f3d038a4767a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Sep 2017 17:05:58 +0530 Subject: [PATCH] Fix the broken tests --- kitty/data-types.h | 2 +- kitty/screen.c | 8 ++++++-- kitty_tests/__init__.py | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 5a4fac85e..8661761a6 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -237,7 +237,7 @@ typedef struct { bool use_latin1, selection_updated_once, is_dirty, scroll_changed; Cursor *cursor; SavepointBuffer main_savepoints, alt_savepoints; - PyObject *callbacks; + PyObject *callbacks, *test_child; LineBuf *linebuf, *main_linebuf, *alt_linebuf; HistoryBuf *historybuf; unsigned int history_line_added_count; diff --git a/kitty/screen.c b/kitty/screen.c index aeea843d8..368a3c0d1 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -49,9 +49,9 @@ static PyObject* new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { Screen *self; int ret = 0; - PyObject *callbacks = Py_None; + PyObject *callbacks = Py_None, *test_child = Py_None; unsigned int columns=80, lines=24, scrollback=0, window_id=0; - if (!PyArg_ParseTuple(args, "|OIIII", &callbacks, &lines, &columns, &scrollback, &window_id)) return NULL; + if (!PyArg_ParseTuple(args, "|OIIIIO", &callbacks, &lines, &columns, &scrollback, &window_id, &test_child)) return NULL; self = (Screen *)type->tp_alloc(type, 0); if (self != NULL) { @@ -75,6 +75,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { self->history_line_added_count = 0; RESET_CHARSETS; self->callbacks = callbacks; Py_INCREF(callbacks); + self->test_child = test_child; Py_INCREF(test_child); self->cursor = alloc_cursor(); self->color_profile = alloc_color_profile(); self->main_linebuf = alloc_linebuf(lines, columns); self->alt_linebuf = alloc_linebuf(lines, columns); @@ -208,6 +209,7 @@ dealloc(Screen* self) { pthread_mutex_destroy(&self->write_buf_lock); PyMem_RawFree(self->write_buf); Py_CLEAR(self->callbacks); + Py_CLEAR(self->test_child); Py_CLEAR(self->cursor); Py_CLEAR(self->main_linebuf); Py_CLEAR(self->alt_linebuf); @@ -962,7 +964,9 @@ screen_bell(Screen UNUSED *self) { static inline void write_to_child(Screen *self, const char *data, size_t sz) { if (self->window_id) schedule_write_to_child(self->window_id, data, sz); + if (self->test_child != Py_None) { PyObject *r = PyObject_CallMethod(self->test_child, "write", "y#", data, sz); if (r == NULL) PyErr_Print(); Py_CLEAR(r); } } + #define write_str_to_child(s) write_to_child(self, (s), sizeof((s)) - 1) void diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index 7d46dff77..4ee48ee80 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -12,7 +12,7 @@ class Callbacks: def __init__(self): self.clear() - def write_to_child(self, data): + def write(self, data): self.wtcbuf += data def title_changed(self, data): @@ -70,7 +70,8 @@ class BaseTest(TestCase): ae = TestCase.assertEqual def create_screen(self, cols=5, lines=5, scrollback=5): - return Screen(Callbacks(), lines, cols, scrollback) + c = Callbacks() + return Screen(c, lines, cols, scrollback, 0, c) def assertEqualAttributes(self, c1, c2): x1, y1, c1.x, c1.y = c1.x, c1.y, 0, 0