Skip to content

Commit

Permalink
Lower case is best case
Browse files Browse the repository at this point in the history
  • Loading branch information
jml committed Sep 3, 2015
1 parent 24c74ca commit d1dea56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
44 changes: 22 additions & 22 deletions eliot/tests/strategies.py
Expand Up @@ -32,30 +32,30 @@



TASK_LEVEL_INDEXES = integers(min_value=1)
task_level_indexes = integers(min_value=1)
# Task levels can be arbitrarily deep, but in the wild rarely as much as 100.
# Five seems a sensible average.
TASK_LEVEL_LISTS = lists(TASK_LEVEL_INDEXES, min_size=1, average_size=5)
TASK_LEVELS = TASK_LEVEL_LISTS.map(lambda level: TaskLevel(level=level))
task_level_lists = lists(task_level_indexes, min_size=1, average_size=5)
task_levels = task_level_lists.map(lambda level: TaskLevel(level=level))


# Text generation is slow, and most of the things are short labels.
LABELS = text(average_size=5)
labels = text(average_size=5)

TIMESTAMPS = floats(min_value=0)
timestamps = floats(min_value=0)

UUIDS = basic(generate=lambda r, _: UUID(int=r.getrandbits(128)))
uuids = basic(generate=lambda r, _: UUID(int=r.getrandbits(128)))

MESSAGE_CORE_DICTS = fixed_dictionaries(
dict(task_level=TASK_LEVEL_LISTS.map(pvector),
task_uuid=UUIDS,
timestamp=TIMESTAMPS)).map(pmap)
message_core_dicts = fixed_dictionaries(
dict(task_level=task_level_lists.map(pvector),
task_uuid=uuids,
timestamp=timestamps)).map(pmap)


# Text generation is slow. We can make it faster by not generating so
# much. These are reasonable values.
MESSAGE_DATA_DICTS = dictionaries(
keys=LABELS, values=text(average_size=10),
message_data_dicts = dictionaries(
keys=labels, values=text(average_size=10),
# People don't normally put much more than twenty fields in their
# messages, surely?
average_size=10,
Expand All @@ -77,17 +77,17 @@ def union(*dicts):
return result.persistent()


MESSAGE_DICTS = builds(union, MESSAGE_DATA_DICTS, MESSAGE_CORE_DICTS)
WRITTEN_MESSAGES = MESSAGE_DICTS.map(WrittenMessage.from_dict)
message_dicts = builds(union, message_data_dicts, message_core_dicts)
written_messages = message_dicts.map(WrittenMessage.from_dict)

_start_action_fields = fixed_dictionaries(
{ ACTION_STATUS_FIELD: just(STARTED_STATUS),
ACTION_TYPE_FIELD: LABELS,
ACTION_TYPE_FIELD: labels,
})
START_ACTION_MESSAGE_DICTS = builds(
union, MESSAGE_DICTS, _start_action_fields).map(
start_action_message_dicts = builds(
union, message_dicts, _start_action_fields).map(
lambda x: x.update({TASK_LEVEL_FIELD: x[TASK_LEVEL_FIELD].set(-1, 1)}))
START_ACTION_MESSAGES = START_ACTION_MESSAGE_DICTS.map(WrittenMessage.from_dict)
start_action_messages = start_action_message_dicts.map(WrittenMessage.from_dict)


def sibling_task_level(message, n):
Expand Down Expand Up @@ -144,14 +144,14 @@ def _make_written_action(start_message, child_messages, end_message_dict):
return WrittenAction.from_messages(start_message, children, end_message)


WRITTEN_ACTIONS = recursive(
WRITTEN_MESSAGES,
written_actions = recursive(
written_messages,
lambda children: builds(
_make_written_action,
start_message=START_ACTION_MESSAGES,
start_message=start_action_messages,
child_messages=lists(children, average_size=5),
end_message_dict=builds(
union, MESSAGE_DICTS, _end_action_fields) | none(),
union, message_dicts, _end_action_fields) | none(),
),
)

Expand Down
48 changes: 24 additions & 24 deletions eliot/tests/test_action.py
Expand Up @@ -35,13 +35,13 @@
from .. import _action, add_destination, remove_destination

from .strategies import (
MESSAGE_DICTS,
START_ACTION_MESSAGE_DICTS,
START_ACTION_MESSAGES,
TASK_LEVEL_INDEXES,
TASK_LEVEL_LISTS,
WRITTEN_ACTIONS,
WRITTEN_MESSAGES,
message_dicts,
start_action_message_dicts,
start_action_messages,
task_level_indexes,
task_level_lists,
written_actions,
written_messages,
reparent_action,
sibling_task_level,
union,
Expand Down Expand Up @@ -853,7 +853,7 @@ def assert_fully_less_than(self, x, y):
]))


@given(lists(TASK_LEVEL_INDEXES))
@given(lists(task_level_indexes))
def test_parent_of_child(self, base_task_level):
"""
L{TaskLevel.child} returns the first child of the task.
Expand All @@ -863,7 +863,7 @@ def test_parent_of_child(self, base_task_level):
self.assertEqual(base_task, child_task.parent())


@given(TASK_LEVEL_LISTS)
@given(task_level_lists)
def test_child_greater_than_parent(self, task_level):
"""
L{TaskLevel.child} returns a child that is greater than its parent.
Expand All @@ -872,7 +872,7 @@ def test_child_greater_than_parent(self, task_level):
self.assert_fully_less_than(task, task.child())


@given(TASK_LEVEL_LISTS)
@given(task_level_lists)
def test_next_sibling_greater(self, task_level):
"""
L{TaskLevel.next_sibling} returns a greater task level.
Expand All @@ -881,7 +881,7 @@ def test_next_sibling_greater(self, task_level):
self.assert_fully_less_than(task, task.next_sibling())


@given(TASK_LEVEL_LISTS)
@given(task_level_lists)
def test_next_sibling(self, task_level):
"""
L{TaskLevel.next_sibling} returns the next sibling of a task.
Expand Down Expand Up @@ -937,7 +937,7 @@ class WrittenActionTests(testtools.TestCase):
Tests for L{WrittenAction}.
"""

@given(START_ACTION_MESSAGES)
@given(start_action_messages)
def test_from_single_message(self, message):
"""
A L{WrittenAction} can be constructed from a single "start" message. Such
Expand All @@ -958,7 +958,7 @@ def test_from_single_message(self, message):
exception=None,
))

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, integers(min_value=2))
@given(start_action_messages, message_dicts, integers(min_value=2))
def test_different_task_uuid(self, start_message, end_message_dict, n):
"""
By definition, an action is either a top-level task or takes place within
Expand All @@ -975,7 +975,7 @@ def test_different_task_uuid(self, start_message, end_message_dict, n):
WrongTask,
WrittenAction.from_messages, start_message, end_message=end_message)

@given(MESSAGE_DICTS)
@given(message_dicts)
def test_invalid_start_message_missing_status(self, message_dict):
"""
A start message must have an C{ACTION_STATUS_FIELD} with the value
Expand All @@ -989,7 +989,7 @@ def test_invalid_start_message_missing_status(self, message_dict):
self.assertRaises(
InvalidStartMessage, WrittenAction.from_messages, message)

