def testTimeout(self): t0 = time.time() c = channels.Channel("test", timeout=0) self.assertTrue(time.time() - t0 < 0.02) t0 = time.time() c = channels.Channel("test", timeout=2) self.assertTrue(time.time() - t0 >= 2) self.assertEquals(c.value, channels.NotInitialized())
def testExtChannel(self): p1 = test_ext_channel(2, "test", "hello") time.sleep(1) # wait for process to be started c = channels.Channel("test") p1_output = p1.stderr.readline().split('\n')[0] self.assertEquals(c.value, p1_output, 'hello') c.value = 5 p1_output = p1.stderr.readline().split('\n')[0] self.assertEquals(p1_output, '5') p1.wait()
import os import time from beacon import channels import sys import gevent args = [arg for arg in sys.argv[2:] if not '=' in arg] kwargs = dict([kwarg.split("=") for kwarg in sys.argv[2:] if '=' in kwarg]) for kw in kwargs.keys(): value = kwargs[kw] try: value = float(value) except: try: value = int(value) except: try: value = bool(value) except: pass kwargs[kw] = value c = channels.Channel(*args, **kwargs) sys.stderr.write("%s\n" % c.value) gevent.sleep(int(sys.argv[1])) sys.stderr.write("%s\n" % c.value)
def testSetChannel(self): c = channels.Channel("test", "test") self.assertEquals(c.value, 'test')
def testNotInitialized(self): c = channels.Channel("test") self.assertEquals(c.value, channels.NotInitialized())