~mbp/bzr/340352-rename-lock

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-06-05 23:21:51 UTC
  • mfrom: (4105.2.310 +trunk)
  • Revision ID: mbp@sourcefrog.net-20090605232151-luwmyyl95siraqyz
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Black-box tests for default log_formats/log_formatters
21
21
 
22
22
import os
23
23
 
24
 
 
25
 
from bzrlib.branch import Branch
26
 
from bzrlib.tests import TestCaseInTempDir
27
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
28
 
 
29
 
 
30
 
class TestLogFormats(TestCaseInTempDir):
 
24
from bzrlib import (
 
25
    config,
 
26
    tests,
 
27
    workingtree,
 
28
    )
 
29
 
 
30
 
 
31
class TestLogFormats(tests.TestCaseWithTransport):
 
32
 
 
33
    def setUp(self):
 
34
        super(TestLogFormats, self).setUp()
 
35
 
 
36
        # Create a config file with some useful variables
 
37
        conf_path = config.config_filename()
 
38
        if os.path.isfile(conf_path):
 
39
                # Something is wrong in environment,
 
40
                # we risk overwriting users config
 
41
                self.fail("%s exists" % conf_path)
 
42
 
 
43
        config.ensure_config_dir_exists()
 
44
        f = open(conf_path,'wb')
 
45
        try:
 
46
            f.write("""[DEFAULT]
 
47
email=Joe Foo <joe@foo.com>
 
48
log_format=line
 
49
""")
 
50
        finally:
 
51
            f.close()
 
52
 
 
53
    def _make_simple_branch(self, relpath='.'):
 
54
        wt = self.make_branch_and_tree(relpath)
 
55
        wt.commit('first revision')
 
56
        wt.commit('second revision')
 
57
        return wt
31
58
 
32
59
    def test_log_default_format(self):
33
 
        self.setup_config()
34
 
 
35
 
        self.run_bzr('init')
36
 
        open('a', 'wb').write('foo\n')
37
 
        self.run_bzr('add a')
38
 
 
39
 
        self.run_bzr('commit -m 1')
40
 
        open('a', 'wb').write('baz\n')
41
 
 
42
 
        self.run_bzr('commit -m 2')
43
 
 
44
 
        # only the lines formatter is this short
45
 
        self.assertEquals(3, len(self.run_bzr('log')[0].split('\n')))
 
60
        self._make_simple_branch()
 
61
        # only the lines formatter is this short, one line by revision
 
62
        log = self.run_bzr('log')[0]
 
63
        self.assertEquals(2, len(log.splitlines()))
46
64
 
47
65
    def test_log_format_arg(self):
48
 
        self.run_bzr('init')
49
 
        open('a', 'wb').write('foo\n')
50
 
        self.run_bzr('add a')
51
 
 
52
 
        self.run_bzr('commit -m 1')
53
 
        open('a', 'wb').write('baz\n')
54
 
 
55
 
        self.run_bzr('commit -m 2')
56
 
 
57
 
        # only the lines formatter is this short
58
 
        self.assertEquals(7,
59
 
            len(self.run_bzr('log --log-format short')[0].split('\n')))
 
66
        self._make_simple_branch()
 
67
        log = self.run_bzr(['log', '--log-format', 'short'])[0]
60
68
 
61
69
    def test_missing_default_format(self):
62
 
        self.setup_config()
63
 
 
64
 
        os.mkdir('a')
65
 
        os.chdir('a')
66
 
        self.run_bzr('init')
67
 
 
68
 
        open('a', 'wb').write('foo\n')
69
 
        self.run_bzr('add a')
70
 
        self.run_bzr('commit -m 1')
71
 
 
72
 
        os.chdir('..')
73
 
        self.run_bzr('branch a b')
74
 
        os.chdir('a')
75
 
 
76
 
        open('a', 'wb').write('bar\n')
77
 
        self.run_bzr('commit -m 2')
78
 
 
79
 
        open('a', 'wb').write('baz\n')
80
 
        self.run_bzr('commit -m 3')
81
 
 
82
 
        os.chdir('../b')
83
 
 
84
 
        self.assertEquals(5,
85
 
            len(self.run_bzr('missing', retcode=1)[0].split('\n')))
86
 
 
87
 
        os.chdir('..')
 
70
        wt = self._make_simple_branch('a')
 
71
        self.run_bzr(['branch', 'a', 'b'])
 
