tests/extmod: Add btree test for errors raised by btree DB library.
This test now passes given the previous two commits.
This commit is contained in:
parent
bd6ca15444
commit
4fa6d939d6
42
tests/extmod/btree_error.py
Normal file
42
tests/extmod/btree_error.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Test that errno's propagate correctly through btree module.
|
||||||
|
|
||||||
|
try:
|
||||||
|
import btree, uio, uerrno
|
||||||
|
|
||||||
|
uio.IOBase
|
||||||
|
except (ImportError, AttributeError):
|
||||||
|
print("SKIP")
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
|
class Device(uio.IOBase):
|
||||||
|
def __init__(self, read_ret=0, ioctl_ret=0):
|
||||||
|
self.read_ret = read_ret
|
||||||
|
self.ioctl_ret = ioctl_ret
|
||||||
|
|
||||||
|
def readinto(self, buf):
|
||||||
|
print("read", len(buf))
|
||||||
|
return self.read_ret
|
||||||
|
|
||||||
|
def ioctl(self, cmd, arg):
|
||||||
|
print("ioctl", cmd)
|
||||||
|
return self.ioctl_ret
|
||||||
|
|
||||||
|
|
||||||
|
# Invalid pagesize; errno comes from btree library
|
||||||
|
try:
|
||||||
|
db = btree.open(Device(), pagesize=511)
|
||||||
|
except OSError as er:
|
||||||
|
print("OSError", er.args[0] == uerrno.EINVAL)
|
||||||
|
|
||||||
|
# Valid pagesize, device returns error on read; errno comes from Device.readinto
|
||||||
|
try:
|
||||||
|
db = btree.open(Device(-1000), pagesize=512)
|
||||||
|
except OSError as er:
|
||||||
|
print(repr(er))
|
||||||
|
|
||||||
|
# Valid pagesize, device returns error on seek; errno comes from Device.ioctl
|
||||||
|
try:
|
||||||
|
db = btree.open(Device(0, -1001), pagesize=512)
|
||||||
|
except OSError as er:
|
||||||
|
print(repr(er))
|
6
tests/extmod/btree_error.py.exp
Normal file
6
tests/extmod/btree_error.py.exp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
OSError True
|
||||||
|
read 24
|
||||||
|
OSError(1000,)
|
||||||
|
read 24
|
||||||
|
ioctl 2
|
||||||
|
OSError(1001,)
|
Loading…
x
Reference in New Issue
Block a user