def test_result_as_kwargs(self): def pop(candidate): print 'select from ' print candidate my_choice = int(raw_input()) print 'great! you selected: %d' % my_choice candidate.discard(my_choice) return candidate choices = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} anor = Anor() current_name = '' last_name = '' for i in range(5): last_name = current_name current_name = 'pop_at_%d' % i anor.next_job(current_name, pop, kwargs={ 'candidate': choices if i == 0 else anor.result_of(last_name) }) print anor.fire()
def test_raise_exception(self): def exception(): raise _TestError('my exception') anor = Anor() try: anor.next_job('raise', exception).fire() except Exception as e: print repr(e)
def test_yet_another_fire(self): def count_down(previous): now = previous - 1 print '[count_down] %d...' % now if now != 0 else 'cyka blyat!!!!!!!!!!!!!!!!!' return now anor = Anor(name='count_down') for i in range(10, 0, -1): name = 'count_down_at_%d' % i anor.next_job(name, count_down, args=(i, )) result = anor.fire() print result self.assertEqual(0, result)
def test_fire(self): anor = Anor(name='math') result = anor.next_job('double', double, args=(1,)). \ next_job('triple', triple, args=(2,)). \ next_job('multiple', multiple, args=(anor.result_of('double'), anor.result_of('triple'))).fire() print result self.assertEqual(1 * 2 * 2 * 3, result)
def test_choice_from_result(self): def init_list(): return ['apple', 'banana', 'grape', 'orange'] anor = Anor(name='choice') result = anor.next_job('init', init_list). \ next_job_choice_from('choice', candidate=anor.result_of('init')). \ fire() print result
def test_prepare_args(self): anor = Anor(name='decide') result = anor.next_job('double', double, args=(1,)). \ next_job('triple', triple, args=(2,)). \ next_job('glue', lambda x, y: {'a': x, 'b': y}, args=[anor.result_of('double'), anor.result_of('triple')]). \ next_job('multiple', multiple, kwargs=anor.result_of('glue')).fire() print result self.assertEqual(1 * 2 * 2 * 3, result)