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 raise SystemExit
import socket import socket
import unittest
def test_bind_resolves_0_0_0_0(): class Test(unittest.TestCase):
s = socket.socket() def test_bind_resolves_0_0_0_0(self):
try: s = socket.socket()
s.bind(("0.0.0.0", 31245)) self.assertEqual(s.bind(("0.0.0.0", 31245)), None)
print("bind actually bound")
s.close() s.close()
except Exception as e:
print("bind raised", e)
def test_bind_resolves_localhost(self):
def test_bind_resolves_localhost(): s = socket.socket()
s = socket.socket() self.assertEqual(s.bind(("localhost", 31245)), None)
try:
s.bind(("localhost", 31245))
print("bind actually bound")
s.close() s.close()
except Exception as e:
print("bind raised", e)
def test_connect_resolves(self):
def test_connect_resolves(): s = socket.socket()
s = socket.socket() self.assertEqual(s.connect(("micropython.org", 80)), None)
try:
s.connect(("micropython.org", 80))
print("connect actually connected")
s.close() s.close()
except Exception as e:
print("connect raised", e)
def test_connect_non_existent(self):
def test_connect_non_existent(): s = socket.socket()
s = socket.socket() with self.assertRaises(OSError):
try: s.connect(("nonexistent.example.com", 80))
s.connect(("nonexistent.example.com", 80))
print("connect actually connected")
s.close() 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_")] if __name__ == "__main__":
for f in sorted(test_funs): unittest.main()
print("--", f, end=": ")
eval(f + "()")