Exemplo n.º 1
0
def test_trace_exception(parse, tmplog):
    @ud.trace(with_args=False)
    def f():
        raise ValueError(42)

    ud.set_function(ud.FUNCTION)
    with pytest.raises(ValueError):
        f()
    ud.exit()

    output = tmplog.read()
    for ((c_type, c_groups),
         (e_type, e_groups)) in zip(parse(output), [
             ('init', {}),
             ('begin', {
                 'begin': 'test_debug2.f(...): ...'
             }),
             ('end', {
                 'end': "test_debug2.f(...): %r(42)" % ValueError
             }),
             ('exit', {}),
         ]):
        assert c_type == e_type
        for key, val in e_groups.items():
            assert c_groups[key] == val
Exemplo n.º 2
0
def test_function(function, expected, parse, tmplog):
	def f():
		_d = ud.function('f')  # noqa: F841
		_d

	ud.set_function(function)
	f()
	ud.exit()

	output = tmplog.read()
	assert [typ for typ, groups in parse(output)] == expected
Exemplo n.º 3
0
def test_trace_detail(parse, tmplog):
	@ud.trace(with_args=True, with_return=True, repr=repr)
	def f(args):
		return 42

	ud.set_function(ud.FUNCTION)
	assert f('in') == 42
	ud.exit()

	output = tmplog.read()
	for ((c_type, c_groups), (e_type, e_groups)) in zip(parse(output), [
		('init', {}),
		('begin', {'begin': "test_debug2.f('in'): ..."}),
		('end', {'end': 'test_debug2.f(...): 42'}),
		('exit', {}),
	]):
		assert c_type == e_type
		for key, val in e_groups.items():
			assert c_groups[key] == val
Exemplo n.º 4
0
def test_trace_plain(parse, tmplog):
	@ud.trace(with_args=False)
	def f():
		pass

	ud.set_function(ud.FUNCTION)
	assert f() is None
	ud.exit()

	output = tmplog.read()
	for ((c_type, c_groups), (e_type, e_groups)) in zip(parse(output), [
		('init', {}),
		('begin', {'begin': 'test_debug2.f(...): ...'}),
		('end', {'end': 'test_debug2.f(...): ...'}),
		('exit', {}),
	]):
		assert c_type == e_type
		for key, val in e_groups.items():
			assert c_groups[key] == val