Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def test_choice_from_array(self):
        choices = [5, 4, 3, 2, 1]
        anor = Anor()

        anor.next_job_choice_from('make_choice',
                                  candidate=choices,
                                  prompt='Choice a number you like:')

        print anor.fire()
Ejemplo n.º 3
0
    def test_auto_choice(self):
        choices = [1, 2, 3, 4, 5]
        anor = Anor()

        anor.next_job_choice_from('make_choice', candidate=choices, auto=True)

        result = anor.fire()
        print result

        self.assertEqual(len(choices), len(result))
Ejemplo n.º 4
0
    def test_choice_with_filter(self):
        def fltr(n):
            return False if n in [1, 3, 5] else True

        choices = [1, 2, 3, 4, 5]
        anor = Anor()

        anor.next_job_choice_from('with_filter',
                                  candidate=choices,
                                  filter_func=fltr)

        result = anor.fire()
        print result
Ejemplo n.º 5
0
    def test_auto_choice_max(self):
        choices = [x for x in range(1, 400)]
        anor = Anor()

        max_cnt = random.randint(1, 400)
        anor.next_job_choice_from('make_choice',
                                  candidate=choices,
                                  auto=True,
                                  max_cnt=max_cnt)

        result = anor.fire()
        print result

        self.assertEqual(max_cnt, len(result))
Ejemplo n.º 6
0
    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)