2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
import py
|
|
|
|
|
|
|
|
import errno
|
|
|
|
|
|
|
|
def test_error_classes():
|
|
|
|
for name in errno.errorcode.values():
|
|
|
|
x = getattr(py.error, name)
|
|
|
|
assert issubclass(x, py.error.Error)
|
|
|
|
assert issubclass(x, EnvironmentError)
|
|
|
|
|
2010-07-27 03:15:15 +08:00
|
|
|
def test_unknown_error():
|
2008-08-16 23:26:59 +08:00
|
|
|
num = 3999
|
|
|
|
cls = py.error._geterrnoclass(num)
|
2010-07-27 03:15:15 +08:00
|
|
|
assert cls.__name__ == 'UnknownErrno%d' % (num,)
|
2008-08-16 23:26:59 +08:00
|
|
|
assert issubclass(cls, py.error.Error)
|
|
|
|
assert issubclass(cls, EnvironmentError)
|
|
|
|
cls2 = py.error._geterrnoclass(num)
|
|
|
|
assert cls is cls2
|
|
|
|
|
2009-08-25 15:38:19 +08:00
|
|
|
def test_error_conversion_ENOTDIR(testdir):
|
|
|
|
p = testdir.makepyfile("")
|
|
|
|
excinfo = py.test.raises(py.error.Error, py.error.checked_call, p.listdir)
|
|
|
|
assert isinstance(excinfo.value, EnvironmentError)
|
|
|
|
assert isinstance(excinfo.value, py.error.Error)
|
2010-07-27 03:15:15 +08:00
|
|
|
assert "ENOTDIR" in repr(excinfo.value)
|
2010-06-03 16:21:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_checked_call_supports_kwargs(tmpdir):
|
|
|
|
import tempfile
|
|
|
|
py.error.checked_call(tempfile.mkdtemp, dir=str(tmpdir))
|