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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Fixtures that can be used within tests.
19
19
 
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.
30
30
 
31
31
def generate_unicode_names():
32
32
    """Generate a sequence of arbitrary unique unicode names.
33
 
    
 
33
 
34
34
    By default they are not representable in ascii.
35
 
    
 
35
 
36
36
    >>> gen = generate_unicode_names()
37
 
    >>> n1 = gen.next()
38
 
    >>> n2 = gen.next()
 
37
    >>> n1 = next(gen)
 
38
    >>> n2 = next(gen)
39
39
    >>> type(n1)
40
 
    <type 'unicode'>
 
40
    <class 'str'>
41
41
    >>> n1 == n2
42
42
    False
43
43
    >>> n1.encode('ascii', 'replace') == n1
60
60
    """Return a generator of unicode encoding names.
61
61
 
62
62
    These can be passed to Python encode/decode/etc.
63
 
    
 
63
 
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
66
66
        strings.
67
67
 
68
 
    >>> n1 = generate_unicode_names().next()
69
 
    >>> enc = generate_unicode_encodings(universal_encoding=True).next()
70
 
    >>> enc2 = generate_unicode_encodings(universal_encoding=False).next()
 
68
    >>> n1 = next(generate_unicode_names())
 
69
    >>> enc = next(generate_unicode_encodings(universal_encoding=True))
 
70
    >>> enc2 = next(generate_unicode_encodings(universal_encoding=False))
71
71
    >>> n1.encode(enc).decode(enc) == n1
72
72
    True
73
73
    >>> try:
74
74
    ...   n1.encode(enc2).decode(enc2)
75
75
    ... except UnicodeError:
76
 
    ...   print 'fail'
 
76
    ...   print('fail')
77
77
    fail
78
78
    """
79
79
    # TODO: check they're supported on this platform?
92
92
 
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.
96
96
 
97
97
    def __exit__(self, exc_type, exc_val, exc_tb):
98
98
        self._calls.append('__exit__')
99
 
        return False # propogate exceptions.
 
99
        return False  # propogate exceptions.
100
100
 
101
101
 
102
102
def build_branch_with_non_ancestral_rev(branch_builder):
118
118
    :returns: the new branch
119
119
    """
120
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')
 
121
    rev1 = branch_builder.build_commit(message="Rev 1")
 
122
    rev2 = branch_builder.build_commit(message="Rev 2")
123
123
    # Move the branch tip back to the first commit
124
124
    source = branch_builder.get_branch()
125
 
    source.set_last_revision_info(1, 'rev-1')
126
 
    return source
 
125
    source.set_last_revision_info(1, rev1)
 
126
    return source, rev1, rev2
127
127
 
128
128
 
129
129
def make_branch_and_populated_tree(testcase):
135
135
    # doesn't need to be bound to the particular files created? -- mbp
136
136
    # 20110705
137
137
    tree = testcase.make_branch_and_tree('t')
138
 
    testcase.build_tree_contents([('t/hello', 'hello world')])
139
 
    tree.add(['hello'], ['hello-id'])
 
138
    testcase.build_tree_contents([('t/hello', b'hello world')])
 
139
    tree.add(['hello'], [b'hello-id'])
140
140
    return tree
141
141
 
142
142
 
143
143
class TimeoutFixture(object):
144
144
    """Kill a test with sigalarm if it runs too long.
145
 
    
 
145
 
146
146
    Only works on Unix at present.
147
147
    """
148
148