@given(message_dict=START_ACTION_MESSAGE_DICTS,
@given(message_dict=start_action_message_dicts,
status=(just(FAILED_STATUS) | just(SUCCEEDED_STATUS) | text()))
def test_invalid_start_message_wrong_status(self, message_dict, status):
"""
Expand All @@ -1005,7 +1005,7 @@ def test_invalid_start_message_wrong_status(self, message_dict, status):
self.assertRaises(
InvalidStartMessage, WrittenAction.from_messages, message)

@given(START_ACTION_MESSAGE_DICTS, integers(min_value=2))
@given(start_action_message_dicts, integers(min_value=2))
def test_invalid_task_level_in_start_message(self, start_message_dict, i):
"""
All messages in an action have a task level. The first message in an
Expand All @@ -1021,7 +1021,7 @@ def test_invalid_task_level_in_start_message(self, start_message_dict, i):
self.assertRaises(
InvalidStartMessage, WrittenAction.from_messages, message)

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, text(), integers(min_value=1))
@given(start_action_messages, message_dicts, text(), integers(min_value=1))
def test_action_type_mismatch(self, start_message, end_message_dict,
end_type, n):
"""
Expand All @@ -1040,7 +1040,7 @@ def test_action_type_mismatch(self, start_message, end_message_dict,
WrongActionType,
WrittenAction.from_messages, start_message, end_message=end_message)

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, integers(min_value=2))
@given(start_action_messages, message_dicts, integers(min_value=2))
def test_successful_end(self, start_message, end_message_dict, n):
"""
A L{WrittenAction} can be constructed with just a start message and an end
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def test_successful_end(self, start_message, end_message_dict, n):
exception=None,
))

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, text(), text(),
@given(start_action_messages, message_dicts, text(), text(),
integers(min_value=2))
def test_failed_end(self, start_message, end_message_dict, exception,
reason, n):
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def test_failed_end(self, start_message, end_message_dict, exception,
exception=exception,
))

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, integers(min_value=2))
@given(start_action_messages, message_dicts, integers(min_value=2))
def test_end_has_no_status(self, start_message, end_message_dict, n):
"""
If we try to end a L{WrittenAction} with a message that lacks an
Expand All @@ -1131,7 +1131,7 @@ def test_end_has_no_status(self, start_message, end_message_dict, n):

# This test is slow, and when run under coverage on pypy on Travis won't
# make the default of 5 examples. 1 is enough.
@given(START_ACTION_MESSAGES, lists(WRITTEN_MESSAGES | WRITTEN_ACTIONS),
@given(start_action_messages, lists(written_messages | written_actions),
settings=Settings(min_satisfying_examples=1))
def test_children(self, start_message, child_messages):
"""
Expand All @@ -1150,7 +1150,7 @@ def test_children(self, start_message, child_messages):
self.assertEqual(
sorted(set(messages), key=task_level), action.children)

@given(START_ACTION_MESSAGES, MESSAGE_DICTS)
@given(start_action_messages, message_dicts)
def test_wrong_task_uuid(self, start_message, child_message):
"""
All child messages of an action must have the same C{task_uuid} as the
Expand All @@ -1162,7 +1162,7 @@ def test_wrong_task_uuid(self, start_message, child_message):
WrongTask,
WrittenAction.from_messages, start_message, v(message))

@given(START_ACTION_MESSAGES, MESSAGE_DICTS)
@given(start_action_messages, message_dicts)
def test_wrong_task_level(self, start_message, child_message):
"""
All child messages of an action must have a task level that is a direct
Expand All @@ -1176,7 +1176,7 @@ def test_wrong_task_level(self, start_message, child_message):
WrongTaskLevel,
WrittenAction.from_messages, start_message, v(message))

@given(START_ACTION_MESSAGES, MESSAGE_DICTS, MESSAGE_DICTS, integers(min_value=2))
@given(start_action_messages, message_dicts, message_dicts, integers(min_value=2))
def test_duplicate_task_level(self, start_message, child1, child2, index):
"""
If we try to add a child to an action that has a task level that's the
Expand Down

0 comments on commit d1dea56

Please sign in to comment.