tests: Use .errno instead of .args[0] for OSError exceptions.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
342d55529d
commit
3123f6918b
@ -65,7 +65,7 @@ print(db.seq(1, b"qux"))
|
||||
try:
|
||||
db.seq(b"foo1")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
print(e.errno == uerrno.EINVAL)
|
||||
|
||||
print(list(db.keys()))
|
||||
print(list(db.values()))
|
||||
|
@ -27,7 +27,7 @@ class Device(uio.IOBase):
|
||||
try:
|
||||
db = btree.open(Device(), pagesize=511)
|
||||
except OSError as er:
|
||||
print("OSError", er.args[0] == uerrno.EINVAL)
|
||||
print("OSError", er.errno == uerrno.EINVAL)
|
||||
|
||||
# Valid pagesize, device returns error on read; errno comes from Device.readinto
|
||||
try:
|
||||
|
@ -33,7 +33,7 @@ poller.unregister(s)
|
||||
try:
|
||||
poller.modify(s, select.POLLIN)
|
||||
except OSError as e:
|
||||
assert e.args[0] == errno.ENOENT
|
||||
assert e.errno == errno.ENOENT
|
||||
|
||||
# poll after closing the socket, should return POLLNVAL
|
||||
poller.register(s)
|
||||
|
@ -14,4 +14,4 @@ s = socket.socket()
|
||||
try:
|
||||
s.recv(1)
|
||||
except OSError as er:
|
||||
print("ENOTCONN:", er.args[0] == errno.ENOTCONN)
|
||||
print("ENOTCONN:", er.errno == errno.ENOTCONN)
|
||||
|
@ -17,4 +17,4 @@ s.settimeout(0)
|
||||
try:
|
||||
s.recv(1)
|
||||
except OSError as er:
|
||||
print("EAGAIN:", er.args[0] == errno.EAGAIN)
|
||||
print("EAGAIN:", er.errno == errno.EAGAIN)
|
||||
|
@ -58,22 +58,22 @@ f.close() # allowed
|
||||
try:
|
||||
f.write("world!")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
print(e.errno == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.read()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
print(e.errno == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
f.flush()
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EINVAL)
|
||||
print(e.errno == uerrno.EINVAL)
|
||||
|
||||
try:
|
||||
open("foo_file.txt", "x")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
print(e.errno == uerrno.EEXIST)
|
||||
|
||||
with open("foo_file.txt", "a") as f:
|
||||
f.write("world!")
|
||||
@ -105,7 +105,7 @@ vfs.mkdir("foo_dir")
|
||||
try:
|
||||
vfs.rmdir("foo_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == 20) # uerrno.ENOTDIR
|
||||
print(e.errno == 20) # uerrno.ENOTDIR
|
||||
|
||||
vfs.remove("foo_file.txt")
|
||||
print(list(vfs.ilistdir()))
|
||||
|
@ -51,22 +51,22 @@ uos.chdir("/ramdisk")
|
||||
try:
|
||||
vfs.mkdir("foo_dir")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EEXIST)
|
||||
print(e.errno == uerrno.EEXIST)
|
||||
|
||||
try:
|
||||
vfs.remove("foo_dir")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EISDIR)
|
||||
print(e.errno == uerrno.EISDIR)
|
||||
|
||||
try:
|
||||
vfs.remove("no_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.ENOENT)
|
||||
print(e.errno == uerrno.ENOENT)
|
||||
|
||||
try:
|
||||
vfs.rename("foo_dir", "/null/file")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.ENOENT)
|
||||
print(e.errno == uerrno.ENOENT)
|
||||
|
||||
# file in dir
|
||||
with open("foo_dir/file-in-dir.txt", "w+t") as f:
|
||||
@ -82,7 +82,7 @@ with open("foo_dir/sub_file.txt", "w") as f:
|
||||
try:
|
||||
vfs.rmdir("foo_dir")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.EACCES)
|
||||
print(e.errno == uerrno.EACCES)
|
||||
|
||||
# trim full path
|
||||
vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
|
||||
@ -111,5 +111,5 @@ try:
|
||||
f = open("large_file.txt", "wb")
|
||||
f.write(bytearray(bsize * free))
|
||||
except OSError as e:
|
||||
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC
|
||||
print("ENOSPC:", e.errno == 28) # uerrno.ENOSPC
|
||||
f.close()
|
||||
|
@ -90,7 +90,7 @@ for exist in ("", "/", "dir", "/dir", "dir/subdir"):
|
||||
try:
|
||||
uos.mkdir(exist)
|
||||
except OSError as er:
|
||||
print("mkdir OSError", er.args[0] == 17) # EEXIST
|
||||
print("mkdir OSError", er.errno == 17) # EEXIST
|
||||
|
||||
uos.chdir("/")
|
||||
print(uos.stat("test5.txt")[:-3])
|
||||
|
@ -57,7 +57,7 @@ print("getcwd:", vfs.getcwd())
|
||||
try:
|
||||
vfs.stat("no_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.ENOENT)
|
||||
print(e.errno == uerrno.ENOENT)
|
||||
|
||||
with vfs.open("foo_file.txt", "w") as f:
|
||||
f.write("hello!")
|
||||
@ -80,7 +80,7 @@ with vfs.open("sub_file.txt", "w") as f:
|
||||
try:
|
||||
vfs.chdir("sub_file.txt")
|
||||
except OSError as e:
|
||||
print(e.args[0] == uerrno.ENOENT)
|
||||
print(e.errno == uerrno.ENOENT)
|
||||
|
||||
vfs.chdir("..")
|
||||
print("getcwd:", vfs.getcwd())
|
||||
@ -94,4 +94,4 @@ print(list(vfs.ilistdir(b"")))
|
||||
try:
|
||||
vfs.ilistdir(b"no_exist")
|
||||
except OSError as e:
|
||||
print("ENOENT:", e.args[0] == uerrno.ENOENT)
|
||||
print("ENOENT:", e.errno == uerrno.ENOENT)
|
||||
|
@ -59,4 +59,4 @@ print(ws.ioctl(9))
|
||||
try:
|
||||
ws.ioctl(-1)
|
||||
except OSError as e:
|
||||
print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL)
|
||||
print("ioctl: EINVAL:", e.errno == uerrno.EINVAL)
|
||||
|
@ -17,7 +17,7 @@ def instance0():
|
||||
try:
|
||||
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
|
||||
except OSError as er:
|
||||
print(er.args[0])
|
||||
print(er.errno)
|
||||
s.close()
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ def instance0():
|
||||
print(s2.recv(10))
|
||||
print(convert_poll_list(poll.poll(1000)))
|
||||
except OSError as er:
|
||||
print(er.args[0])
|
||||
print(er.errno)
|
||||
print(convert_poll_list(poll.poll(1000)))
|
||||
# TODO lwip raises here but apparently it shouldn't
|
||||
print(s2.recv(10))
|
||||
|
@ -24,7 +24,7 @@ async def handle_connection(reader, writer):
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
except OSError as er:
|
||||
print("OSError", er.args[0])
|
||||
print("OSError", er.errno)
|
||||
ev.set()
|
||||
|
||||
|
||||
|
@ -12,5 +12,5 @@ s.listen(1)
|
||||
try:
|
||||
s.accept()
|
||||
except OSError as er:
|
||||
print(er.args[0] == 11) # 11 is EAGAIN
|
||||
print(er.errno == 11) # 11 is EAGAIN
|
||||
s.close()
|
||||
|
@ -18,5 +18,5 @@ s.listen(1)
|
||||
try:
|
||||
s.accept()
|
||||
except OSError as er:
|
||||
print(er.args[0] in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno
|
||||
print(er.errno in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno
|
||||
s.close()
|
||||
|
@ -13,7 +13,7 @@ def test(peer_addr):
|
||||
try:
|
||||
s.connect(peer_addr)
|
||||
except OSError as er:
|
||||
print(er.args[0] == errno.EINPROGRESS)
|
||||
print(er.errno == errno.EINPROGRESS)
|
||||
s.close()
|
||||
|
||||
|
||||
|
@ -25,9 +25,9 @@ def do_connect(peer_addr, tls, handshake):
|
||||
# print("Connecting to", peer_addr)
|
||||
s.connect(peer_addr)
|
||||
except OSError as er:
|
||||
print("connect:", er.args[0] == errno.EINPROGRESS)
|
||||
if er.args[0] != errno.EINPROGRESS:
|
||||
print(" got", er.args[0])
|
||||
print("connect:", er.errno == errno.EINPROGRESS)
|
||||
if er.errno != errno.EINPROGRESS:
|
||||
print(" got", er.errno)
|
||||
# wrap with ssl/tls if desired
|
||||
if tls:
|
||||
try:
|
||||
@ -67,7 +67,7 @@ def test(peer_addr, tls=False, handshake=False):
|
||||
except OSError as er:
|
||||
#
|
||||
dp(er)
|
||||
print("send:", er.args[0] in (errno.EAGAIN, errno.EINPROGRESS))
|
||||
print("send:", er.errno in (errno.EAGAIN, errno.EINPROGRESS))
|
||||
s.close()
|
||||
else: # fake it...
|
||||
print("connect:", True)
|
||||
@ -103,7 +103,7 @@ def test(peer_addr, tls=False, handshake=False):
|
||||
print("recv:", s.recv(10))
|
||||
except OSError as er:
|
||||
dp(er)
|
||||
print("recv:", er.args[0] == errno.EAGAIN)
|
||||
print("recv:", er.errno == errno.EAGAIN)
|
||||
s.close()
|
||||
else: # fake it...
|
||||
print("connect:", True)
|
||||
|
@ -17,7 +17,7 @@ def test(addr, hostname, block=True):
|
||||
s.connect(addr)
|
||||
print("connected")
|
||||
except OSError as e:
|
||||
if e.args[0] != errno.EINPROGRESS:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
print("EINPROGRESS")
|
||||
|
||||
|
@ -16,7 +16,7 @@ def test_one(site, opts):
|
||||
s.connect(addr)
|
||||
raise OSError(-1, "connect blocks")
|
||||
except OSError as e:
|
||||
if e.args[0] != errno.EINPROGRESS:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
|
||||
if sys.implementation.name != "micropython":
|
||||
@ -31,7 +31,7 @@ def test_one(site, opts):
|
||||
else:
|
||||
s = ssl.wrap_socket(s, do_handshake_on_connect=False)
|
||||
except OSError as e:
|
||||
if e.args[0] != errno.EINPROGRESS:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
print("wrapped")
|
||||
|
||||
@ -69,7 +69,7 @@ def test_one(site, opts):
|
||||
try:
|
||||
b = s.read(128)
|
||||
except OSError as err:
|
||||
if err.args[0] == 2: # 2=ssl.SSL_ERROR_WANT_READ:
|
||||
if err.errno == 2: # 2=ssl.SSL_ERROR_WANT_READ:
|
||||
continue
|
||||
raise
|
||||
if b is None:
|
||||
|
Loading…
Reference in New Issue
Block a user