mirror of
https://github.com/samba-team/samba.git
synced 2025-03-24 10:50:22 +03:00
pytevent: Add more tests.
This commit is contained in:
parent
ddb3c48f1a
commit
e68afdc02f
62
lib/tevent/bindings.py
Normal file
62
lib/tevent/bindings.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Python integration for tevent - tests
|
||||
#
|
||||
# Copyright (C) Jelmer Vernooij 2010
|
||||
#
|
||||
# ** NOTE! The following LGPL license applies to the tevent
|
||||
# ** library. This does NOT imply that all of Samba is released
|
||||
# ** under the LGPL
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 3 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import signal
|
||||
import _tevent
|
||||
from unittest import TestCase
|
||||
|
||||
class BackendListTests(TestCase):
|
||||
|
||||
def test_backend_list(self):
|
||||
self.assertTrue(isinstance(_tevent.backend_list(), list))
|
||||
|
||||
|
||||
class CreateContextTests(TestCase):
|
||||
|
||||
def test_by_name(self):
|
||||
ctx = _tevent.Context(_tevent.backend_list()[0])
|
||||
self.assertTrue(ctx is not None)
|
||||
|
||||
def test_no_name(self):
|
||||
ctx = _tevent.Context()
|
||||
self.assertTrue(ctx is not None)
|
||||
|
||||
|
||||
class ContextTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ContextTests, self).setUp()
|
||||
self.ctx = _tevent.Context()
|
||||
|
||||
def test_signal_support(self):
|
||||
self.assertTrue(type(self.ctx.signal_support) is bool)
|
||||
|
||||
def test_reinitialise(self):
|
||||
self.ctx.reinitialise()
|
||||
|
||||
def test_loop_wait(self):
|
||||
self.ctx.loop_wait()
|
||||
|
||||
def test_add_signal(self):
|
||||
sig = self.ctx.add_signal(signal.SIGINT, 0, lambda callback: None)
|
||||
self.assertTrue(isinstance(sig, _tevent.Signal))
|
@ -270,6 +270,7 @@ static PyObject *py_tevent_context_loop_once(TeventContext_Object *self)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
#ifdef TEVENT_DEPRECATED
|
||||
static bool py_tevent_finished(PyObject *callback)
|
||||
{
|
||||
PyObject *py_ret;
|
||||
@ -299,6 +300,7 @@ static PyObject *py_tevent_context_loop_until(TeventContext_Object *self, PyObje
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void py_tevent_signal_handler(struct tevent_context *ev,
|
||||
struct tevent_signal *se,
|
||||
@ -313,6 +315,19 @@ static void py_tevent_signal_handler(struct tevent_context *ev,
|
||||
Py_XDECREF(ret);
|
||||
}
|
||||
|
||||
static void py_tevent_signal_dealloc(TeventSignal_Object *self)
|
||||
{
|
||||
talloc_free(self->signal);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyTypeObject TeventSignal_Type = {
|
||||
.tp_name = "Signal",
|
||||
.tp_basicsize = sizeof(TeventSignal_Object),
|
||||
.tp_dealloc = (destructor)py_tevent_signal_dealloc,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
};
|
||||
|
||||
static PyObject *py_tevent_context_add_signal(TeventContext_Object *self, PyObject *args)
|
||||
{
|
||||
int signum, sa_flags;
|
||||
@ -361,7 +376,7 @@ static PyObject *py_tevent_context_add_timer(TeventContext_Object *self, PyObjec
|
||||
timer = tevent_add_timer(self->ev, NULL, next_event, py_timer_handler,
|
||||
handler);
|
||||
if (timer == NULL) {
|
||||
PyExc_SetNone(PyExc_RuntimeError);
|
||||
PyErr_SetNone(PyExc_RuntimeError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -430,8 +445,10 @@ static PyMethodDef py_tevent_context_methods[] = {
|
||||
METH_NOARGS, "S.loop_wait()" },
|
||||
{ "loop_once", (PyCFunction)py_tevent_context_loop_once,
|
||||
METH_NOARGS, "S.loop_once()" },
|
||||
#ifdef TEVENT_DEPRECATED
|
||||
{ "loop_until", (PyCFunction)py_tevent_context_loop_until,
|
||||
METH_VARARGS, "S.loop_until(callback)" },
|
||||
#endif
|
||||
{ "add_signal", (PyCFunction)py_tevent_context_add_signal,
|
||||
METH_VARARGS, "S.add_signal(signum, sa_flags, handler) -> signal" },
|
||||
{ "add_timer", (PyCFunction)py_tevent_context_add_timer,
|
||||
@ -597,7 +614,7 @@ static PyGetSetDef py_tevent_context_getsetters[] = {
|
||||
static void py_tevent_context_dealloc(TeventContext_Object *self)
|
||||
{
|
||||
talloc_free(self->ev);
|
||||
Py_Object_Del(self);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *py_tevent_context_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user