/brz/remove-bazaar

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