/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 tests/test_builder.py

Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 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
"""Test our ability to build up test repositories"""
 
18
 
 
19
from cStringIO import StringIO
 
20
 
 
21
from bzrlib.plugins.git import tests
 
22
 
 
23
 
 
24
class TestCommitBuilder(tests.TestCase):
 
25
 
 
26
    def test__create_blob(self):
 
27
        stream = StringIO()
 
28
        builder = tests.GitCommitBuilder(stream)
 
29
        self.assertEqual(1, builder._create_blob('foo\nbar\n'))
 
30
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
 
31
                             stream.getvalue())
 
32
 
 
33
    def test_set_file(self):
 
34
        stream = StringIO()
 
35
        builder = tests.GitCommitBuilder(stream)
 
36
        builder.set_file('foobar', 'foo\nbar\n', False)
 
37
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
 
38
                             stream.getvalue())
 
39
        self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info)
 
40
 
 
41
    def test_set_file_unicode(self):
 
42
        stream = StringIO()
 
43
        builder = tests.GitCommitBuilder(stream)
 
44
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
 
45
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
 
46
                             stream.getvalue())
 
47
        self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
 
48
 
 
49
    def test_set_file_executable(self):
 
50
        stream = StringIO()
 
51
        builder = tests.GitCommitBuilder(stream)
 
52
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True)
 
53
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
 
54
                             stream.getvalue())
 
55
        self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
 
56
 
 
57
    def test_set_link(self):
 
58
        stream = StringIO()
 
59
        builder = tests.GitCommitBuilder(stream)
 
60
        builder.set_link(u'f\xb5/bar', 'link/contents')
 
61
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
 
62
                             stream.getvalue())
 
63
        self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
 
64
 
 
65
    def test_delete_entry(self):
 
66
        stream = StringIO()
 
67
        builder = tests.GitCommitBuilder(stream)
 
68
        builder.delete_entry(u'path/to/f\xb5')
 
69
        self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
 
70
 
 
71
    def test_add_and_commit(self):
 
72
        stream = StringIO()
 
73
        builder = tests.GitCommitBuilder(stream)
 
74
 
 
75
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
 
76
        self.assertEqual(2, builder.commit('refs/head/master',
 
77
                                           'Joe Foo <joe@foo.com>',
 
78
                                           u'committing f\xb5/bar',
 
79
                                           timestamp=1194586400,
 
80
                                           timezone='+0100'))
 
81
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n'
 
82
                             'commit refs/head/master\n'
 
83
                             'mark :2\n'
 
84
                             'committer Joe Foo <joe@foo.com> 1194586400 +0100\n'
 
85
                             'data 18\n'
 
86
                             'committing f\xc2\xb5/bar'
 
87
                             '\n'
 
88
                             'M 100644 :1 f\xc2\xb5/bar\n'
 
89
                             '\n',
 
90
                             stream.getvalue())