1try: 2 import usocket as socket, sys 3except: 4 import socket, sys 5 6 7def test_non_existent(): 8 try: 9 res = socket.getaddrinfo("nonexistent.example.com", 80) 10 print("getaddrinfo returned", res) 11 except OSError as e: 12 print("getaddrinfo raised") 13 14 15def test_bogus(): 16 try: 17 res = socket.getaddrinfo("hey.!!$$", 80) 18 print("getaddrinfo returned", res) 19 except OSError as e: 20 print("getaddrinfo raised") 21 except Exception as e: 22 print("getaddrinfo raised") # CPython raises UnicodeError!? 23 24 25def test_ip_addr(): 26 try: 27 res = socket.getaddrinfo("10.10.10.10", 80) 28 print("getaddrinfo returned resolutions") 29 except Exception as e: 30 print("getaddrinfo raised", e) 31 32 33def test_0_0_0_0(): 34 try: 35 res = socket.getaddrinfo("0.0.0.0", 80) 36 print("getaddrinfo returned resolutions") 37 except Exception as e: 38 print("getaddrinfo raised", e) 39 40 41def test_valid(): 42 try: 43 res = socket.getaddrinfo("micropython.org", 80) 44 print("getaddrinfo returned resolutions") 45 except Exception as e: 46 print("getaddrinfo raised", e) 47 48 49test_funs = [n for n in dir() if n.startswith("test_")] 50for f in sorted(test_funs): 51 print("--", f, end=": ") 52 eval(f + "()") 53