/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_blackbox.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-12 22:51:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4955.
  • Revision ID: john@arbash-meinel.com-20100112225131-he8h411p6aeeb947
Delay grabbing an output stream until we actually go to show a diff.

This makes the test suite happy, but it also seems to be reasonable.
If we aren't going to write anything, we don't need to hold an
output stream open.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Black-box tests for bzr-git."""
18
 
 
19
 
from dulwich.repo import (
20
 
    Repo as GitRepo,
21
 
    )
22
 
 
23
 
import os
24
 
 
25
 
from bzrlib import (
26
 
    version_info as bzrlib_version,
27
 
    )
28
 
from bzrlib.bzrdir import (
29
 
    BzrDir,
30
 
    )
31
 
 
32
 
from bzrlib.tests.blackbox import ExternalBase
33
 
from bzrlib.tests import KnownFailure
34
 
 
35
 
from bzrlib.plugins.git import (
36
 
    tests,
37
 
    )
38
 
 
39
 
 
40
 
class TestGitBlackBox(ExternalBase):
41
 
 
42
 
    def simple_commit(self):
43
 
        # Create a git repository with a revision.
44
 
        repo = GitRepo.init(self.test_dir)
45
 
        builder = tests.GitBranchBuilder()
46
 
        builder.set_file('a', 'text for a\n', False)
47
 
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
48
 
        return repo, builder.finish()[r1]
49
 
 
50
 
    def test_nick(self):
51
 
        GitRepo.init(self.test_dir)
52
 
        dir = BzrDir.open(self.test_dir)
53
 
        dir.create_branch()
54
 
        output, error = self.run_bzr(['nick'])
55
 
        self.assertEquals("master\n", output)
56
 
 
57
 
    def test_info(self):
58
 
        self.simple_commit()
59
 
        output, error = self.run_bzr(['info'])
60
 
        self.assertEqual(error, '')
61
 
        self.assertTrue("Standalone tree (format: git)" in output)
62
 
 
63
 
    def test_branch(self):
64
 
        os.mkdir("gitbranch")
65
 
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
66
 
        os.chdir('gitbranch')
67
 
        builder = tests.GitBranchBuilder()
68
 
        builder.set_file('a', 'text for a\n', False)
69
 
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
70
 
        builder.finish()
71
 
        os.chdir('..')
72
 
 
73
 
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
74
 
        self.assertEqual(error, 'Branched 1 revision(s).\n')
75
 
 
76
 
    def test_checkout(self):
77
 
        os.mkdir("gitbranch")
78
 
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
79
 
        os.chdir('gitbranch')
80
 
        builder = tests.GitBranchBuilder()
81
 
        builder.set_file('a', 'text for a\n', False)
82
 
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
83
 
        builder.finish()
84
 
        os.chdir('..')
85
 
 
86
 
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
87
 
        self.assertEqual(error, '')
88
 
        self.assertEqual(output, '')
89
 
 
90
 
    def test_branch_ls(self):
91
 
        self.simple_commit()
92
 
        output, error = self.run_bzr(['ls', '-r-1'])
93
 
        self.assertEqual(error, '')
94
 
        self.assertEqual(output, "a\n")
95
 
 
96
 
    def test_init(self):
97
 
        self.run_bzr("init --git repo")
98
 
 
99
 
    def test_info_verbose(self):
100
 
        self.simple_commit()
101
 
 
102
 
        if bzrlib_version < (2, 4):
103
 
            raise KnownFailure("bzr info uses inventory on bzr < 2.4")
104
 
 
105
 
        output, error = self.run_bzr(['info', '-v'])
106
 
        self.assertEqual(error, '')
107
 
        self.assertTrue("Standalone tree (format: git)" in output)
108
 
        self.assertTrue("control: Local Git Repository" in output)
109
 
        self.assertTrue("branch: Git Branch" in output)
110
 
        self.assertTrue("repository: Git Repository" in output)
111
 
 
112
 
    def test_push_roundtripping(self):
113
 
        raise KnownFailure("roundtripping is not yet supported")
114
 
        self.with_roundtripping()
115
 
        os.mkdir("bla")
116
 
        GitRepo.init(os.path.join(self.test_dir, "bla"))
117
 
        self.run_bzr(['init', 'foo'])
118
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
119
 
        # when roundtripping is supported
120
 
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
121
 
        self.assertEquals("", output)
122
 
        self.assertTrue(error.endswith("Created new branch.\n"))
123
 
 
124
 
    def test_log(self):
125
 
        # Smoke test for "bzr log" in a git repository.
126
 
        self.simple_commit()
127
 
 
128
 
        # Check that bzr log does not fail and includes the revision.
129
 
        output, error = self.run_bzr(['log'])
130
 
        self.assertEqual(error, '')
131
 
        self.assertTrue(
132
 
            '<The commit message>' in output,
133
 
            "Commit message was not found in output:\n%s" % (output,))
134
 
 
135
 
    def test_log_verbose(self):
136
 
        # Smoke test for "bzr log -v" in a git repository.
137
 
        self.simple_commit()
138
 
 
139
 
        # Check that bzr log does not fail and includes the revision.
140
 
        output, error = self.run_bzr(['log', '-v'])
141
 
 
142
 
    def test_tags(self):
143
 
        git_repo, commit_sha1 = self.simple_commit()
144
 
        git_repo.refs["refs/tags/foo"] = commit_sha1
145
 
 
146
 
        output, error = self.run_bzr(['tags'])
147
 
        self.assertEquals(error, '')
148
 
        self.assertEquals(output, "foo                  1\n")
149
 
 
150
 
    def test_tag(self):
151
 
        self.simple_commit()
152
 
 
153
 
        output, error = self.run_bzr(["tag", "bar"])
154
 
 
155
 
        # bzr <= 2.2 emits this message in the output stream
156
 
        # bzr => 2.3 emits this message in the error stream
157
 
        self.assertEquals(error + output, 'Created tag bar.\n')
158
 
 
159
 
    def test_init_repo(self):
160
 
        output, error = self.run_bzr(["init", "--git", "bla.git"])
161
 
        self.assertEquals(error, '')
162
 
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
163