示例#1
0
    def test_object_copy_includes_its_side_effects(self):
        se = SideEffect([self.alist], [])
        self.call.add_side_effect(se)
        put_on_timeline(self.alist, se, self.call)

        timeline = assertions_for_interaction(self.call)

        alists = all_of_type(timeline, SequenceObject)
        assert_length(alists, 2)
        assert alists[0] is not alists[1]

        side_effects = all_of_type(timeline, SideEffect)
        side_effect = assert_one_element_and_return(side_effects)
        assert alists[1] in side_effect.affected_objects
示例#2
0
def remove_objects_unworthy_of_naming(events):
    new_events = list(events)
    side_effects = all_of_type(events, SideEffect)
    affected_objects = objects_affected_by_side_effects(side_effects)
    invoked_objects = objects_with_method_calls(events) + objects_with_attribute_references(events)
    for obj, usage_count in object_usage_counts(events):
        # ImmutableObjects don't need to be named, as their identity is
        # always unambiguous.
        if not isinstance(obj, ImmutableObject):
            # Anything mentioned more than once have to be named.
            if usage_count > 1:
                continue
            # Anything affected by side effects is also worth naming.
            if obj in affected_objects:
                continue
            # All user objects with method calls should also get names for
            # readability.
            if obj in invoked_objects:
                continue
        try:
            while True:
                new_events.remove(obj)
        except ValueError:
            pass # If the element wasn't on the timeline, even better.
    return new_events
示例#3
0
def function_code_from_definition(definition):
    """Return a code object of a given function definition.

    Can raise SyntaxError if the definition is not valid.
    """
    consts = compile_without_warnings(unindent(str(definition))).co_consts
    return all_of_type(consts, types.CodeType)[0]
示例#4
0
    def test_assertion_gets_timestamp_075_higher_than_the_last_call_action(
            self):
        se = SideEffect([self.alist], [])
        self.call.add_side_effect(se)
        put_on_timeline(self.call, self.alist, se)

        assertion_lines = all_of_type(assertions_for_interaction(self.call),
                                      Line)
        assertion = assert_one_element_and_return(assertion_lines)
        assert_equal(se.timestamp + 0.75, assertion.timestamp)
示例#5
0
    def test_returns_one_assertion_if_output_object_didnt_exist_before_the_call(
            self):
        put_on_timeline(self.call, self.alist)

        assertion_lines = all_of_type(assertions_for_interaction(self.call),
                                      Line)
        assertion = assert_one_element_and_return(assertion_lines)
        assert_is_equal_assertion_line(assertion,
                                       expected_a_copy=True,
                                       expected=self.call.output,
                                       actual=self.call)
        assert assertion.timestamp > self.call.timestamp
示例#6
0
    def test_returns_two_assertions_if_output_object_existed_before_the_call(
            self):
        put_on_timeline(self.alist, self.call)

        assertion_lines = all_of_type(assertions_for_interaction(self.call),
                                      Line)
        assert_length(assertion_lines, 2)

        assert_is_equal_assertion_line(assertion_lines[0],
                                       expected=self.call.output,
                                       actual=self.call)
        assert_is_equal_assertion_line(assertion_lines[1],
                                       expected_a_copy=True,
                                       expected=self.call.output,
                                       actual=self.call.output)
        assert assertion_lines[0].timestamp < assertion_lines[1].timestamp
示例#7
0
 def _get_test_classes(self):
     return all_of_type(self.objects, TestClass)
示例#8
0
 def _get_functions(self):
     return all_of_type(self.objects, Function)
示例#9
0
 def find_object(self, type, name):
     for obj in all_of_type(self.objects, type):
         if obj.name == name:
             return obj
示例#10
0
def side_effects_that_affect_object(events, obj):
    "Filter out side effects that are irrelevant to given object."
    for side_effect in all_of_type(events, SideEffect):
        if obj in side_effect.affected_objects:
            yield side_effect
示例#11
0
 def iter_captured_generator_objects(self):
     return all_of_type(self.captured_objects.values(), GeneratorObject)
示例#12
0
def objects_only(events):
    return all_of_type(events, SerializedObject)
示例#13
0
 def get_those_and_contained_objects(objs):
     return all_of_type(objs,
                        SerializedObject) + get_contained_objects(objs)