From 6fafc0a631cb3b225e591b3b34ce5eebe7fcbd3a Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 11 Dec 2018 23:16:16 +0000 Subject: [PATCH] select: Python 2.x required __nonzero__ for bool(Select) --- mitogen/select.py | 2 ++ tests/select_test.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/mitogen/select.py b/mitogen/select.py index 6d46c336..92945a9d 100644 --- a/mitogen/select.py +++ b/mitogen/select.py @@ -135,6 +135,8 @@ class Select(object): """ return bool(self._receivers) + __nonzero__ = __bool__ + def __enter__(self): return self diff --git a/tests/select_test.py b/tests/select_test.py index d9345954..7e6256c8 100644 --- a/tests/select_test.py +++ b/tests/select_test.py @@ -6,6 +6,22 @@ import mitogen.select import testlib +class BoolTest(testlib.RouterMixin, testlib.TestCase): + klass = mitogen.select.Select + + def test_receiver(self): + recv = mitogen.core.Receiver(self.router) # oneshot + select = self.klass() + self.assertFalse(select) + select.add(recv) + self.assertTrue(select) + + recv._on_receive(mitogen.core.Message.pickled('123')) + self.assertTrue(select) + self.assertEquals('123', select.get().unpickle()) + self.assertFalse(select) + + class AddTest(testlib.RouterMixin, testlib.TestCase): klass = mitogen.select.Select