~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_commit.py

  • Committer: Robert Collins
  • Date: 2010-04-07 22:22:27 UTC
  • mto: This revision was merged to the branch mainline in revision 5138.
  • Revision ID: robertc@robertcollins.net-20100407222227-a5el12vho6d33ndx
Review feedback: add comment about return value and an additional test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
675
675
        self.assertContainsRe(err,
676
676
            r'^bzr: ERROR: Cannot lock.*readonly transport')
677
677
 
678
 
    def test_commit_hook_template(self):
 
678
    def setup_editor(self):
679
679
        # Test that commit template hooks work
680
680
        if sys.platform == "win32":
681
681
            f = file('fed.bat', 'w')
688
688
            f.close()
689
689
            os.chmod('fed.sh', 0755)
690
690
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
691
 
 
692
    def setup_commit_with_template(self):
 
693
        self.setup_editor()
691
694
        msgeditor.hooks.install_named_hook("commit_message_template",
692
695
                lambda commit_obj, msg: "save me some typing\n", None)
693
696
        tree = self.make_branch_and_tree('tree')
694
697
        self.build_tree(['tree/hello.txt'])
695
698
        tree.add('hello.txt')
 
699
        return tree
 
700
 
 
701
    def test_commit_hook_template_accepted(self):
 
702
        tree = self.setup_commit_with_template()
696
703
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
697
704
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
698
705
        self.assertEqual('save me some typing\n', last_rev.message)
 
706
 
 
707
    def test_commit_hook_template_rejected(self):
 
708
        tree = self.setup_commit_with_template()
 
709
        expected = tree.last_revision()
 
710
        out, err = self.run_bzr_error(["empty commit message"],
 
711
            "commit tree/hello.txt", stdin="n\n")
 
712
        self.assertEqual(expected, tree.last_revision())