/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_commit.py

  • Committer: John Arbash Meinel
  • Date: 2007-10-02 18:26:42 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002182642-qs9ohpjp8fdkkl2o
Handle pointless commits and trees with unknown files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
561
561
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
562
562
    """Tests on the actual 'commit' button being pushed."""
563
563
 
 
564
    def _set_question_yes(self, dlg):
 
565
        """Set the dialog to answer YES to any questions."""
 
566
        self.questions = []
 
567
        def _question_yes(*args):
 
568
            self.questions.append(args)
 
569
            self.questions.append('YES')
 
570
            return gtk.RESPONSE_YES
 
571
        dlg._question_dialog = _question_yes
 
572
 
 
573
    def _set_question_no(self, dlg):
 
574
        """Set the dialog to answer NO to any questions."""
 
575
        self.questions = []
 
576
        def _question_no(*args):
 
577
            self.questions.append(args)
 
578
            self.questions.append('NO')
 
579
            return gtk.RESPONSE_NO
 
580
        dlg._question_dialog = _question_no
 
581
 
564
582
    def test_bound_commit_local(self):
565
583
        tree = self.make_branch_and_tree('tree')
566
584
        self.build_tree(['tree/a'])
612
630
        tree.add(['b'], ['b-id'])
613
631
 
614
632
        dlg = commit.CommitDialog(tree)
615
 
        questions = []
616
 
        def _question_cancel(*args):
617
 
            questions.append(args)
618
 
            questions.append('NO')
619
 
            return gtk.RESPONSE_NO
620
 
 
621
 
        def _question_ok(*args):
622
 
            questions.append(args)
623
 
            questions.append('OK')
624
 
            return gtk.RESPONSE_OK
625
 
 
626
 
        dlg._question_dialog = _question_cancel
 
633
        self._set_question_no(dlg)
627
634
        dlg._do_commit()
628
635
        self.assertEqual(
629
636
            [('Commit with an empty message?',
630
637
              'You can describe your commit intent in the message.'),
631
638
              'NO',
632
 
            ], questions)
 
639
            ], self.questions)
633
640
        # By saying NO, nothing should be committed.
634
641
        self.assertEqual(rev_id, tree.last_revision())
635
642
        self.assertIs(None, dlg.committed_revision_id)
636
643
        self.assertTrue(dlg._global_message_text_view.get_property('is-focus'))
637
644
 
638
 
        dlg._question_dialog = _question_ok
639
 
        del questions[:]
 
645
        self._set_question_yes(dlg)
640
646
 
641
647
        dlg._do_commit()
642
648
        self.assertEqual(
643
649
            [('Commit with an empty message?',
644
650
              'You can describe your commit intent in the message.'),
645
 
              'OK',
646
 
            ], questions)
 
651
              'YES',
 
652
            ], self.questions)
647
653
        committed = tree.last_revision()
648
654
        self.assertNotEqual(rev_id, committed)
649
655
        self.assertEqual(committed, dlg.committed_revision_id)
662
668
        rev = tree.branch.repository.get_revision(last_rev)
663
669
        self.assertEqual(last_rev, rev.revision_id)
664
670
        self.assertEqual('Some text\n', rev.message)
 
671
 
 
672
    def test_pointless_commit(self):
 
673
        tree = self.make_branch_and_tree('tree')
 
674
        self.build_tree(['tree/a'])
 
675
        tree.add(['a'], ['a-id'])
 
676
        rev_id1 = tree.commit('one')
 
677
 
 
678
        dlg = commit.CommitDialog(tree)
 
679
        dlg._set_global_commit_message('Some text\n')
 
680
 
 
681
        self._set_question_no(dlg)
 
682
        dlg._do_commit()
 
683
 
 
684
        self.assertIs(None, dlg.committed_revision_id)
 
685
        self.assertEqual(rev_id1, tree.last_revision())
 
686
        self.assertEqual(
 
687
            [('Commit with no changes?',
 
688
              'There are no changes in the working tree.'
 
689
              ' Do you want to commit anyway?'),
 
690
              'NO',
 
691
            ], self.questions)
 
692
 
 
693
        self._set_question_yes(dlg)
 
694
        dlg._do_commit()
 
695
 
 
696
        rev_id2 = tree.last_revision()
 
697
        self.assertEqual(rev_id2, dlg.committed_revision_id)
 
698
        self.assertNotEqual(rev_id1, rev_id2)
 
699
        self.assertEqual(
 
700
            [('Commit with no changes?',
 
701
              'There are no changes in the working tree.'
 
702
              ' Do you want to commit anyway?'),
 
703
              'YES',
 
704
            ], self.questions)
 
705
 
 
706
    def test_unknowns(self):
 
707
        """We should check if there are unknown files."""
 
708
        tree = self.make_branch_and_tree('tree')
 
709
        rev_id1 = tree.commit('one')
 
710
        self.build_tree(['tree/a', 'tree/b'])
 
711
        tree.add(['a'], ['a-id'])
 
712
 
 
713
        dlg = commit.CommitDialog(tree)
 
714
        dlg._set_global_commit_message('Some text\n')
 
715
        self._set_question_no(dlg)
 
716
 
 
717
        dlg._do_commit()
 
718
 
 
719
        self.assertIs(None, dlg.committed_revision_id)
 
720
        self.assertEqual(rev_id1, tree.last_revision())
 
721
        self.assertEqual(
 
722
            [("Commit with unknowns?",
 
723
              "Unknown files exist in the working tree. Commit anyway?"),
 
724
              "NO",
 
725
            ], self.questions)
 
726
 
 
727
        self._set_question_yes(dlg)
 
728
        dlg._do_commit()
 
729
 
 
730
        rev_id2 = tree.last_revision()
 
731
        self.assertNotEqual(rev_id1, rev_id2)
 
732
        self.assertEqual(rev_id2, dlg.committed_revision_id)
 
733
        self.assertEqual(
 
734
            [("Commit with unknowns?",
 
735
              "Unknown files exist in the working tree. Commit anyway?"),
 
736
              "YES",
 
737
            ], self.questions)
 
738