2020-04-20 13:59:22 +00:00
|
|
|
# Test that errno's propagate correctly through btree module.
|
|
|
|
|
|
|
|
try:
|
2022-08-18 06:57:45 +00:00
|
|
|
import btree, io, errno
|
2020-04-20 13:59:22 +00:00
|
|
|
|
2022-08-18 06:57:45 +00:00
|
|
|
io.IOBase
|
2020-04-20 13:59:22 +00:00
|
|
|
except (ImportError, AttributeError):
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
2022-08-18 06:57:45 +00:00
|
|
|
class Device(io.IOBase):
|
2020-04-20 13:59:22 +00:00
|
|
|
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:
|
2022-08-18 06:57:45 +00:00
|
|
|
import btree, io, errno
|
|
|
|
|
2020-04-20 13:59:22 +00:00
|
|
|
db = btree.open(Device(), pagesize=511)
|
|
|
|
except OSError as er:
|
2022-08-18 06:57:45 +00:00
|
|
|
print("OSError", er.errno == errno.EINVAL)
|
2020-04-20 13:59:22 +00:00
|
|
|
|
|
|
|
# Valid pagesize, device returns error on read; errno comes from Device.readinto
|
|
|
|
try:
|
2022-08-18 06:57:45 +00:00
|
|
|
import btree, io, errno
|
|
|
|
|
2020-04-20 13:59:22 +00:00
|
|
|
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:
|
2022-08-18 06:57:45 +00:00
|
|
|
import btree, io, errno
|
|
|
|
|
2020-04-20 13:59:22 +00:00
|
|
|
db = btree.open(Device(0, -1001), pagesize=512)
|
|
|
|
except OSError as er:
|
|
|
|
print(repr(er))
|