Пример #1
0
 def test_dispatch(self):
     for line, sequence in TestDispatch.cases.items():
         argv = line.split()
         args = todo.parse_args(argv)
         calls = []
         handler = get_trace_handler(calls)
         sys.settrace(handler)
         todo.dispatch(args, TestDispatch.todolist)
         sys.settrace(None)
         calls = calls[1:]
         for (name, args), (e_name, e_args) in zip(sequence, calls):
             self.assertEqual(name, e_name)
             for arg_name, arg_value in args.items():
                 self.assertIn(arg_name, e_args)
                 self.assertEqual(arg_value, e_args[arg_name])
Пример #2
0
 def test_dispatch(self):
     for line, sequence in TestDispatch.cases.items():
         argv = line.split()
         args = todo.parse_args(argv)
         calls = []
         handler = get_trace_handler(calls)
         sys.settrace(handler)
         todo.dispatch(args, TestDispatch.todolist)
         sys.settrace(None)
         calls = calls[1:]
         for (name, args), (e_name, e_args) in zip(sequence, calls):
             self.assertEqual(name, e_name)
             for arg_name, arg_value in args.items():
                 self.assertIn(arg_name, e_args)
                 self.assertEqual(arg_value, e_args[arg_name])
Пример #3
0
            todo.dispatch(args, TestDispatch.todolist)
            sys.settrace(None)
            calls = calls[1:]
            for (name, args), (e_name, e_args) in zip(sequence, calls):
                self.assertEqual(name, e_name)
                for arg_name, arg_value in args.items():
                    self.assertIn(arg_name, e_args)
                    self.assertEqual(arg_value, e_args[arg_name])


def get_trace_handler(list_):
    def handler(frame, event, arg):
        if event != 'call':
            return
        f_name = frame.f_code.co_name
        local = frame.f_locals
        list_.append((f_name, local))

    return handler


if __name__ == '__main__':
    calls = []
    args = todo.parse_args(['-c', 'hello'])
    todolist = todo.TodoList([], {})
    sys.settrace(get_trace_handler(calls))
    todo.dispatch(args, todolist)
    sys.settrace(None)
    for c in calls:
        print(c)
Пример #4
0
			sys.settrace(handler)
			todo.dispatch(args, TestDispatch.todolist)
			sys.settrace(None)
			calls = calls[1:]
			for (name, args), (e_name, e_args) in zip(sequence, calls):
				self.assertEqual(name, e_name)
				for arg_name, arg_value in args.items():
					self.assertIn(arg_name, e_args)
					self.assertEqual(arg_value, e_args[arg_name])


def get_trace_handler(list_):
	def handler(frame, event, arg):
		if event != 'call':
			return
		f_name = frame.f_code.co_name
		local = frame.f_locals
		list_.append((f_name, local))
	return handler


if __name__ == '__main__':
	calls = []
	args = todo.parse_args(['-c', 'hello'])
	todolist = todo.TodoList([], {})
	sys.settrace(get_trace_handler(calls))
	todo.dispatch(args, todolist)
	sys.settrace(None)
	for c in calls:
		print(c)