##// END OF EJS Templates
move some general parallel test utilities to clienttest
MinRK -
Show More
@@ -15,6 +15,7 b' Authors:'
15 import sys
15 import sys
16 import tempfile
16 import tempfile
17 import time
17 import time
18 from StringIO import StringIO
18
19
19 from nose import SkipTest
20 from nose import SkipTest
20
21
@@ -59,6 +60,28 b' def raiser(eclass):'
59 """raise an exception"""
60 """raise an exception"""
60 raise eclass()
61 raise eclass()
61
62
63 def generate_output():
64 """function for testing output
65
66 publishes two outputs of each type, and returns
67 a rich displayable object.
68 """
69
70 import sys
71 from IPython.core.display import display, HTML, Math
72
73 print "stdout"
74 print >> sys.stderr, "stderr"
75
76 display(HTML("<b>HTML</b>"))
77
78 print "stdout2"
79 print >> sys.stderr, "stderr2"
80
81 display(Math(r"\alpha=\beta"))
82
83 return Math("42")
84
62 # test decorator for skipping tests when libraries are unavailable
85 # test decorator for skipping tests when libraries are unavailable
63 def skip_without(*names):
86 def skip_without(*names):
64 """skip a test if some names are not importable"""
87 """skip a test if some names are not importable"""
@@ -73,6 +96,41 b' def skip_without(*names):'
73 return f(*args, **kwargs)
96 return f(*args, **kwargs)
74 return skip_without_names
97 return skip_without_names
75
98
99 #-------------------------------------------------------------------------------
100 # Classes
101 #-------------------------------------------------------------------------------
102
103 class CapturedIO(object):
104 """Simple object for containing captured stdout/err StringIO objects"""
105
106 def __init__(self, stdout, stderr):
107 self.stdout_io = stdout
108 self.stderr_io = stderr
109
110 @property
111 def stdout(self):
112 return self.stdout_io.getvalue()
113
114 @property
115 def stderr(self):
116 return self.stderr_io.getvalue()
117
118
119 class capture_output(object):
120 """context manager for capturing stdout/err"""
121
122 def __enter__(self):
123 self.sys_stdout = sys.stdout
124 self.sys_stderr = sys.stderr
125 stdout = sys.stdout = StringIO()
126 stderr = sys.stderr = StringIO()
127 return CapturedIO(stdout, stderr)
128
129 def __exit__(self, exc_type, exc_value, traceback):
130 sys.stdout = self.sys_stdout
131 sys.stderr = self.sys_stderr
132
133
76 class ClusterTestCase(BaseZMQTestCase):
134 class ClusterTestCase(BaseZMQTestCase):
77
135
78 def add_engines(self, n=1, block=True):
136 def add_engines(self, n=1, block=True):
@@ -117,6 +175,17 b' class ClusterTestCase(BaseZMQTestCase):'
117 else:
175 else:
118 self.fail("should have raised a RemoteError")
176 self.fail("should have raised a RemoteError")
119
177
178 def _wait_for(self, f, timeout=10):
179 """wait for a condition"""
180 tic = time.time()
181 while time.time() <= tic + timeout:
182 if f():
183 return
184 time.sleep(0.1)
185 self.client.spin()
186 if not f():
187 print "Warning: Awaited condition never arrived"
188
120 def setUp(self):
189 def setUp(self):
121 BaseZMQTestCase.setUp(self)
190 BaseZMQTestCase.setUp(self)
122 self.client = self.connect_client()
191 self.client = self.connect_client()
@@ -590,16 +590,6 b' class TestView(ClusterTestCase, ParametricTestCase):'
590
590
591
591
592 # begin execute tests
592 # begin execute tests
593 def _wait_for(self, f, timeout=10):
594 tic = time.time()
595 while time.time() <= tic + timeout:
596 if f():
597 return
598 time.sleep(0.1)
599 self.client.spin()
600 if not f():
601 print "Warning: Awaited condition never arrived"
602
603
593
604 def test_execute_reply(self):
594 def test_execute_reply(self):
605 e0 = self.client[self.client.ids[0]]
595 e0 = self.client[self.client.ids[0]]
General Comments 0
You need to be logged in to leave comments. Login now