2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
import py
|
|
|
|
import marshal
|
|
|
|
|
|
|
|
class TestRaises:
|
|
|
|
def test_raises(self):
|
|
|
|
py.test.raises(ValueError, "int('qwe')")
|
|
|
|
|
|
|
|
def test_raises_exec(self):
|
|
|
|
py.test.raises(ValueError, "a,x = []")
|
|
|
|
|
|
|
|
def test_raises_syntax_error(self):
|
|
|
|
py.test.raises(SyntaxError, "qwe qwe qwe")
|
|
|
|
|
|
|
|
def test_raises_function(self):
|
|
|
|
py.test.raises(ValueError, int, 'hello')
|
|
|
|
|
2008-09-21 23:15:28 +08:00
|
|
|
def test_importorskip():
|
2009-03-01 19:24:52 +08:00
|
|
|
from py.__.test.outcome import Skipped
|
2008-09-21 20:50:56 +08:00
|
|
|
try:
|
2008-09-21 23:15:28 +08:00
|
|
|
sys = py.test.importorskip("sys")
|
|
|
|
assert sys == py.std.sys
|
|
|
|
#path = py.test.importorskip("os.path")
|
|
|
|
#assert path == py.std.os.path
|
|
|
|
py.test.raises(Skipped, "py.test.importorskip('alskdj')")
|
|
|
|
py.test.raises(SyntaxError, "py.test.importorskip('x y z')")
|
|
|
|
py.test.raises(SyntaxError, "py.test.importorskip('x=y')")
|
|
|
|
path = py.test.importorskip("py", minversion=".".join(py.__version__))
|
2009-07-09 19:13:31 +08:00
|
|
|
mod = py.std.new.module("hello123")
|
|
|
|
mod.__version__ = "1.3"
|
2008-09-21 23:15:28 +08:00
|
|
|
py.test.raises(Skipped, """
|
2009-07-09 19:13:31 +08:00
|
|
|
py.test.importorskip("hello123", minversion="5.0")
|
2008-09-21 23:15:28 +08:00
|
|
|
""")
|
2008-09-21 20:50:56 +08:00
|
|
|
except Skipped:
|
2008-09-21 23:15:28 +08:00
|
|
|
print py.code.ExceptionInfo()
|
|
|
|
py.test.fail("spurious skip")
|
2008-09-21 20:50:56 +08:00
|
|
|
|
2009-05-22 19:01:48 +08:00
|
|
|
def test_pytest_exit():
|
|
|
|
try:
|
|
|
|
py.test.exit("hello")
|
|
|
|
except:
|
|
|
|
excinfo = py.code.ExceptionInfo()
|
|
|
|
assert excinfo.errisinstance(KeyboardInterrupt)
|
|
|
|
|