[svn r63913] make py.log.APIWARN available
--HG-- branch : trunk
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import py
|
||||
from py.__.log.warning import WarningPlugin
|
||||
mypath = py.magic.autopath()
|
||||
|
||||
class TestWarningPlugin:
|
||||
def setup_method(self, method):
|
||||
self.pluginmanager = py._com.Registry()
|
||||
self.wb = WarningPlugin(self.pluginmanager)
|
||||
self.pluginmanager.register(self)
|
||||
self.warnings = []
|
||||
|
||||
def pyevent__WARNING(self, warning):
|
||||
self.warnings.append(warning)
|
||||
|
||||
def test_event_generation(self):
|
||||
self.wb.warn("hello")
|
||||
assert len(self.warnings) == 1
|
||||
|
||||
def test_location(self):
|
||||
self.wb.warn("again")
|
||||
warning = self.warnings[0]
|
||||
lno = self.test_location.im_func.func_code.co_firstlineno + 1
|
||||
assert warning.lineno == lno
|
||||
assert warning.path == mypath
|
||||
locstr = "%s:%d: " %(mypath, lno+1,)
|
||||
assert repr(warning).startswith(locstr)
|
||||
assert str(warning) == warning.msg
|
||||
|
||||
def test_stacklevel(self):
|
||||
def f():
|
||||
self.wb.warn("x", stacklevel=2)
|
||||
# 3
|
||||
# 4
|
||||
f()
|
||||
lno = self.test_stacklevel.im_func.func_code.co_firstlineno + 5
|
||||
warning = self.warnings[0]
|
||||
assert warning.lineno == lno
|
||||
|
||||
def test_forwarding_to_warnings_module(self):
|
||||
py.test.deprecated_call(self.wb.warn, "x")
|
||||
|
||||
def test_apiwarn(self):
|
||||
self.wb.apiwarn("3.0", "xxx")
|
||||
warning = self.warnings[0]
|
||||
assert warning.msg == "xxx (since version 3.0)"
|
||||
|
||||
def test_default():
|
||||
assert py._com.comregistry.isregistered(py.log.APIWARN.im_self)
|
||||
Reference in New Issue
Block a user