logxpy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logxpy/__init__.py +126 -0
- logxpy/_action.py +958 -0
- logxpy/_async.py +186 -0
- logxpy/_base.py +80 -0
- logxpy/_compat.py +71 -0
- logxpy/_config.py +45 -0
- logxpy/_dest.py +88 -0
- logxpy/_errors.py +58 -0
- logxpy/_fmt.py +68 -0
- logxpy/_generators.py +136 -0
- logxpy/_mask.py +23 -0
- logxpy/_message.py +195 -0
- logxpy/_output.py +517 -0
- logxpy/_pool.py +93 -0
- logxpy/_traceback.py +126 -0
- logxpy/_types.py +71 -0
- logxpy/_util.py +56 -0
- logxpy/_validation.py +486 -0
- logxpy/_version.py +21 -0
- logxpy/cli.py +61 -0
- logxpy/dask.py +172 -0
- logxpy/decorators.py +268 -0
- logxpy/filter.py +124 -0
- logxpy/journald.py +88 -0
- logxpy/json.py +149 -0
- logxpy/loggerx.py +253 -0
- logxpy/logwriter.py +84 -0
- logxpy/parse.py +191 -0
- logxpy/prettyprint.py +173 -0
- logxpy/serializers.py +36 -0
- logxpy/stdlib.py +23 -0
- logxpy/tai64n.py +45 -0
- logxpy/testing.py +472 -0
- logxpy/tests/__init__.py +9 -0
- logxpy/tests/common.py +36 -0
- logxpy/tests/strategies.py +231 -0
- logxpy/tests/test_action.py +1751 -0
- logxpy/tests/test_api.py +86 -0
- logxpy/tests/test_async.py +67 -0
- logxpy/tests/test_compat.py +13 -0
- logxpy/tests/test_config.py +21 -0
- logxpy/tests/test_coroutines.py +105 -0
- logxpy/tests/test_dask.py +211 -0
- logxpy/tests/test_decorators.py +54 -0
- logxpy/tests/test_filter.py +122 -0
- logxpy/tests/test_fmt.py +42 -0
- logxpy/tests/test_generators.py +292 -0
- logxpy/tests/test_journald.py +246 -0
- logxpy/tests/test_json.py +208 -0
- logxpy/tests/test_loggerx.py +44 -0
- logxpy/tests/test_logwriter.py +262 -0
- logxpy/tests/test_message.py +334 -0
- logxpy/tests/test_output.py +921 -0
- logxpy/tests/test_parse.py +309 -0
- logxpy/tests/test_pool.py +55 -0
- logxpy/tests/test_prettyprint.py +303 -0
- logxpy/tests/test_pyinstaller.py +35 -0
- logxpy/tests/test_serializers.py +36 -0
- logxpy/tests/test_stdlib.py +73 -0
- logxpy/tests/test_tai64n.py +66 -0
- logxpy/tests/test_testing.py +1051 -0
- logxpy/tests/test_traceback.py +251 -0
- logxpy/tests/test_twisted.py +814 -0
- logxpy/tests/test_util.py +45 -0
- logxpy/tests/test_validation.py +989 -0
- logxpy/twisted.py +265 -0
- logxpy-0.1.0.dist-info/METADATA +100 -0
- logxpy-0.1.0.dist-info/RECORD +72 -0
- logxpy-0.1.0.dist-info/WHEEL +5 -0
- logxpy-0.1.0.dist-info/entry_points.txt +2 -0
- logxpy-0.1.0.dist-info/licenses/LICENSE +201 -0
- logxpy-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hypothesis strategies for eliot.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from functools import partial
|
|
6
|
+
|
|
7
|
+
from hypothesis.strategies import (
|
|
8
|
+
builds,
|
|
9
|
+
dictionaries,
|
|
10
|
+
fixed_dictionaries,
|
|
11
|
+
floats,
|
|
12
|
+
integers,
|
|
13
|
+
lists,
|
|
14
|
+
just,
|
|
15
|
+
none,
|
|
16
|
+
one_of,
|
|
17
|
+
recursive,
|
|
18
|
+
text,
|
|
19
|
+
uuids,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from pyrsistent import pmap, pvector, ny, thaw
|
|
23
|
+
|
|
24
|
+
from .._action import (
|
|
25
|
+
ACTION_STATUS_FIELD,
|
|
26
|
+
ACTION_TYPE_FIELD,
|
|
27
|
+
FAILED_STATUS,
|
|
28
|
+
STARTED_STATUS,
|
|
29
|
+
SUCCEEDED_STATUS,
|
|
30
|
+
TaskLevel,
|
|
31
|
+
WrittenAction,
|
|
32
|
+
)
|
|
33
|
+
from .._message import (
|
|
34
|
+
EXCEPTION_FIELD,
|
|
35
|
+
REASON_FIELD,
|
|
36
|
+
TASK_LEVEL_FIELD,
|
|
37
|
+
TASK_UUID_FIELD,
|
|
38
|
+
WrittenMessage,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
task_level_indexes = integers(min_value=1, max_value=10)
|
|
42
|
+
# Task levels can be arbitrarily deep, but in the wild rarely as much as 100.
|
|
43
|
+
# Five seems a sensible average.
|
|
44
|
+
task_level_lists = lists(task_level_indexes, min_size=1, max_size=6)
|
|
45
|
+
task_levels = task_level_lists.map(lambda level: TaskLevel(level=level))
|
|
46
|
+
|
|
47
|
+
# Text generation is slow, and most of the things are short labels. We set
|
|
48
|
+
# a restricted alphabet so they're easier to read, and in general large
|
|
49
|
+
# amount of randomness in label generation doesn't enhance our testing in
|
|
50
|
+
# any way, since we don't parse type names or user field values.
|
|
51
|
+
labels = text(min_size=1, max_size=8, alphabet="CGAT")
|
|
52
|
+
|
|
53
|
+
timestamps = floats(min_value=0, max_value=1000.0)
|
|
54
|
+
|
|
55
|
+
message_core_dicts = fixed_dictionaries(
|
|
56
|
+
dict(
|
|
57
|
+
task_level=task_level_lists.map(pvector),
|
|
58
|
+
task_uuid=uuids().map(str),
|
|
59
|
+
timestamp=timestamps,
|
|
60
|
+
)
|
|
61
|
+
).map(pmap)
|
|
62
|
+
|
|
63
|
+
# Text generation is slow. We can make it faster by not generating so
|
|
64
|
+
# much. These are reasonable values.
|
|
65
|
+
message_data_dicts = dictionaries(
|
|
66
|
+
keys=labels,
|
|
67
|
+
values=labels,
|
|
68
|
+
# People don't normally put much more than ten fields in their
|
|
69
|
+
# messages, surely?
|
|
70
|
+
max_size=10,
|
|
71
|
+
).map(pmap)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def written_from_pmap(d):
|
|
75
|
+
"""
|
|
76
|
+
Convert a C{pmap} to a C{WrittenMessage}.
|
|
77
|
+
"""
|
|
78
|
+
return WrittenMessage.from_dict(thaw(d))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def union(*dicts):
|
|
82
|
+
result = pmap().evolver()
|
|
83
|
+
for d in dicts:
|
|
84
|
+
# Work around bug in pyrsistent where it sometimes loses updates if
|
|
85
|
+
# they contain some kv pairs that are identical to the ones in the
|
|
86
|
+
# dict being updated.
|
|
87
|
+
#
|
|
88
|
+
# https://github.com/tobgu/pyrsistent/pull/54
|
|
89
|
+
for key, value in d.items():
|
|
90
|
+
if key in result and result[key] is value:
|
|
91
|
+
continue
|
|
92
|
+
result[key] = value
|
|
93
|
+
return result.persistent()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
message_dicts = builds(union, message_data_dicts, message_core_dicts)
|
|
97
|
+
written_messages = message_dicts.map(written_from_pmap)
|
|
98
|
+
|
|
99
|
+
_start_action_fields = fixed_dictionaries(
|
|
100
|
+
{ACTION_STATUS_FIELD: just(STARTED_STATUS), ACTION_TYPE_FIELD: labels}
|
|
101
|
+
)
|
|
102
|
+
start_action_message_dicts = builds(union, message_dicts, _start_action_fields).map(
|
|
103
|
+
lambda x: x.update({TASK_LEVEL_FIELD: x[TASK_LEVEL_FIELD].set(-1, 1)})
|
|
104
|
+
)
|
|
105
|
+
start_action_messages = start_action_message_dicts.map(written_from_pmap)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def sibling_task_level(message, n):
|
|
109
|
+
return message.task_level.parent().level.append(n)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
_end_action_fields = one_of(
|
|
113
|
+
just({ACTION_STATUS_FIELD: SUCCEEDED_STATUS}),
|
|
114
|
+
fixed_dictionaries(
|
|
115
|
+
{
|
|
116
|
+
ACTION_STATUS_FIELD: just(FAILED_STATUS),
|
|
117
|
+
# Text generation is slow. We can make it faster by not generating so
|
|
118
|
+
# much. Thqese are reasonable values.
|
|
119
|
+
EXCEPTION_FIELD: labels,
|
|
120
|
+
REASON_FIELD: labels,
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _make_written_action(start_message, child_messages, end_message_dict):
|
|
127
|
+
"""
|
|
128
|
+
Helper for creating arbitrary L{WrittenAction}s.
|
|
129
|
+
|
|
130
|
+
The child messages and end message (if provided) will be updated to have
|
|
131
|
+
the same C{task_uuid} as C{start_message}. Likewise, their C{task_level}s
|
|
132
|
+
will be such that they follow on from C{start_message}.
|
|
133
|
+
|
|
134
|
+
@param WrittenMessage start_message: The message to start the action with.
|
|
135
|
+
@param child_messages: A sequence of L{WrittenAction}s and
|
|
136
|
+
L{WrittenMessage}s that make up the action.
|
|
137
|
+
@param (PMap | None) end_message_dict: A dictionary that makes up an end
|
|
138
|
+
message. If None, then the action is unfinished.
|
|
139
|
+
|
|
140
|
+
@return: A L{WrittenAction}
|
|
141
|
+
"""
|
|
142
|
+
task_uuid = start_message.task_uuid
|
|
143
|
+
children = []
|
|
144
|
+
|
|
145
|
+
for i, child in enumerate(child_messages, 2):
|
|
146
|
+
task_level = TaskLevel(level=sibling_task_level(start_message, i))
|
|
147
|
+
children.append(reparent_action(task_uuid, task_level, child))
|
|
148
|
+
|
|
149
|
+
if end_message_dict:
|
|
150
|
+
end_message = written_from_pmap(
|
|
151
|
+
union(
|
|
152
|
+
end_message_dict,
|
|
153
|
+
{
|
|
154
|
+
ACTION_TYPE_FIELD: start_message.contents[ACTION_TYPE_FIELD],
|
|
155
|
+
TASK_UUID_FIELD: task_uuid,
|
|
156
|
+
TASK_LEVEL_FIELD: sibling_task_level(
|
|
157
|
+
start_message, 2 + len(children)
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
else:
|
|
163
|
+
end_message = None
|
|
164
|
+
|
|
165
|
+
return WrittenAction.from_messages(start_message, children, end_message)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
written_actions = recursive(
|
|
169
|
+
written_messages,
|
|
170
|
+
lambda children: builds(
|
|
171
|
+
_make_written_action,
|
|
172
|
+
start_message=start_action_messages,
|
|
173
|
+
child_messages=lists(children, max_size=5),
|
|
174
|
+
end_message_dict=builds(union, message_dicts, _end_action_fields) | none(),
|
|
175
|
+
),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _map_messages(f, written_action):
|
|
180
|
+
"""
|
|
181
|
+
Map C{f} across all of the messages that make up C{written_action}.
|
|
182
|
+
|
|
183
|
+
This is a structure-preserving map operation. C{f} will be applied to all
|
|
184
|
+
messages that make up C{written_action}: the start message, end message,
|
|
185
|
+
and children. If any of the children are themselves L{WrittenAction}s, we
|
|
186
|
+
recurse down into them.
|
|
187
|
+
|
|
188
|
+
@param f: A function that takes a L{WrittenMessage} and returns a new
|
|
189
|
+
L{WrittenMessage}.
|
|
190
|
+
@param (WrittenAction | WrittenMessage) written_action: A written
|
|
191
|
+
|
|
192
|
+
@return: A L{WrittenMessage} if C{written_action} is a C{WrittenMessage},
|
|
193
|
+
a L{WrittenAction} otherwise.
|
|
194
|
+
"""
|
|
195
|
+
if isinstance(written_action, WrittenMessage):
|
|
196
|
+
return f(written_action)
|
|
197
|
+
|
|
198
|
+
start_message = f(written_action.start_message)
|
|
199
|
+
children = written_action.children.transform([ny], partial(_map_messages, f))
|
|
200
|
+
if written_action.end_message:
|
|
201
|
+
end_message = f(written_action.end_message)
|
|
202
|
+
else:
|
|
203
|
+
end_message = None
|
|
204
|
+
|
|
205
|
+
return WrittenAction.from_messages(
|
|
206
|
+
start_message=start_message, children=pvector(children), end_message=end_message
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def reparent_action(task_uuid, task_level, written_action):
|
|
211
|
+
"""
|
|
212
|
+
Return a version of C{written_action} that has the given C{task_uuid} and
|
|
213
|
+
is rooted at the given C{task_level}.
|
|
214
|
+
|
|
215
|
+
@param UUID task_uuid: The new task UUID.
|
|
216
|
+
@param TaskLevel task_level: The new task level.
|
|
217
|
+
@param (WrittenAction | WrittenMessage) written_action: The action or
|
|
218
|
+
message to update.
|
|
219
|
+
|
|
220
|
+
@return: A new version of C{written_action}.
|
|
221
|
+
"""
|
|
222
|
+
new_prefix = list(task_level.level)
|
|
223
|
+
old_prefix_len = len(written_action.task_level.level)
|
|
224
|
+
|
|
225
|
+
def fix_message(message):
|
|
226
|
+
return message.transform(
|
|
227
|
+
["_logged_dict", TASK_LEVEL_FIELD],
|
|
228
|
+
lambda level: new_prefix + level[old_prefix_len:],
|
|
229
|
+
).transform(["_logged_dict", TASK_UUID_FIELD], task_uuid)
|
|
230
|
+
|
|
231
|
+
return _map_messages(fix_message, written_action)
|