/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
7
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
12
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
17
"""Blackbox tests for version_info"""
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
18
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
19
import imp
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
20
import os
21
import sys
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
22
23
from bzrlib.tests import TestCase, TestCaseWithTransport
24
25
26
class TestVersionInfo(TestCaseWithTransport):
0.8.2 by John Arbash Meinel
Have working rio output
27
28
    def test_invalid_format(self):
29
        bzr = self.run_bzr
30
31
        bzr('version-info', '--format', 'quijibo', retcode=3)
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
32
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
33
    def create_branch(self):
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
34
        wt = self.make_branch_and_tree('branch')
35
        
36
        self.build_tree(['branch/a'])
37
        wt.add('a')
38
        wt.commit('adding a', rev_id='r1')
39
40
        self.build_tree(['branch/b'])
41
        wt.add('b')
42
        wt.commit('adding b', rev_id='r2')
43
44
        self.revisions = wt.branch.revision_history()
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
45
0.8.22 by John Arbash Meinel
Add a test that a default format is chosen
46
    def test_default(self):
47
        # smoketest that not supplying a --format still works
48
        self.create_branch()
49
50
        info = self.run_bzr('version-info', 'branch')[0]
51
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
52
    def test_rio(self):
53
        self.create_branch()
54
55
        def regen(*args):
0.8.22 by John Arbash Meinel
Add a test that a default format is chosen
56
            return self.run_bzr('version-info', '--format', 'rio',
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
57
                                'branch', *args)[0]
58
59
        txt = regen()
60
        self.assertContainsRe(txt, 'date:')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
61
        self.assertContainsRe(txt, 'build-date:')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
62
        self.assertContainsRe(txt, 'revno: 2')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
63
        self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
64
65
        txt = regen('--all')
66
        self.assertContainsRe(txt, 'date:')
67
        self.assertContainsRe(txt, 'revno: 2')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
68
        self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
69
        self.assertContainsRe(txt, 'clean: True')
70
        self.assertContainsRe(txt, 'revisions:')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
71
        for rev_id in self.revisions:
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
72
            self.assertContainsRe(txt, 'id: ' + rev_id)
73
        self.assertContainsRe(txt, 'message: adding a')
74
        self.assertContainsRe(txt, 'message: adding b')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
75
        self.assertContainsRe(txt, 'file-revisions:')
76
        self.assertContainsRe(txt, 'path: a')
77
        self.assertContainsRe(txt, 'path: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
78
79
        txt = regen('--check-clean')
80
        self.assertContainsRe(txt, 'clean: True')
81
82
        open('branch/c', 'wb').write('now unclean\n')
83
        txt = regen('--check-clean')
84
        self.assertContainsRe(txt, 'clean: False')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
85
86
        txt = regen('--check-clean', '--include-file-revisions')
87
        self.assertContainsRe(txt, 'revision: unversioned')
88
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
89
        os.remove('branch/c')
90
91
        # Make sure it works without a directory
92
        os.chdir('branch')
93
        txt = self.run_bzr('version-info', '--format', 'rio')
94
95
    def test_python(self):
96
        def bzr(*args, **kwargs):
97
            return self.run_bzr(*args, **kwargs)[0]
98
99
        def regen(*args):
100
            txt = self.run_bzr('version-info', '--format', 'python',
101
                               'branch', *args)[0]
102
            outf = open('test_version_information.py', 'wb')
103
            outf.write(txt)
104
            outf.close()
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
105
            module_info = imp.find_module('test_version_information',
106
                                          [os.getcwdu()])
107
            tvi = imp.load_module('tvi', *module_info)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
108
            # Make sure the module isn't cached
109
            sys.modules.pop('tvi', None)
110
            sys.modules.pop('test_version_information', None)
111
            # Delete the compiled versions, because we are generating
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
112
            # a new file fast enough that python doesn't detect it
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
113
            # needs to recompile, and using sleep() just makes the
114
            # test slow
115
            if os.path.exists('test_version_information.pyc'):
116
                os.remove('test_version_information.pyc')
117
            if os.path.exists('test_version_information.pyo'):
118
                os.remove('test_version_information.pyo')
119
            return tvi
120
121
        self.create_branch()
122
123
        tvi = regen()
124
        self.assertEqual(tvi.version_info['revno'], 2)
125
        self.failUnless(tvi.version_info.has_key('date'))
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
126
        self.assertEqual(self.revisions[-1], tvi.version_info['revision_id'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
127
        self.assertEqual({}, tvi.revisions)
128
        self.assertEqual({}, tvi.file_revisions)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
129
130
        tvi = regen('--all')
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
131
        rev_info = [(rev, message) for rev, message, timestamp, timezone 
132
                                   in tvi.revisions] 
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
133
        self.assertEqual([(self.revisions[0], 'adding a'),
134
                          (self.revisions[1], 'adding b')],
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
135
                         rev_info)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
136
        self.assertEqual(True, tvi.version_info['clean'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
137
        file_revisions = []
138
        for path in sorted(tvi.file_revisions.keys()):
139
            file_revisions.append((path, tvi.file_revisions[path]))
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
140
        self.assertEqual([('a', self.revisions[0]), ('b', self.revisions[1])],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
141
            file_revisions)
142
143
        open('branch/c', 'wb').write('now unclean\n')
144
        tvi = regen('--check-clean', '--include-file-revisions')
145
        self.assertEqual(False, tvi.version_info['clean'])
146
        self.assertEqual('unversioned', tvi.file_revisions['c'])
147
        os.remove('branch/c')
148
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
149