class TestLead(unittest.TestCase): def setUp(self): self.lead = Lead("test", db=TEST_DB) # fork the understudy self.p = Process(target=start_understudy, args=("test",)) self.p.start() def tearDown(self): self.p.terminate() def test_shell(self): # non-blocking while True: try: result = self.lead.shell('echo "test"') break except NoUnderstudiesError: pass self.assertTrue(isinstance(result, Result)) self.assertTrue(re.match(UUID, result.uuid)) actual_result = result.check() while not actual_result: actual_result = result.check() self.assertEquals("test\n", actual_result) # blocking result = self.lead.shell('echo "test"', block=True) self.assertEquals("test\n", result)
def dispatch(cls, *args, **kwargs): if '__understudy__' in kwargs: del(kwargs['__understudy__']) logger = kwargs['logger'] setattr(cls, 'logger', logger) del(kwargs['logger']) return func(cls, *args, **kwargs) channel = uargs[0] block = ukwargs.get('block', False) queue = ukwargs.get('queue', False) host = ukwargs.get('host', 'localhost') port = ukwargs.get('port', 6379) db = ukwargs.get('db', 0) password = ukwargs.get('password', None) packages = ukwargs.get('packages', []) sourcefile = inspect.getsourcefile(cls.__class__) f = open(sourcefile, 'rb'); source = f.read(); f.close() action = {'source':simplejson.dumps(source), 'cls':cls.__class__.__name__, 'func':func.__name__, 'args':args, 'kwargs':kwargs, 'packages':packages} lead = Lead(channel, queue=queue, host=host, port=port, db=db, password=password) result = lead.perform(action, block=block) return result
def setUp(self): self.lead = Lead("test", db=TEST_DB) # fork the understudy self.p = Process(target=start_understudy, args=("test",)) self.p.start()