18
18
"""Fixtures that can be used within tests.
20
20
Fixtures can be created during a test as a way to separate out creation of
21
objects to test. Fixture objects can hold some state so that different
21
objects to test. Fixture objects can hold some state so that different
22
22
objects created during a test instance can be related. Normally a fixture
23
23
should live only for the duration of a single test, and its tearDown method
24
24
should be passed to `addCleanup` on the test.
60
60
"""Return a generator of unicode encoding names.
62
62
These can be passed to Python encode/decode/etc.
64
64
:param universal_encoding: True/False/None tristate to say whether the
65
generated encodings either can or cannot encode all unicode
65
generated encodings either can or cannot encode all unicode
68
>>> n1 = next(generate_unicode_names())
69
>>> enc = next(generate_unicode_encodings(universal_encoding=True))
70
>>> enc2 = next(generate_unicode_encodings(universal_encoding=False))
68
>>> n1 = generate_unicode_names().next()
69
>>> enc = generate_unicode_encodings(universal_encoding=True).next()
70
>>> enc2 = generate_unicode_encodings(universal_encoding=False).next()
71
71
>>> n1.encode(enc).decode(enc) == n1
74
74
... n1.encode(enc2).decode(enc2)
75
75
... except UnicodeError:
79
79
# TODO: check they're supported on this platform?
93
93
def __enter__(self):
94
94
self._calls.append('__enter__')
95
return self # This is bound to the 'as' clause in a with statement.
95
return self # This is bound to the 'as' clause in a with statement.
97
97
def __exit__(self, exc_type, exc_val, exc_tb):
98
98
self._calls.append('__exit__')
99
return False # propogate exceptions.
102
def build_branch_with_non_ancestral_rev(branch_builder):
103
"""Builds a branch with a rev not in the ancestry of the tip.
105
This is the revision graph::
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.
116
:param branch_builder: A BranchBuilder (e.g. from
117
TestCaseWithMemoryTransport.make_branch_builder).
118
:returns: the new branch
120
# Make a sequence of two commits
121
rev1 = branch_builder.build_commit(message="Rev 1")
122
rev2 = branch_builder.build_commit(message="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, rev1)
126
return source, rev1, rev2
129
def make_branch_and_populated_tree(testcase):
130
"""Make a simple branch and tree.
132
The tree holds some added but uncommitted files.
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
137
tree = testcase.make_branch_and_tree('t')
138
testcase.build_tree_contents([('t/hello', b'hello world')])
139
tree.add(['hello'], [b'hello-id'])
143
class TimeoutFixture(object):
144
"""Kill a test with sigalarm if it runs too long.
146
Only works on Unix at present.
149
def __init__(self, timeout_secs):
151
self.timeout_secs = timeout_secs
152
self.alarm_fn = getattr(signal, 'alarm', None)
155
if self.alarm_fn is not None:
156
self.alarm_fn(self.timeout_secs)
159
if self.alarm_fn is not None:
99
return False # propogate exceptions.