8000 tests: Use .errno instead of .args[0] for OSError exceptions. · micropython/micropython@3123f69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3123f69

Browse files
committed
tests: Use .errno instead of .args[0] for OSError exceptions.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 342d555 commit 3123f69

19 files changed

+36
-36
lines changed

tests/extmod/btree1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
try:
6666
db.seq(b"foo1")
6767
except OSError as e:
68-
print(e.args[0] == uerrno.EINVAL)
68+
print(e.errno == uerrno.EINVAL)
6969

7070
print(list(db.keys()))
7171
print(list(db.values()))

tests/extmod/btree_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def ioctl(self, cmd, arg):
2727
try:
2828
db = btree.open(Device(), pagesize=511)
2929
except OSError as er:
30-
print("OSError", er.args[0] == uerrno.EINVAL)
30+
print("OSError", er.errno == uerrno.EINVAL)
3131

3232
# Valid pagesize, device returns error on read; errno comes from Device.readinto
3333
try:

tests/extmod/uselect_poll_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
try:
3434
poller.modify(s, select.POLLIN)
3535
except OSError as e:
36-
assert e.args[0] == errno.ENOENT
36+
assert e.errno == errno.ENOENT
3737

3838
# poll after closing the socket, should return POLLNVAL
3939
poller.register(s)

tests/extmod/usocket_tcp_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
try:
1515
s.recv(1)
1616
except OSError as er:
17-
print("ENOTCONN:", er.args[0] == errno.ENOTCONN)
17+
print("ENOTCONN:", er.errno == errno.ENOTCONN)

tests/extmod/usocket_udp_nonblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
try:
1818
s.recv(1)
1919
except OSError as er:
20-
print("EAGAIN:", er.args[0] == errno.EAGAIN)
20+
print("EAGAIN:", er.errno == errno.EAGAIN)

tests/extmod/vfs_fat_fileio1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ def ioctl(self, op, arg):
5858
try:
5959
f.write("world!")
6060
except OSError as e:
61-
print(e.args[0] == uerrno.EINVAL)
61+
print(e.errno == uerrno.EINVAL)
6262

6363
try:
6464
f.read()
6565
except OSError as e:
66-
print(e.args[0] == uerrno.EINVAL)
66+
print(e.errno == uerrno.EINVAL)
6767

6868
try:
6969
f.flush()
7070
except OSError as e:
71-
print(e.args[0] == uerrno.EINVAL)
71+
print(e.errno == uerrno.EINVAL)
7272

7373
try:
7474
open("foo_file.txt", "x")
7575
except OSError as e:
76-
print(e.args[0] == uerrno.EEXIST)
76+
print(e.errno == uerrno.EEXIST)
7777

7878
with open("foo_file.txt", "a") as f:
7979
f.write("world!")
@@ -105,7 +105,7 @@ def ioctl(self, op, arg):
105105
try:
106106
vfs.rmdir("foo_file.txt")
107107
except OSError as e:
108-
print(e.args[0] == 20) # uerrno.ENOTDIR
108+
print(e.errno == 20) # uerrno.ENOTDIR
109109

110110
vfs.remove("foo_file.txt")
111111
print(list(vfs.ilistdir()))

tests/extmod/vfs_fat_fileio2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ def ioctl(self, op, arg):
5151
try:
5252
vfs.mkdir("foo_dir")
5353
except OSError as e:
54-
print(e.args[0] == uerrno.EEXIST)
54+
print(e.errno == uerrno.EEXIST)
5555

5656
try:
5757
vfs.remove("foo_dir")
5858
except OSError as e:
59-
print(e.args[0] == uerrno.EISDIR)
59+
print(e.errno == uerrno.EISDIR)
6060

6161
try:
6262
vfs.remove("no_file.txt")
6363
except OSError as e:
64-
print(e.args[0] == uerrno.ENOENT)
64+
print(e.errno == uerrno.ENOENT)
6565

6666
try:
6767
vfs.rename("foo_dir", "/null/file")
6868
except OSError as e:
69-
print(e.args[0] == uerrno.ENOENT)
69+
print(e.errno == uerrno.ENOENT)
7070

7171
# file in dir
7272
with open("foo_dir/file-in-dir.txt", "w+t") as f:
@@ -82,7 +82,7 @@ def ioctl(self, op, arg):
8282
try:
8383
vfs.rmdir("foo_dir")
8484
except OSError as e:
85-
print(e.args[0] == uerrno.EACCES)
85+
print(e.errno == uerrno.EACCES)
8686

8787
# trim full path
8888
vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
@@ -111,5 +111,5 @@ def ioctl(self, op, arg):
111111
f = open("large_file.txt", "wb")
112112
f.write(bytearray(bsize * free))
113113
except OSError as e:
114-
print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC
114+
print("ENOSPC:", e.errno == 28) # uerrno.ENOSPC
115115
f.close()

tests/extmod/vfs_fat_more.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def ioctl(self, op, arg):
9090
try:
9191
uos.mkdir(exist)
9292
except OSError as er:
93-
print("mkdir OSError", er.args[0] == 17) # EEXIST
93+
print("mkdir OSError", er.errno == 17) # EEXIST
9494

9595
uos.chdir("/")
9696
print(uos.stat("test5.txt")[:-3])

tests/extmod/vfs_fat_ramdisk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def ioctl(self, op, arg):
5757
try:
5858
vfs.stat("no_file.txt")
5959
except OSError as e:
60-
print(e.args[0] == uerrno.ENOENT)
60+
print(e.errno == uerrno.ENOENT)
6161

6262
with vfs.open("foo_file.txt", "w") as f:
6363
f.write("hello!")
@@ -80,7 +80,7 @@ def ioctl(self, op, arg):
8080
try:
8181
vfs.chdir("sub_file.txt")
8282
except OSError as e:
83-
print(e.args[0] == uerrno.ENOENT)
83+
print(e.errno == uerrno.ENOENT)
8484

8585
vfs.chdir("..")
8686
print("getcwd:", vfs.getcwd())
@@ -94,4 +94,4 @@ def ioctl(self, op, arg):
9494
try:
9595
vfs.ilistdir(b"no_exist")
9696
except OSError as e:
97-
print("ENOENT:", e.args[0] == uerrno.ENOENT)
97+
print("ENOENT:", e.errno == uerrno.ENOENT)

tests/extmod/websocket_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ def ws_write(msg, sz):
5959
try:
6060
ws.ioctl(-1)
6161
except OSError as e:
62-
print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL)
62+
print("ioctl: EINVAL:", e.errno == uerrno.EINVAL)

tests/multi_net/tcp_accept_recv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def instance0():
1717
try:
1818
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
1919
except OSError as er:
20-
print(er.args[0])
20+
print(er.errno)
2121
s.close()
2222

2323

tests/multi_net/tcp_client_rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def instance0():
3333
print(s2.recv(10))
3434
print(convert_poll_list(poll.poll(1000)))
3535
except OSError as er:
36-
print(er.args[0])
36+
print(er.errno)
3737
print(convert_poll_list(poll.poll(1000)))
3838
# TODO lwip raises here but apparently it shouldn't
3939
print(s2.recv(10))

tests/multi_net/uasyncio_tcp_client_rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def handle_connection(reader, writer):
2424
writer.close()
2525
await writer.wait_closed()
2626
except OSError as er:
27-
print("OSError", er.args[0])
27+
print("OSError", er.errno)
2828
ev.set()
2929

3030

tests/net_hosted/accept_nonblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
try:
1313
s.accept()
1414
except OSError as er:
15-
print(er.args[0] == 11) # 11 is EAGAIN
15+
print(er.errno == 11) # 11 is EAGAIN
1616
s.close()

tests/net_hosted/accept_timeout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
try:
1919
s.accept()
2020
except OSError as er:
21-
print(er.args[0] in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno
21+
print(er.errno in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno
2222
s.close()

tests/net_hosted/connect_nonblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test(peer_addr):
1313
try:
1414
s.connect(peer_addr)
1515
except OSError as er:
16-
print(er.args[0] == errno.EINPROGRESS)
16+
print(er.errno == errno.EINPROGRESS)
1717
s.close()
1818

1919

tests/net_hosted/connect_nonblock_xfer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def do_connect(peer_addr, tls, handshake):
2525
# print("Connecting to", peer_addr)
2626
s.connect(peer_addr)
2727
except OSError as er:
28-
print("connect:", er.args[0] == errno.EINPROGRESS)
29-
if er.args[0] != errno.EINPROGRESS:
30-
print(" got", er.args[0])
28+
print("connect:", er.errno == errno.EINPROGRESS)
29+
if er.errno != errno.EINPROGRESS:
30+
print(" got", er.errno)
3131
# wrap with ssl/tls if desired
3232
if tls:
3333
try:
@@ -67,7 +67,7 @@ def test(peer_addr, tls=False, handshake=False):
6767
except OSError as er:
6868
#
6969
dp(er)
70-
print("send:", er.args[0] in (errno.EAGAIN, errno.EINPROGRESS))
70+
print("send:", er.errno in (errno.EAGAIN, errno.EINPROGRESS))
7171
s.close()
7272
else: # fake it...
7373
print("connect:", True)
@@ -103,7 +103,7 @@ def test(peer_addr, tls=False, handshake=False):
103103
print("recv:", s.recv(10))
104104
except OSError as er:
105105
dp(er)
106-
print("recv:", er.args[0] == errno.EAGAIN)
106+
print("recv:", er.errno == errno.EAGAIN)
107107
s.close()
108108
else: # fake it...
109109
print("connect:", True)

tests/net_inet/ssl_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test(addr, hostname, block=True):
1717
s.connect(addr)
1818
print("connected")
1919
except OSError as e:
20-
if e.args[0] != errno.EINPROGRESS:
20+
if e.errno != errno.EINPROGRESS:
2121
raise
2222
print("EINPROGRESS")
2323

tests/net_inet/test_tls_nonblock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_one(site, opts):
1616
s.connect(addr)
1717
raise OSError(-1, "connect blocks")
1818
except OSError as e:
19-
if e.args[0] != errno.EINPROGRESS:
19+
if e.errno != errno.EINPROGRESS:
2020
raise
2121

2222
if sys.implementation.name != "micropython":
@@ -31,7 +31,7 @@ def test_one(site, opts):
3131
else:
3232
s = ssl.wrap_socket(s, do_handshake_on_connect=False)
3333
except OSError as e:
34-
if e.args[0] != errno.EINPROGRESS:
34+
if e.errno != errno.EINPROGRESS:
3535
raise
3636
print("wrapped")
3737

@@ -69,7 +69,7 @@ def test_one(site, opts):
6969
try:
7070
b = s.read(128)
7171
except OSError as err:
72-
if err.args[0] == 2: # 2=ssl.SSL_ERROR_WANT_READ:
72+
if err.errno == 2: # 2=ssl.SSL_ERROR_WANT_READ:
7373
continue
7474
raise
7575
if b is None:

0 commit comments

Comments
 (0)
0