tests/net_inet/resolve_on_connect.py: Convert to use unittest.

This makes it clear what this test is expected to return/do.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-08-17 00:42:17 +10:00
parent c5dc84c797
commit 6fef4eb55c

View File

@@ -8,51 +8,31 @@ if sys.implementation.name == "micropython" and sys.platform != "esp32":
raise SystemExit
import socket
import unittest
def test_bind_resolves_0_0_0_0():
s = socket.socket()
try:
s.bind(("0.0.0.0", 31245))
print("bind actually bound")
class Test(unittest.TestCase):
def test_bind_resolves_0_0_0_0(self):
s = socket.socket()
self.assertEqual(s.bind(("0.0.0.0", 31245)), None)
s.close()
except Exception as e:
print("bind raised", e)
def test_bind_resolves_localhost():
s = socket.socket()
try:
s.bind(("localhost", 31245))
print("bind actually bound")
def test_bind_resolves_localhost(self):
s = socket.socket()
self.assertEqual(s.bind(("localhost", 31245)), None)
s.close()
except Exception as e:
print("bind raised", e)
def test_connect_resolves():
s = socket.socket()
try:
s.connect(("micropython.org", 80))
print("connect actually connected")
def test_connect_resolves(self):
s = socket.socket()
self.assertEqual(s.connect(("micropython.org", 80)), None)
s.close()
except Exception as e:
print("connect raised", e)
def test_connect_non_existent():
s = socket.socket()
try:
s.connect(("nonexistent.example.com", 80))
print("connect actually connected")
def test_connect_non_existent(self):
s = socket.socket()
with self.assertRaises(OSError):
s.connect(("nonexistent.example.com", 80))
s.close()
except OSError as e:
print("connect raised OSError")
except Exception as e:
print("connect raised", e)
test_funs = [n for n in dir() if n.startswith("test_")]
for f in sorted(test_funs):
print("--", f, end=": ")
eval(f + "()")
if __name__ == "__main__":
unittest.main()