Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/extmod: Add btree test for errors raised by btree DB library.
This test now passes given the previous two commits.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
OSError True | ||
read 24 | ||
OSError(1000,) | ||
read 24 | ||
ioctl 2 | ||
OSError(1001,) |