def testWhyNotUpdates(self):
        issue = 31337
        fake1_change = 1
        fake1 = fake.DeferredFakeVerifier(base.SUCCEEDED, fake1_change)
        fake1.name = 'fake1'

        fake2_change = 3
        fake2 = fake.DeferredFakeVerifier(base.SUCCEEDED, fake2_change)
        fake2.name = 'fake2'
        pc = self._get_pc([fake1, fake2], [])
        pc.look_for_new_pending_commit()
        pc.process_new_pending_commit()

        self.context.status.check_names(['initial', 'why not'])

        # Make sure the 'why not' is only pushed when it changes.
        for i in range(fake2_change * 2):
            expected = ['why not'
                        ] if fake1_change == i or fake2_change == i else []
            pc.update_status()
            self.context.status.check_names(expected)

        pc.scan_results()

        self.context.rietveld.check_calls([
            _try_comment(),
            'close_issue(%d)' % issue,
            "update_description(%d, u'foo')" % issue,
            "add_comment(%d, 'Change committed as 125')" % issue
        ])
        self.context.status.check_names(['why not', 'commit'])
        self.context.checkout.check_calls(self._prepare_apply_commit(0, issue))
 def _check_defer_4(self, f1, f2, f3, f4):
     issue = 31337
     fake1 = fake.DeferredFakeVerifier(f1, 0)
     fake1.name = 'fake1'
     fake2 = fake.DeferredFakeVerifier(f2, 0)
     fake2.name = 'fake2'
     fake3 = fake.DeferredFakeVerifier(f3, 0)
     fake3.name = 'fake3'
     fake4 = fake.DeferredFakeVerifier(f4, 0)
     fake4.name = 'fake4'
     pc = self._get_pc([fake1, fake2], [fake3, fake4])
     self.assertEqual(len(pc.queue.iterate()), 0)
     pc.look_for_new_pending_commit()
     self.assertEqual(len(pc.queue.iterate()), 1)
     commit = pc.queue.get(issue)
     self.assertEqual(len(commit.verifications), 0)
     pc.process_new_pending_commit()
     commit = pc.queue.get(issue)
     self.assertEqual(commit.verifications['fake1'].get_state(),
                      base.PROCESSING)
     self.assertEqual(commit.verifications['fake2'].get_state(),
                      base.PROCESSING)
     self.assertEqual(commit.verifications['fake3'].get_state(),
                      base.PROCESSING)
     self.assertEqual(commit.verifications['fake4'].get_state(),
                      base.PROCESSING)
     self.assertEqual(len(commit.verifications), 4)
     pc.update_status()
     self.assertEqual(commit.verifications['fake1'].get_state(), f1)
     self.assertEqual(commit.verifications['fake2'].get_state(), f2)
     self.assertEqual(commit.verifications['fake3'].get_state(), f3)
     self.assertEqual(commit.verifications['fake4'].get_state(), f4)
     self.assertEqual('', commit.relpath)
     self._check_standard_verification(
         pc, all(x == base.SUCCEEDED for x in (f1, f2, f3, f4)), False)
     if all(x == base.SUCCEEDED for x in (f1, f2, f3, f4)):
         self.context.status.check_names(
             ['initial', 'why not', 'why not', 'why not', 'commit'])
     else:
         self.context.status.check_names(
             ['initial', 'why not', 'why not', 'abort'])
 def testDeferPatchVerificationFail(self):
     pc = self._get_pc([], [fake.DeferredFakeVerifier(base.FAILED, 0)])
     self._check_defer_1(pc, base.FAILED)
 def testDeferNoPatchVerification(self):
     pc = self._get_pc([fake.DeferredFakeVerifier(base.SUCCEEDED, 0)], [])
     self._check_defer_1(pc, base.SUCCEEDED)