def test_timeline_for_user_object(execution_events, user_object): """Construct a new timeline for a test case based on real execution timeline and a user object that needs to be tested. The new timeline in most cases will contain assertions. """ init_call = user_object.get_init_call() external_calls = testable_calls(user_object.get_external_calls()) # If the constructor raised an exception, object creation should be an assertion. if init_call and init_call.raised_exception(): call_return_timestamp = last_call_action_timestamp(init_call) return [ RaisesAssertionLine(init_call.exception, MethodCallContext(init_call, user_object), call_return_timestamp + 0.25) ] timeline = give_context_to_method_calls( compact([init_call]) + flatten([ test_timeline_for_call(execution_events, call) for call in external_calls ]), user_object) if init_call and len(external_calls) == 0: timeline.append( CommentLine("# Make sure it doesn't raise any exceptions.", timeline[-1].timestamp)) return timeline
def test_timeline_for_user_object(execution_events, user_object): """Construct a new timeline for a test case based on real execution timeline and a user object that needs to be tested. The new timeline in most cases will contain assertions. """ init_call = user_object.get_init_call() external_calls = testable_calls(user_object.get_external_calls()) # If the constructor raised an exception, object creation should be an assertion. if init_call and init_call.raised_exception(): call_return_timestamp = last_call_action_timestamp(init_call) return [ RaisesAssertionLine( init_call.exception, MethodCallContext(init_call, user_object), call_return_timestamp + 0.25 ) ] timeline = give_context_to_method_calls( compact([init_call]) + flatten(map(lambda call: test_timeline_for_call(execution_events, call), external_calls)), user_object, ) if init_call and len(external_calls) == 0: timeline.append(CommentLine("# Make sure it doesn't raise any exceptions.", timeline[-1].timestamp)) return timeline
def objects_with_attribute_references(events): def objects_from_references(event): if isinstance(event, ObjectAttributeReference): return event.obj elif isinstance(event, EqualAssertionLine): return objects_from_references(event.actual) elif isinstance(event, RaisesAssertionLine): return objects_from_references(event.call) elif isinstance(event, GeneratorAssertionLine): return objects_from_references(event.generator_call) else: return None return compact(list(map(objects_from_references, events)))
def objects_with_method_calls(events): def objects_from_methods(event): if isinstance(event, MethodCallContext): return event.user_object elif isinstance(event, EqualAssertionLine): return objects_from_methods(event.actual) elif isinstance(event, RaisesAssertionLine): return objects_from_methods(event.call) elif isinstance(event, GeneratorAssertionLine): return objects_from_methods(event.generator_call) else: return None return compact(list(map(objects_from_methods, events)))
def objects_with_attribute_references(events): def objects_from_references(event): if isinstance(event, ObjectAttributeReference): return event.obj elif isinstance(event, EqualAssertionLine): return objects_from_references(event.actual) elif isinstance(event, RaisesAssertionLine): return objects_from_references(event.call) elif isinstance(event, GeneratorAssertionLine): return objects_from_references(event.generator_call) else: return None return compact(map(objects_from_references, events))
def objects_with_method_calls(events): def objects_from_methods(event): if isinstance(event, MethodCallContext): return event.user_object elif isinstance(event, EqualAssertionLine): return objects_from_methods(event.actual) elif isinstance(event, RaisesAssertionLine): return objects_from_methods(event.call) elif isinstance(event, GeneratorAssertionLine): return objects_from_methods(event.generator_call) else: return None return compact(map(objects_from_methods, events))
def input_from_argvalues(args, varargs, varkw, locals): return dict(resolve_args(args + compact([varargs, varkw]), locals))