Skip to content

Commit

Permalink
Three basic ioloop tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusty Phillips committed Jan 25, 2010
1 parent 393f3bf commit 1abd2e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
@@ -0,0 +1,7 @@
from psyclone import ioloop

def pytest_funcarg__IOloop(request):
'''Funcarg to create a ioloop that is not the standard ioloop. This allows
test teardown more easily. It also allows testing of independent
IOLoops.'''
return ioloop.IOLoop()
36 changes: 36 additions & 0 deletions tests/test_ioloop.py
@@ -0,0 +1,36 @@
from psyclone import ioloop
import os
def test_class_instance():
'''Ensure two calls to ioloop.instance create only one object.'''
assert not hasattr(ioloop.IOLoop, '_instance')
assert ioloop.IOLoop.instance() == ioloop.IOLoop.instance()
assert hasattr(ioloop.IOLoop, '_instance')
assert ioloop.IOLoop.initialized()
del ioloop.IOLoop._instance

def test_ioloop_funcarg(IOloop):
'''Ensure the ioloop funcarg isn't from instance'''
assert isinstance(IOloop, ioloop.IOLoop)
assert not hasattr(ioloop.IOLoop, '_instance')

def test_run_loop(IOloop):
'''Test adding a file descriptor to the IOLoop and it receives events.'''
fdr, fdw = os.pipe()
reader = os.fdopen(fdr, "rb", 0)
writer = os.fdopen(fdw, "wb", 0)
IOloop._set_nonblocking(fdr)
IOloop._set_nonblocking(fdw)
read_values = []
def read_callback(fd, events):
assert fd == fdr
assert events & ioloop.IOLoop.READ
assert IOloop.running()
val = reader.read()
if val != None:
assert val == b"ho"
IOloop.stop()
def send_val():
writer.write("ho")
IOloop.add_handler(fdr, read_callback, IOloop.READ)
IOloop.add_callback(send_val)
IOloop.start()

0 comments on commit 1abd2e5

Please sign in to comment.