def test_2(self): '''With evaluation''' q = WishboneQueue(max_size=1000001) for _ in xrange(1000000): q.put(1)
def test_putUnlock(self): queue = WishboneQueue() queue.putLock() try: queue.put("test") except QueueLocked: pass else: raise AssertionError ("Queue putUnlock() does not seem to have the desired effect.")
def test_init_max_size(self): queue = WishboneQueue(max_size=1) queue.put("test") try: queue.put("test") except QueueFull: pass else: raise AssertionError("Queue max_size does not appear to be working.")
def test_putLock(self): queue = WishboneQueue() queue.putLock() try: queue.put("test") except QueueLocked: pass else: raise AssertionError("Queue putLock() not having desired effect.")
def test_getUnlock(self): queue = WishboneQueue() queue.put("test") queue.getLock() try: queue.get() except QueueLocked: queue.getUnlock() assert queue.get() == "test" else: raise AssertionError ("Queue getLock() does not seem to have the desired effect.")
def test_waitUntilFreePlace(self): from gevent import spawn, sleep def go(queue): queue.waitUntilFreePlace() queue = WishboneQueue(max_size=1) queue.put("test") instance=spawn(go, queue) sleep() assert not instance.ready() queue.get() sleep() assert instance.ready()
def test_waitUntilData(self): from gevent import spawn, sleep def go(queue): queue.waitUntilData() queue = WishboneQueue() queue.put("blah") instance=spawn(go, queue) sleep() assert instance.ready() queue = WishboneQueue() instance=spawn(go, queue) sleep() assert not instance.ready()
def test_waitUntilPutAllowed(self): from gevent import spawn, sleep def go(queue): queue.waitUntilPutAllowed() queue.put("test") queue = WishboneQueue() queue.putLock() instance=spawn(go, queue) sleep() assert not instance.ready() queue.putUnlock() sleep() assert instance.ready()
def test_lock(self): queue = WishboneQueue() queue.put("test") queue.lock() try: queue.put("test") except QueueLocked: pass else: raise AssertionError("Queue lock() not having desired effect.") try: queue.get() except QueueLocked: pass else: raise AssertionError("Queue lock not having desired effect.") assert queue.isLocked() == (True, True)
def test_stats(self): queue = WishboneQueue() for _ in xrange(10): queue.put("test") for _ in xrange(9): queue.get() stats = queue.stats() assert isinstance(stats, dict) assert stats["in_total"] == 10 assert stats["out_total"] == 9 assert stats["size"] == 1
def test_clear(self): queue = WishboneQueue() queue.put("test") assert queue.size() == 1
def test_1(self): '''No evaluation''' q = WishboneQueue() for _ in xrange(1000000): q.put(1)
def test_rescue(self): queue = WishboneQueue() queue.lock() queue.rescue("test") queue.unlock() assert queue.get() == "test"
def test_isLocked(self): queue = WishboneQueue() queue.getLock() assert queue.isLocked() == (True, False)
def test_size(self): queue = WishboneQueue() queue.lock() queue.rescue("test") assert queue.size() == 1
def test_get(self): queue = WishboneQueue() queue.put("test") assert queue.get() == "test"
def test_empty(self): queue = WishboneQueue() queue.put("test") queue.clear() assert queue.size() == 0
class QLogging(): ''' Generates Wishbone formatted log messages following the Syslog priority definition. Generated logs are stored in a local queue <self.logs>. It is up to an external process the consume this queue. ''' def __init__(self, name): self.logs=WishboneQueue() self.name=name self.pid=getpid() def __log(self, level, message): self.logs.put({"header":{},"data":(level, time(), self.pid, self.name, message)}) def emergency(self, message): """Generates a log message with priority emergency(0). """ self.__log(0, message) emerg=emergency def alert(self, message): """Generates a log message with priority alert(1). """ self.__log(1, message) def critical(self, message): """Generates a log message with priority critical(2). """ self.__log(2, message) crit=critical def error(self, message): """Generates a log message with priority error(3). """ self.__log(3, message) err=error def warning(self, message): """Generates a log message with priority warning(4). """ self.__log(4, message) warn=warning def notice(self, message): """Generates a log message with priority notice(5). """ self.__log(5, message) def informational(self, message): """Generates a log message with priority informational(6). """ self.__log(6, message) info=informational def debug(self, message): """Generates a log message with priority debug(7). """ self.__log(7, message)
def __init__(self, name): self.logs=WishboneQueue() self.name=name self.pid=getpid()
def test_dump(self): queue = WishboneQueue() queue.put("test") queue.put("test") assert len([x for x in queue.dump()]) == 2