/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006, 2007, 2009, 2011, 2016 Canonical Ltd
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4070.4.2 by Martin Pool
Remove obsolete run_bzr wrapper from test_logformats
16
17
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
18
"""Black-box tests for default log_formats/log_formatters
19
"""
20
4070.4.2 by Martin Pool
Remove obsolete run_bzr wrapper from test_logformats
21
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
22
import os
23
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy import (
7336.2.1 by Martin
Split non-ini config methods to bedding
25
    bedding,
4325.4.1 by Vincent Ladeuil
Some cleanups.
26
    tests,
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
27
    workingtree,
4325.4.1 by Vincent Ladeuil
Some cleanups.
28
    )
29
30
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
31
class TestLogFormats(tests.TestCaseWithTransport):
4325.4.1 by Vincent Ladeuil
Some cleanups.
32
33
    def setUp(self):
34
        super(TestLogFormats, self).setUp()
35
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
36
        # Create a config file with some useful variables
7336.2.1 by Martin
Split non-ini config methods to bedding
37
        conf_path = bedding.config_path()
4325.4.1 by Vincent Ladeuil
Some cleanups.
38
        if os.path.isfile(conf_path):
7143.15.2 by Jelmer Vernooij
Run autopep8.
39
            # Something is wrong in environment,
40
            # we risk overwriting users config
41
            self.fail("%s exists" % conf_path)
4325.4.1 by Vincent Ladeuil
Some cleanups.
42
7336.2.1 by Martin
Split non-ini config methods to bedding
43
        bedding.ensure_config_dir_exists()
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
44
        with open(conf_path, 'wb') as f:
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
45
            f.write(b"""[DEFAULT]
4325.4.1 by Vincent Ladeuil
Some cleanups.
46
email=Joe Foo <joe@foo.com>
47
log_format=line
48
""")
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
49
50
    def _make_simple_branch(self, relpath='.'):
51
        wt = self.make_branch_and_tree(relpath)
52
        wt.commit('first revision')
53
        wt.commit('second revision')
54
        return wt
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
55
56
    def test_log_default_format(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
57
        self._make_simple_branch()
58
        # only the lines formatter is this short, one line by revision
59
        log = self.run_bzr('log')[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
60
        self.assertEqual(2, len(log.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
61
62
    def test_log_format_arg(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
63
        self._make_simple_branch()
64
        log = self.run_bzr(['log', '--log-format', 'short'])[0]
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
65
66
    def test_missing_default_format(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
67
        wt = self._make_simple_branch('a')
68
        self.run_bzr(['branch', 'a', 'b'])
69
        wt.commit('third revision')
70
        wt.commit('fourth revision')
71
72
        missing = self.run_bzr('missing', retcode=1, working_dir='b')[0]
73
        # one line for 'Using save location'
74
        # one line for 'You are missing 2 revision(s)'
75
        # one line by missing revision (the line log format is used as
76
        # configured)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
77
        self.assertEqual(4, len(missing.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
78
79
    def test_missing_format_arg(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
80
        wt = self._make_simple_branch('a')
81
        self.run_bzr(['branch', 'a', 'b'])
82
        wt.commit('third revision')
83
        wt.commit('fourth revision')
84
85
        missing = self.run_bzr(['missing', '--log-format', 'short'],
86
                               retcode=1, working_dir='b')[0]
87
        # one line for 'Using save location'
88
        # one line for 'You are missing 2 revision(s)'
89
        # three lines by missing revision
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
90
        self.assertEqual(8, len(missing.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
91
4070.4.4 by Martin Pool
Add dodgy smoketest for gnu changelogs
92
    def test_logformat_gnu_changelog(self):
93
        # from http://launchpad.net/bugs/29582/
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
94
        wt = self.make_branch_and_tree('.')
95
        wt.commit('first revision', timestamp=1236045060,
7143.15.2 by Jelmer Vernooij
Run autopep8.
96
                  timezone=0)  # Aka UTC
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
97
98
        log, err = self.run_bzr(['log', '--log-format', 'gnu-changelog',
99
                                 '--timezone=utc'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
100
        self.assertEqual('', err)
101
        expected = """2009-03-03  Joe Foo  <joe@foo.com>
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
102
103
\tfirst revision
104
105
"""
106
        self.assertEqualDiff(expected, log)
5725.1.1 by Neil Martinsen-Burrell
Scale author field with length of line in LineLogFormatter
107
108
    def test_logformat_line_wide(self):
109
        """Author field should get larger for column widths over 80"""
110
        wt = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
111
        wt.commit('revision with a long author', committer='Person with'
5725.1.3 by Neil Martinsen-Burrell
fix off by one knock-on error in blackbox test
112
                  ' long name SENTINEL')
5725.1.1 by Neil Martinsen-Burrell
Scale author field with length of line in LineLogFormatter
113
        log, err = self.run_bzr('log --line')
114
        self.assertNotContainsString(log, 'SENTINEL')
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
115
        self.overrideEnv('BRZ_COLUMNS', '116')
5725.1.1 by Neil Martinsen-Burrell
Scale author field with length of line in LineLogFormatter
116
        log, err = self.run_bzr('log --line')
117
        self.assertContainsString(log, 'SENT...')
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
118
        self.overrideEnv('BRZ_COLUMNS', '0')
5725.1.1 by Neil Martinsen-Burrell
Scale author field with length of line in LineLogFormatter
119
        log, err = self.run_bzr('log --line')
120
        self.assertContainsString(log, 'SENTINEL')