Author: Antonio Cuni <[email protected]>
Branch: gc-disable
Changeset: r94632:c892bfb192d6
Date: 2018-05-18 18:35 +0200
http://bitbucket.org/pypy/pypy/changeset/c892bfb192d6/
Log: introduce the debuglog fixture, so that tests can easily capture the
content of debug_{start,stop,print}
diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -37,6 +37,10 @@
assert False, ("nesting error: no start corresponding to stop %r" %
(category,))
+ def reset(self):
+ # only for tests: empty the log
+ self[:] = []
+
def __repr__(self):
import pprint
return pprint.pformat(list(self))
diff --git a/rpython/rlib/test/test_debug.py b/rpython/rlib/test/test_debug.py
--- a/rpython/rlib/test/test_debug.py
+++ b/rpython/rlib/test/test_debug.py
@@ -1,5 +1,5 @@
-
import py
+import pytest
from rpython.rlib.debug import (check_annotation, make_sure_not_resized,
debug_print, debug_start, debug_stop,
have_debug_prints, debug_offset, debug_flush,
@@ -10,6 +10,12 @@
from rpython.rlib import debug
from rpython.rtyper.test.test_llinterp import interpret, gengraph
[email protected]
+def debuglog(monkeypatch):
+ dlog = debug.DebugLog()
+ monkeypatch.setattr(debug, '_log', dlog)
+ return dlog
+
def test_check_annotation():
class Error(Exception):
pass
@@ -94,7 +100,7 @@
py.test.raises(NotAListOfChars, "interpret(g, [3])")
-def test_debug_print_start_stop():
+def test_debug_print_start_stop(debuglog):
def f(x):
debug_start("mycat")
debug_print("foo", 2, "bar", x)
@@ -103,21 +109,14 @@
debug_offset() # should not explode at least
return have_debug_prints()
- try:
- debug._log = dlog = debug.DebugLog()
- res = f(3)
- assert res is True
- finally:
- debug._log = None
- assert dlog == [("mycat", [('debug_print', 'foo', 2, 'bar', 3)])]
+ res = f(3)
+ assert res is True
+ assert debuglog == [("mycat", [('debug_print', 'foo', 2, 'bar', 3)])]
+ debuglog.reset()
- try:
- debug._log = dlog = debug.DebugLog()
- res = interpret(f, [3])
- assert res is True
- finally:
- debug._log = None
- assert dlog == [("mycat", [('debug_print', 'foo', 2, 'bar', 3)])]
+ res = interpret(f, [3])
+ assert res is True
+ assert debuglog == [("mycat", [('debug_print', 'foo', 2, 'bar', 3)])]
def test_debug_start_stop_timestamp():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit