/
api.txt
368 lines (248 loc) · 13.3 KB
/
api.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
API Reference
=============
.. currentmodule:: testfixtures
.. autoclass:: Comparison
.. autoclass:: LogCapture
:members:
.. autoclass:: OutputCapture
:members:
.. autoclass:: Replace
:members:
.. autoclass:: Replacer
:members:
.. autofunction:: replace
.. autoclass:: RoundComparison
:members:
.. autoclass:: RangeComparison
:members:
.. autoclass:: ShouldRaise
:members:
.. autofunction:: ShouldAssert
.. autoclass:: ShouldWarn
:members:
.. autoclass:: ShouldNotWarn
:members:
.. autoclass:: StringComparison
:members:
.. autoclass:: TempDirectory
:members:
.. autofunction:: compare(x, y, prefix=None, suffix=None, raises=True, recursive=True, strict=False, comparers=None, **kw)
.. autofunction:: testfixtures.comparison.register
.. autofunction:: testfixtures.comparison.compare_simple
.. autofunction:: testfixtures.comparison.compare_object
.. autofunction:: testfixtures.comparison.compare_exception
.. autofunction:: testfixtures.comparison.compare_with_type
.. autofunction:: testfixtures.comparison.compare_sequence
.. autofunction:: testfixtures.comparison.compare_generator
.. autofunction:: testfixtures.comparison.compare_tuple
.. autofunction:: testfixtures.comparison.compare_dict
.. autofunction:: testfixtures.comparison.compare_set
.. autofunction:: testfixtures.comparison.compare_text
.. autofunction:: diff
.. autofunction:: generator
.. autofunction:: log_capture
.. autoclass:: should_raise
.. autofunction:: tempdir
.. function:: test_date(year=2001, month=1, day=1, delta=None, delta_type='days', strict=False)
A function that returns a mock object that can be used in place of
the :class:`datetime.date` class but where the return value of
:meth:`~datetime.date.today` can be controlled.
If a single positional argument of ``None`` is passed, then the
queue of dates to be returned will be empty and you will need to
call :meth:`~tdate.set` or :meth:`~tdate.add` before calling
:meth:`~tdate.today`.
If an instance of :class:`~datetime.date` is passed as a single
positional argument, that will be used as the first date returned by
:meth:`~datetime.date.today`
:param year: An optional year used to create the first date returned by
:meth:`~datetime.date.today`.
:param month: An optional month used to create the first date returned by
:meth:`~datetime.date.today`.
:param day: An optional day used to create the first date returned by
:meth:`~datetime.date.today`.
:param delta: The size of the delta to use between values returned
from :meth:`~datetime.date.today`. If not specified,
it will increase by 1 with each call to
:meth:`~datetime.date.today`.
:param delta_type: The type of the delta to use between values returned
from :meth:`~datetime.date.today`. This can be
any keyword parameter accepted by the
:class:`~datetime.timedelta` constructor.
:param strict: If ``True``, calling the mock class and any of its
methods will result in an instance of the mock
being returned. If ``False``, the default, an
instance of :class:`~datetime.date` will be returned
instead.
The mock returned will behave exactly as the :class:`datetime.date`
class with the exception of the following members:
.. method:: tdate.add(*args, **kw)
This will add the :class:`datetime.date` created from the
supplied parameters to the queue of dates to be returned by
:meth:`~tdate.today`. An instance
of :class:`~datetime.date` may also be passed as a single
positional argument.
.. method:: tdate.set(*args, **kw)
This will set the :class:`datetime.date` created from the
supplied parameters as the next date to be returned by
:meth:`~tdate.today`, regardless of any dates in the
queue. An instance
of :class:`~datetime.date` may also be passed as a single
positional argument.
.. method:: tdate.tick(*args, **kw)
This method should be called either with a :class:`~datetime.timedelta`
as a positional argument, or with keyword parameters that will be used
to construct a :class:`~datetime.timedelta`.
The :class:`~datetime.timedelta` will be used to advance the next date
to be returned by :meth:`~tdate.today`.
.. classmethod:: tdate.today()
This will return the next supplied or calculated date from the
internal queue, rather than the actual current date.
.. function:: test_datetime(year=2001, month=1, day=1, hour=0, minute=0, second=0, microsecond=0,tzinfo=None, delta=None, delta_type='seconds', date_type=datetime.date, strict=False)
A function that returns a mock object that can be used in place of
the :class:`datetime.datetime` class but where the return value of
:meth:`~tdatetime.now` can be controlled.
If a single positional argument of ``None`` is passed, then the
queue of datetimes to be returned will be empty and you will need to
call :meth:`~tdatetime.set` or :meth:`~tdatetime.add` before calling
:meth:`~tdatetime.now` or :meth:`~tdatetime.utcnow`.
If an instance of :class:`~datetime.datetime` is passed as a single
positional argument, that will be used as the first date returned by
:meth:`~tdatetime.now`
:param year: An optional year used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param month: An optional month used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param day: An optional day used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param hour: An optional hour used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param minute: An optional minute used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param second: An optional second used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param microsecond: An optional microsecond used to create the first datetime returned by
:meth:`~tdatetime.now`.
:param tzinfo: An optional tzinfo that will be used to indicate the
timezone intended for the values returned by
returned by :meth:`~tdatetime.now`. It will be used to
correctly calculate return values when `tz` is passed
to :meth:`~tdatetime.now` and when
:meth:`~tdatetime.utcnow` is called.
:param delta: The size of the delta to use between values returned
from :meth:`~tdatetime.now`. If not specified,
it will increase by 1 with each call to
:meth:`~tdatetime.now`.
:param delta_type: The type of the delta to use between values returned
from :meth:`~tdatetime.now`. This can be
any keyword parameter accepted by the
:class:`~datetime.timedelta` constructor.
:param date_type: The type to use for the return value of the
:meth:`~datetime.datetime.date` method. This can
help with gotchas that occur when type checking
if performed on values returned by the mock's
:meth:`~datetime.datetime.date` method.
:param strict: If ``True``, calling the mock class and any of its
methods will result in an instance of the mock
being returned. If ``False``, the default, an
instance of :class:`~datetime.datetime` will be
returned instead.
The mock returned will behave exactly as the :class:`datetime.datetime`
class with the exception of the following members:
.. method:: tdatetime.add(*args, **kw)
This will add the :class:`datetime.datetime` created from the
supplied parameters to the queue of datetimes to be returned by
:meth:`~tdatetime.now` or :meth:`~tdatetime.utcnow`. An instance
of :class:`~datetime.datetime` may also be passed as a single
positional argument.
.. method:: tdatetime.set(*args, *kw)
This will set the :class:`datetime.datetime` created from the
supplied parameters as the next datetime to be returned by
:meth:`~tdatetime.now` or :meth:`~tdatetime.utcnow`, clearing out
any datetimes in the queue. An instance
of :class:`~datetime.datetime` may also be passed as a single
positional argument.
.. method:: tdatetime.tick(*args, **kw)
This method should be called either with a :class:`~datetime.timedelta`
as a positional argument, or with keyword parameters that will be used
to construct a :class:`~datetime.timedelta`.
The :class:`~datetime.timedelta` will be used to advance the next datetime
to be returned by :meth:`~tdatetime.now` or :meth:`~tdatetime.utcnow`.
.. classmethod:: tdatetime.now([tz])
:param tz: An optional timezone to apply to the returned time.
If supplied, it must be an instance of a
:class:`~datetime.tzinfo` subclass.
This will return the next supplied or calculated datetime from the
internal queue, rather than the actual current datetime.
If `tz` is supplied, it will be applied to the datetime that
would have have been returned from the internal queue, treating
that datetime as if it were in the UTC timezone.
.. classmethod:: tdatetime.utcnow()
This will return the next supplied or calculated datetime from the
internal queue, rather than the actual current UTC datetime.
No timezone will be applied, even that supplied to the constructor.
.. classmethod:: tdatetime.date()
This will return the date component of the current mock instance,
but using the date type supplied when the mock class was created.
.. function:: test_time(year=2001, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, delta=None, delta_type='seconds')
A function that returns a mock object that can be used in place of
the :class:`time.time` function but where the return value can be
controlled.
If a single positional argument of ``None`` is passed, then the
queue of times to be returned will be empty and you will need to
call :meth:`~ttime.set` or :meth:`~ttime.add` before calling
the mock.
If an instance of :class:`~datetime.datetime` is passed as a single
positional argument, that will be used to create the first time returned.
:param year: An optional year used to create the first time returned.
:param month: An optional month used to create the first time.
:param day: An optional day used to create the first time.
:param hour: An optional hour used to create the first time.
:param minute: An optional minute used to create the first time.
:param second: An optional second used to create the first time.
:param microsecond: An optional microsecond used to create the first time.
:param delta: The size of the delta to use between values returned.
If not specified, it will increase by 1 with each
call to the mock.
:param delta_type: The type of the delta to use between values
returned. This can be
any keyword parameter accepted by the
:class:`~datetime.timedelta` constructor.
The mock additionally has the following methods available on it:
.. method:: ttime.add(*args, **kw)
This will add the time specified by the supplied parameters to the
queue of times to be returned by calls to the mock. The
parameters are the same as the :class:`datetime.datetime`
constructor. An instance of :class:`~datetime.datetime` may also
be passed as a single positional argument.
.. method:: ttime.set(*args, **kw)
This will set the time specified by the supplied parameters as
the next time to be returned by a call to the mock, regardless of
any times in the queue. The parameters are the same as the
:class:`datetime.datetime` constructor. An instance of
:class:`~datetime.datetime` may also be passed as a single
positional argument.
.. method:: ttime.tick(*args, **kw)
This method should be called either with a :class:`~datetime.timedelta`
as a positional argument, or with keyword parameters that will be used
to construct a :class:`~datetime.timedelta`.
The :class:`~datetime.timedelta` will be used to advance the next time
to be returned by a call to the mock.
.. autofunction:: wrap
.. autoclass:: testfixtures.components.TestComponents
:members:
.. autoclass:: testfixtures.sybil.FileParser
.. data:: not_there
A singleton used to represent the absence of a particular attribute.
.. currentmodule:: testfixtures.popen
.. automodule:: testfixtures.popen
:members:
.. automodule:: testfixtures.django
:members:
.. function:: compare(x, y, prefix=None, suffix=None, raises=True, recursive=True, strict=False, comparers=None, **kw)
This is identical to :func:`compare`, but with ``ignore=True``
automatically set to make comparing django :class:`~django.db.models.Model`
instances easier.
.. automodule:: testfixtures.mock
.. automodule:: testfixtures.twisted
:member-order: bysource
:members: