tests: Use .errno instead of .args[0] for OSError exceptions.

Signed-off-by: Damien George <damien@micropython.org>
pull/7136/head
Damien George 2021-04-22 19:32:21 +10:00
rodzic 342d55529d
commit 3123f6918b
19 zmienionych plików z 36 dodań i 36 usunięć

Wyświetl plik

@ -65,7 +65,7 @@ print(db.seq(1, b"qux"))
try: try:
db.seq(b"foo1") db.seq(b"foo1")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EINVAL) print(e.errno == uerrno.EINVAL)
print(list(db.keys())) print(list(db.keys()))
print(list(db.values())) print(list(db.values()))

Wyświetl plik

@ -27,7 +27,7 @@ class Device(uio.IOBase):
try: try:
db = btree.open(Device(), pagesize=511) db = btree.open(Device(), pagesize=511)
except OSError as er: 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 # Valid pagesize, device returns error on read; errno comes from Device.readinto
try: try:

Wyświetl plik

@ -33,7 +33,7 @@ poller.unregister(s)
try: try:
poller.modify(s, select.POLLIN) poller.modify(s, select.POLLIN)
except OSError as e: except OSError as e:
assert e.args[0] == errno.ENOENT assert e.errno == errno.ENOENT
# poll after closing the socket, should return POLLNVAL # poll after closing the socket, should return POLLNVAL
poller.register(s) poller.register(s)

Wyświetl plik

@ -14,4 +14,4 @@ s = socket.socket()
try: try:
s.recv(1) s.recv(1)
except OSError as er: except OSError as er:
print("ENOTCONN:", er.args[0] == errno.ENOTCONN) print("ENOTCONN:", er.errno == errno.ENOTCONN)

Wyświetl plik

@ -17,4 +17,4 @@ s.settimeout(0)
try: try:
s.recv(1) s.recv(1)
except OSError as er: except OSError as er:
print("EAGAIN:", er.args[0] == errno.EAGAIN) print("EAGAIN:", er.errno == errno.EAGAIN)

Wyświetl plik

@ -58,22 +58,22 @@ f.close() # allowed
try: try:
f.write("world!") f.write("world!")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EINVAL) print(e.errno == uerrno.EINVAL)
try: try:
f.read() f.read()
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EINVAL) print(e.errno == uerrno.EINVAL)
try: try:
f.flush() f.flush()
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EINVAL) print(e.errno == uerrno.EINVAL)
try: try:
open("foo_file.txt", "x") open("foo_file.txt", "x")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EEXIST) print(e.errno == uerrno.EEXIST)
with open("foo_file.txt", "a") as f: with open("foo_file.txt", "a") as f:
f.write("world!") f.write("world!")
@ -105,7 +105,7 @@ vfs.mkdir("foo_dir")
try: try:
vfs.rmdir("foo_file.txt") vfs.rmdir("foo_file.txt")
except OSError as e: except OSError as e:
print(e.args[0] == 20) # uerrno.ENOTDIR print(e.errno == 20) # uerrno.ENOTDIR
vfs.remove("foo_file.txt") vfs.remove("foo_file.txt")
print(list(vfs.ilistdir())) print(list(vfs.ilistdir()))

Wyświetl plik

@ -51,22 +51,22 @@ uos.chdir("/ramdisk")
try: try:
vfs.mkdir("foo_dir") vfs.mkdir("foo_dir")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EEXIST) print(e.errno == uerrno.EEXIST)
try: try:
vfs.remove("foo_dir") vfs.remove("foo_dir")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EISDIR) print(e.errno == uerrno.EISDIR)
try: try:
vfs.remove("no_file.txt") vfs.remove("no_file.txt")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.ENOENT) print(e.errno == uerrno.ENOENT)
try: try:
vfs.rename("foo_dir", "/null/file") vfs.rename("foo_dir", "/null/file")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.ENOENT) print(e.errno == uerrno.ENOENT)
# file in dir # file in dir
with open("foo_dir/file-in-dir.txt", "w+t") as f: 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: try:
vfs.rmdir("foo_dir") vfs.rmdir("foo_dir")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.EACCES) print(e.errno == uerrno.EACCES)
# trim full path # trim full path
vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
@ -111,5 +111,5 @@ try:
f = open("large_file.txt", "wb") f = open("large_file.txt", "wb")
f.write(bytearray(bsize * free)) f.write(bytearray(bsize * free))
except OSError as e: except OSError as e:
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC print("ENOSPC:", e.errno == 28) # uerrno.ENOSPC
f.close() f.close()

Wyświetl plik

@ -90,7 +90,7 @@ for exist in ("", "/", "dir", "/dir", "dir/subdir"):
try: try:
uos.mkdir(exist) uos.mkdir(exist)
except OSError as er: except OSError as er:
print("mkdir OSError", er.args[0] == 17) # EEXIST print("mkdir OSError", er.errno == 17) # EEXIST
uos.chdir("/") uos.chdir("/")
print(uos.stat("test5.txt")[:-3]) print(uos.stat("test5.txt")[:-3])

Wyświetl plik

@ -57,7 +57,7 @@ print("getcwd:", vfs.getcwd())
try: try:
vfs.stat("no_file.txt") vfs.stat("no_file.txt")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.ENOENT) print(e.errno == uerrno.ENOENT)
with vfs.open("foo_file.txt", "w") as f: with vfs.open("foo_file.txt", "w") as f:
f.write("hello!") f.write("hello!")
@ -80,7 +80,7 @@ with vfs.open("sub_file.txt", "w") as f:
try: try:
vfs.chdir("sub_file.txt") vfs.chdir("sub_file.txt")
except OSError as e: except OSError as e:
print(e.args[0] == uerrno.ENOENT) print(e.errno == uerrno.ENOENT)
vfs.chdir("..") vfs.chdir("..")
print("getcwd:", vfs.getcwd()) print("getcwd:", vfs.getcwd())
@ -94,4 +94,4 @@ print(list(vfs.ilistdir(b"")))
try: try:
vfs.ilistdir(b"no_exist") vfs.ilistdir(b"no_exist")
except OSError as e: except OSError as e:
print("ENOENT:", e.args[0] == uerrno.ENOENT) print("ENOENT:", e.errno == uerrno.ENOENT)

