/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 bzrlib/tests/blackbox/test_logformats.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
 
17
 
16
18
"""Black-box tests for default log_formats/log_formatters
17
19
"""
18
20
 
 
21
 
19
22
import os
20
23
 
21
 
from bzrlib.branch import Branch
22
 
from bzrlib.tests import TestCaseInTempDir
23
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
24
 
 
25
 
 
26
 
class TestLogFormats(TestCaseInTempDir):
27
 
 
28
 
    def bzr(self, *args, **kwargs):
29
 
        return self.run_bzr(*args, **kwargs)[0]
 
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
30
58
 
31
59
    def test_log_default_format(self):
32
 
        self.setup_config()
33
 
 
34
 
        self.bzr('init')
35
 
        open('a', 'wb').write('foo\n')
36
 
        self.bzr('add a')
37
 
 
38
 
        self.bzr('commit -m 1')
39
 
        open('a', 'wb').write('baz\n')
40
 
 
41
 
        self.bzr('commit -m 2')
42
 
 
43
 
        # only the lines formatter is this short
44
 
        self.assertEquals(3, len(self.bzr('log').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()))
45
64
 
46
65
    def test_log_format_arg(self):
47
 
        self.bzr('init')
48
 
        open('a', 'wb').write('foo\n')
49
 
        self.bzr('add a')
50
 
 
51
 
        self.bzr('commit -m 1')
52
 
        open('a', 'wb').write('baz\n')
53
 
 
54
 
        self.bzr('commit -m 2')
55
 
 
56
 
        # only the lines formatter is this short
57
 
        self.assertEquals(7, len(self.bzr('log --log-format short').split('\n')))
 
66
        self._make_simple_branch()
 
67
        log = self.run_bzr(['log', '--log-format', 'short'])[0]
58
68
 
59
69
    def test_missing_default_format(self):
60
 
        self.setup_config()
61
 
 
62
 
        os.mkdir('a')
63
 
        os.chdir('a')
64
 
        self.bzr('init')
65
 
 
66
 
        open('a', 'wb').write('foo\n')
67
 
        self.bzr('add a')
68
 
        self.bzr('commit -m 1')
69
 
 
70
 
        os.chdir('..')
71
 
        self.bzr('branch a b')
72
 
        os.chdir('a')
73
 
 
74
 
        open('a', 'wb').write('bar\n')
75
 
        self.bzr('commit -m 2')
76
 
 
77
 
        open('a', 'wb').write('baz\n')
78
 
        self.bzr('commit -m 3')
79
 
 
80
 
        os.chdir('../b')
81
 
 
82
 
        self.assertEquals(5, len(self.bzr('missing', retcode=1).split('\n')))
83
 
 
84
 
        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()))
85
81
 
86
82
    def test_missing_format_arg(self):
87
 
        self.setup_config()
88
 
 
89
 
        os.mkdir('a')
90
 
        os.chdir('a')
91
 
        self.bzr('init')
92
 
 
93
 
        open('a', 'wb').write('foo\n')
94
 
        self.bzr('add a')
95
 
        self.bzr('commit -m 1')
96
 
 
97
 
        os.chdir('..')
98
 
        self.bzr('branch a b')
99
 
        os.chdir('a')
100
 
 
101
 
        open('a', 'wb').write('bar\n')
102
 
        self.bzr('commit -m 2')
103
 
 
104
 
        open('a', 'wb').write('baz\n')
105
 
        self.bzr('commit -m 3')
106
 
 
107
 
        os.chdir('../b')
108
 
 
109
 
        self.assertEquals(9, len(self.bzr('missing --log-format short',
110
 
                                          retcode=1).split('\n')))
111
 
 
112
 
        os.chdir('..')
113
 
 
114
 
 
115
 
    def setup_config(self):
116
 
        if os.path.isfile(config_filename()):
117
 
                # Something is wrong in environment, 
118
 
                # we risk overwriting users config 
119
 
                self.assert_(config_filename() + "exists, abort")
120
 
            
121
 
        ensure_config_dir_exists()
122
 
        CONFIG=("[DEFAULT]\n"
123
 
                "email=Joe Foo <joe@foo.com>\n"
124
 
                "log_format=line\n")
125
 
 
126
 
        open(config_filename(),'wb').write(CONFIG)
 
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()))
 
94
 
 
95
    def test_logformat_gnu_changelog(self):
 
96
        # from http://launchpad.net/bugs/29582/
 
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)