72
        wt.commit('third revision')
 
73
        wt.commit('fourth revision')
 
74
 
 
75
        missing = self.run_bzr('missing', retcode=1, working_dir='b')[0]
 
76
        # one line for 'Using save location'
 
77
        # one line for 'You are missing 2 revision(s)'
 
78
        # one line by missing revision (the line log format is used as
 
79
        # configured)
 
80
        self.assertEquals(4, len(missing.splitlines()))
88
81
 
89
82
    def test_missing_format_arg(self):
90
 
        self.setup_config()
91
 
 
92
 
        os.mkdir('a')
93
 
        os.chdir('a')
94
 
        self.run_bzr('init')
95
 
 
96
 
        open('a', 'wb').write('foo\n')
97
 
        self.run_bzr('add a')
98
 
        self.run_bzr('commit -m 1')
99
 
 
100
 
        os.chdir('..')
101
 
        self.run_bzr('branch a b')
102
 
        os.chdir('a')
103
 
 
104
 
        open('a', 'wb').write('bar\n')
105
 
        self.run_bzr('commit -m 2')
106
 
 
107
 
        open('a', 'wb').write('baz\n')
108
 
        self.run_bzr('commit -m 3')
109
 
 
110
 
        os.chdir('../b')
111
 
 
112
 
        self.assertEquals(9,
113
 
            len(self.run_bzr('missing --log-format short',
114
 
                retcode=1)[0].split('\n')))
115
 
 
116
 
        os.chdir('..')
 
83
        wt = self._make_simple_branch('a')
 
84
        self.run_bzr(['branch', 'a', 'b'])
 
85
        wt.commit('third revision')
 
86
        wt.commit('fourth revision')
 
87
 
 
88
        missing = self.run_bzr(['missing', '--log-format', 'short'],
 
89
                               retcode=1, working_dir='b')[0]
 
90
        # one line for 'Using save location'
 
91
        # one line for 'You are missing 2 revision(s)'
 
92
        # three lines by missing revision
 
93
        self.assertEquals(8, len(missing.splitlines()))
117
94
 
118
95
    def test_logformat_gnu_changelog(self):
119
96
        # from http://launchpad.net/bugs/29582/
120
 
        self.setup_config()
121
 
        repo_url = self.make_trivial_history()
122
 
 
123
 
        out, err = self.run_bzr(
124
 
            ['log', self.get_url('repo/a'),
125
 
             '--log-format=gnu-changelog',
126
 
             '--timezone=utc'])
127
 
        self.assertEquals(err, '')
128
 
        self.assertEqualDiff(out,
129
 
"""2009-03-03  Joe Foo  <joe@foo.com>
130
 
 
131
 
\tcommit 1
132
 
 
133
 
""")
134
 
 
135
 
    def make_trivial_history(self):
136
 
        """Make a one-commit history and return the URL of the branch"""
137
 
        repo = self.make_repository('repo', shared=True, format='1.6')
138
 
        bb = self.make_branch_builder('repo/a')
139
 
        bb.start_series()
140
 
        bb.build_snapshot('rev-1', None,
141
 
            [('add', ('', 'root-id', 'directory', ''))],
142
 
            timestamp=1236045060)
143
 
        bb.finish_series()
144
 
        return self.get_url('repo/a')
145
 
 
146
 
    def setup_config(self):
147
 
        if os.path.isfile(config_filename()):
148
 
                # Something is wrong in environment,
149
 
                # we risk overwriting users config
150
 
                self.assert_(config_filename() + "exists, abort")
151
 
 
152
 
        ensure_config_dir_exists()
153
 
        CONFIG=("[DEFAULT]\n"
154
 
                "email=Joe Foo <joe@foo.com>\n"
155
 
                "log_format=line\n")
156
 
 
157
 
        open(config_filename(),'wb').write(CONFIG)
 
97
        wt = self.make_branch_and_tree('.')
 
98
        wt.commit('first revision', timestamp=1236045060,
 
99
                  timezone=0) # Aka UTC
 
100
 
 
101
        log, err = self.run_bzr(['log', '--log-format', 'gnu-changelog',
 
102
                                 '--timezone=utc'])
 
103
        self.assertEquals('', err)
 
104
        expected = """2009-03-03  Joe Foo  <joe@foo.com>
 
105
 
 
106
\tfirst revision
 
107
 
 
108
"""
 
109
        self.assertEqualDiff(expected, log)