Exemplo n.º 1
0
    def test_closing(self):
        closable = self.Closable()
        with closing(closable) as c:
            self.assertFalse(c.closed)
        self.assertTrue(closable.closed)

    def test_closing_after_error(self):
        closable = self.Closable()
        exc = Exception()
        try:
            with closing(closable) as c:
                raise exc
        except Exception as e:
            self.assertEqual(exc, e)
        self.assertTrue(closable.closed)


class SuppressTestCase(TestCase):

    def test_suppress(self):
        with suppress(ValueError, TypeError):
            raise ValueError()
            raise TypeError()
        self.assertTrue(True)


if __name__ == '__main__':
    run_class(ContextManagerTestCase)
    run_class(ClosingTestCase)
    run_class(SuppressTestCase)
Exemplo n.º 2
0
def run_unittest(*classes):
    for c in classes:
        unittest.run_class(c)
Exemplo n.º 3
0
        except Exception as e:
            self.assertEqual(type(e), queues.QueueFull)
        self.assertEqual(q.get_nowait(), 12)
        try:
            q.get_nowait()
            self.assertTrue(False)
        except Exception as e:
            self.assertEqual(type(e), queues.QueueEmpty)

    def test_qsize(self):
        q = queues.Queue()
        for n in range(10):
            q.put_nowait(10)
        self.assertEqual(q.qsize(), 10)

    def test_empty(self):
        q = queues.Queue()
        self.assertTrue(q.empty())
        q.put_nowait(10)
        self.assertFalse(q.empty())

    def test_full(self):
        q = queues.Queue(maxsize=1)
        self.assertFalse(q.full())
        q.put_nowait(10)
        self.assertTrue(q.full())


if __name__ == '__main__':
    run_class(QueueTestCase)
Exemplo n.º 4
0
        except Exception as e:
            self.assertEqual(type(e), queues.QueueFull)
        self.assertEqual(q.get_nowait(), 12)
        try:
            q.get_nowait()
            self.assertTrue(False)
        except Exception as e:
            self.assertEqual(type(e), queues.QueueEmpty)

    def test_qsize(self):
        q = queues.Queue()
        for n in range(10):
            q.put_nowait(10)
        self.assertEqual(q.qsize(), 10)

    def test_empty(self):
        q = queues.Queue()
        self.assertTrue(q.empty())
        q.put_nowait(10)
        self.assertFalse(q.empty())

    def test_full(self):
        q = queues.Queue(maxsize=1)
        self.assertFalse(q.full())
        q.put_nowait(10)
        self.assertTrue(q.full())


if __name__ == "__main__":
    run_class(QueueTestCase)