diff options
| author | Damien George <damien@micropython.org> | 2025-10-03 23:02:55 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-10-20 11:56:06 +1100 |
| commit | c5dc84c7972e58f127f8c70a2c1fe2f49e488bc9 (patch) | |
| tree | 883e9bac9b2a87a12285e8a7cd4c8a4042cdd299 /tests/net_inet/resolve_on_connect.py | |
| parent | 60edfeeead49cba018c9695a0fa10f812b1e04d9 (diff) | |
tests: Move ports/esp32/resolve_on_connect.py to net_inet.
The main reason for moving this test is that it needs internet connection
to pass. So putting it in `net_inet` makes sure it's alongside other tests
that need the internet.
Also, it's a general test that could eventually run on other ports, if/when
they support doing an address resolution as part of `socket.connect()`.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/net_inet/resolve_on_connect.py')
| -rw-r--r-- | tests/net_inet/resolve_on_connect.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/net_inet/resolve_on_connect.py b/tests/net_inet/resolve_on_connect.py new file mode 100644 index 000000000..cd8bb9a1d --- /dev/null +++ b/tests/net_inet/resolve_on_connect.py @@ -0,0 +1,58 @@ +# Test that the socket module performs DNS resolutions on bind and connect. +# Currenty only the esp32 port does this, so the test is restricted to that port. + +import sys + +if sys.implementation.name == "micropython" and sys.platform != "esp32": + print("SKIP") + raise SystemExit + +import socket + + +def test_bind_resolves_0_0_0_0(): + s = socket.socket() + try: + s.bind(("0.0.0.0", 31245)) + print("bind actually bound") + 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") + 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") + 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") + 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 + "()") |