Wyświetl plik

@ -59,4 +59,4 @@ print(ws.ioctl(9))
try: try:
ws.ioctl(-1) ws.ioctl(-1)
except OSError as e: except OSError as e:
print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL) print("ioctl: EINVAL:", e.errno == uerrno.EINVAL)

Wyświetl plik

@ -17,7 +17,7 @@ def instance0():
try: try:
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
except OSError as er: except OSError as er:
print(er.args[0]) print(er.errno)
s.close() s.close()

Wyświetl plik

@ -33,7 +33,7 @@ def instance0():
print(s2.recv(10)) print(s2.recv(10))
print(convert_poll_list(poll.poll(1000))) print(convert_poll_list(poll.poll(1000)))
except OSError as er: except OSError as er:
print(er.args[0]) print(er.errno)
print(convert_poll_list(poll.poll(1000))) print(convert_poll_list(poll.poll(1000)))
# TODO lwip raises here but apparently it shouldn't # TODO lwip raises here but apparently it shouldn't
print(s2.recv(10)) print(s2.recv(10))

Wyświetl plik

@ -24,7 +24,7 @@ async def handle_connection(reader, writer):
writer.close() writer.close()
await writer.wait_closed() await writer.wait_closed()
except OSError as er: except OSError as er:
print("OSError", er.args[0]) print("OSError", er.errno)
ev.set() ev.set()

Wyświetl plik

@ -12,5 +12,5 @@ s.listen(1)
try: try:
s.accept() s.accept()
except OSError as er: except OSError as er:
print(er.args[0] == 11) # 11 is EAGAIN print(er.errno == 11) # 11 is EAGAIN
s.close() s.close()

Wyświetl plik

@ -18,5 +18,5 @@ s.listen(1)
try: try:
s.accept() s.accept()
except OSError as er: 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() s.close()

Wyświetl plik

@ -13,7 +13,7 @@ def test(peer_addr):
try: try:
s.connect(peer_addr) s.connect(peer_addr)
except OSError as er: except OSError as er:
print(er.args[0] == errno.EINPROGRESS) print(er.errno == errno.EINPROGRESS)
s.close() s.close()

Wyświetl plik

@ -25,9 +25,9 @@ def do_connect(peer_addr, tls, handshake):
# print("Connecting to", peer_addr) # print("Connecting to", peer_addr)
s.connect(peer_addr) s.connect(peer_addr)
except OSError as er: except OSError as er:
print("connect:", er.args[0] == errno.EINPROGRESS) print("connect:", er.errno == errno.EINPROGRESS)
if er.args[0] != errno.EINPROGRESS: if er.errno != errno.EINPROGRESS:
print(" got", er.args[0]) print(" got", er.errno)
# wrap with ssl/tls if desired # wrap with ssl/tls if desired
if tls: if tls:
try: try:
@ -67,7 +67,7 @@ def test(peer_addr, tls=False, handshake=False):
except OSError as er: except OSError as er:
# #
dp(er) dp(er)
print("send:", er.args[0] in (errno.EAGAIN, errno.EINPROGRESS)) print("send:", er.errno in (errno.EAGAIN, errno.EINPROGRESS))
s.close() s.close()
else: # fake it... else: # fake it...
print("connect:", True) print("connect:", True)
@ -103,7 +103,7 @@ def test(peer_addr, tls=False, handshake=False):
print("recv:", s.recv(10)) print("recv:", s.recv(10))
except OSError as er: except OSError as er:
dp(er) dp(er)
print("recv:", er.args[0] == errno.EAGAIN) print("recv:", er.errno == errno.EAGAIN)
s.close() s.close()
else: # fake it... else: # fake it...
print("connect:", True) print("connect:", True)

Wyświetl plik

@ -17,7 +17,7 @@ def test(addr, hostname, block=True):
s.connect(addr) s.connect(addr)
print("connected") print("connected")
except OSError as e: except OSError as e:
if e.args[0] != errno.EINPROGRESS: if e.errno != errno.EINPROGRESS:
raise raise
print("EINPROGRESS") print("EINPROGRESS")

Wyświetl plik

@ -16,7 +16,7 @@ def test_one(site, opts):
s.connect(addr) s.connect(addr)
raise OSError(-1, "connect blocks") raise OSError(-1, "connect blocks")
except OSError as e: except OSError as e:
if e.args[0] != errno.EINPROGRESS: if e.errno != errno.EINPROGRESS:
raise raise
if sys.implementation.name != "micropython": if sys.implementation.name != "micropython":
@ -31,7 +31,7 @@ def test_one(site, opts):
else: else:
s = ssl.wrap_socket(s, do_handshake_on_connect=False) s = ssl.wrap_socket(s, do_handshake_on_connect=False)
except OSError as e: except OSError as e:
if e.args[0] != errno.EINPROGRESS: if e.errno != errno.EINPROGRESS:
raise raise
print("wrapped") print("wrapped")
@ -69,7 +69,7 @@ def test_one(site, opts):
try: try:
b = s.read(128) b = s.read(128)
except OSError as err: 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 continue
raise raise
if b is None: if b is None: