~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/fixtures.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    def __exit__(self, exc_type, exc_val, exc_tb):
98
98
        self._calls.append('__exit__')
99
99
        return False # propogate exceptions.
 
100
 
 
101
 
 
102
def build_branch_with_non_ancestral_rev(branch_builder):
 
103
    """Builds a branch with a rev not in the ancestry of the tip.
 
104
 
 
105
    This is the revision graph::
 
106
 
 
107
      rev-2
 
108
        |
 
109
      rev-1
 
110
        |
 
111
      (null)
 
112
 
 
113
    The branch tip is 'rev-1'.  'rev-2' is present in the branch's repository,
 
114
    but is not part of rev-1's ancestry.
 
115
 
 
116
    :param branch_builder: A BranchBuilder (e.g. from
 
117
        TestCaseWithMemoryTransport.make_branch_builder).
 
118
    :returns: the new branch
 
119
    """
 
120
    # Make a sequence of two commits
 
121
    branch_builder.build_commit(message="Rev 1", rev_id='rev-1')
 
122
    branch_builder.build_commit(message="Rev 2", rev_id='rev-2')
 
123
    # Move the branch tip back to the first commit
 
124
    source = branch_builder.get_branch()
 
125
    source.set_last_revision_info(1, 'rev-1')
 
126
    return source
 
127
 
 
128
 
 
129
def make_branch_and_populated_tree(testcase):
 
130
    """Make a simple branch and tree.
 
131
 
 
132
    The tree holds some added but uncommitted files.
 
133
    """
 
134
    # TODO: Either accept or return the names of the files, so the caller
 
135
    # doesn't need to be bound to the particular files created? -- mbp
 
136
    # 20110705
 
137
    tree = testcase.make_branch_and_tree('t')
 
138
    testcase.build_tree_contents([('t/hello', 'hello world')])
 
139
    tree.add(['hello'], ['hello-id'])
 
140
    return tree
 
141
 
 
142
 
 
143
class TimeoutFixture(object):
 
144
    """Kill a test with sigalarm if it runs too long.
 
145
    
 
146
    Only works on Unix at present.
 
147
    """
 
148
 
 
149
    def __init__(self, timeout_secs):
 
150
        import signal
 
151
        self.timeout_secs = timeout_secs
 
152
        self.alarm_fn = getattr(signal, 'alarm', None)
 
153
 
 
154
    def setUp(self):
 
155
        if self.alarm_fn is not None:
 
156
            self.alarm_fn(self.timeout_secs)
 
157
 
 
158
    def cleanUp(self):
 
159
        if self.alarm_fn is not None:
 
160
            self.alarm_fn(0)