/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/__init__.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:
17
17
"""The basic test suite for bzr-git."""
18
18
 
19
19
import subprocess
 
20
import time
20
21
 
21
22
from bzrlib import (
22
23
    tests,
57
58
    return out
58
59
 
59
60
 
 
61
class GitBranchBuilder(object):
 
62
 
 
63
    def __init__(self, stream):
 
64
        self.commit_info = []
 
65
        self.stream = stream
 
66
        self._counter = 0
 
67
        self._branch = 'refs/head/master'
 
68
 
 
69
    def set_branch(self, branch):
 
70
        """Set the branch we are committing."""
 
71
        self._branch = branch
 
72
 
 
73
    def _create_blob(self, content):
 
74
        self._counter += 1
 
75
        self.stream.write('blob\n')
 
76
        self.stream.write('mark :%d\n' % (self._counter,))
 
77
        self.stream.write('data %d\n' % (len(content),))
 
78
        self.stream.write(content)
 
79
        self.stream.write('\n')
 
80
        return self._counter
 
81
 
 
82
    def set_file(self, path, content, executable):
 
83
        """Create or update content at a given path."""
 
84
        mark = self._create_blob(content)
 
85
        if executable:
 
86
            mode = '100755'
 
87
        else:
 
88
            mode = '100644'
 
89
        self.commit_info.append('M %s :%d %s\n'
 
90
                                % (mode, mark, path.encode('utf-8')))
 
91
 
 
92
    def set_link(self, path, link_target):
 
93
        """Create or update a link at a given path."""
 
94
        mark = self._create_blob(link_target)
 
95
        self.commit_info.append('M 120000 :%d %s\n'
 
96
                                % (mark, path.encode('utf-8')))
 
97
 
 
98
    def delete_entry(self, path):
 
99
        """This will delete files or symlinks at the given location."""
 
100
        self.commit_info.append('D %s\n' % (path.encode('utf-8'),))
 
101
 
 
102
    def commit(self, committer, message, timestamp=None,
 
103
               timezone='+0000', author=None):
 
104
        self._counter += 1
 
105
        mark = self._counter
 
106
        self.stream.write('commit %s\n' % (branch,))
 
107
        self.stream.write('mark :%d\n' % (mark,))
 
108
        self.stream.write('committer %s %s %s\n'
 
109
                          % (committer, timestamp, timezone))
 
110
        message = message.encode('UTF-8')
 
111
        self.stream.write('data %d\n' % (len(message),))
 
112
        self.stream.write(message)
 
113
        self.stream.write('\n')
 
114
        self.stream.writelines(self.commit_info)
 
115
        self.stream.write('\n')
 
116
        self.commit_info = []
 
117
        return mark
 
118
 
 
119
 
 
120
class GitBranchBuilder(object):
 
121
    """This uses git-fast-import to build up something directly."""
 
122
 
 
123
    def __init__(self, git_dir):
 
124
        self.git_dir = git_dir
 
125
 
 
126
 
60
127
def test_suite():
61
128
    loader = tests.TestLoader()
62
129
 
63
130
    suite = tests.TestSuite()
64
131
 
65
132
    testmod_names = [
 
133
        'test_builder',
66
134
        'test_git_branch',
67
135
        'test_git_dir',
68
136
        'test_git_repository',