Path: blob/main/python/python-wasm/src/test/posix/netdb.test.ts
1067 views
import { syncPython } from "../../node";12/*3>>> import socket; socket.gethostbyaddr('2001:4860:4860::8888')4('dns.google', ['8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa'], ['2001:4860:4860::8888'])5*/67test("gethostbyaddr for google's v4 ip -- consistency check", async () => {8const { exec, repr } = await syncPython();9exec("import socket");10exec("s = socket.gethostbyaddr(socket.gethostbyname('google.com'))");11// console.log(repr("s"));12expect(repr("s[0].endswith('.net')")).toBe("True");13});1415// test("gethostbyaddr on a domain name should also work (it does in native cpython)", async () => {16// await exec("s = socket.gethostbyaddr('google.com')");17// expect(await repr("s[0].endswith('.net')")).toBe("True");18// });1920// test("gethostbyaddr for google's v6 ip", async () => {21// await exec("s = socket.gethostbyaddr('2001:4860:4860::8888')");22// expect(23// await repr("s[0] == 'dns.google' and s[-1] == ['2001:4860:4860::8888']")24// ).toBe("True");25// });2627// test("gethostbyname for google (not sure how stable output is)", async () => {28// const ip = eval(await repr("socket.gethostbyname('google.com')"));29// expect(ip).toMatch(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/g);30// });3132// test("gethostbyaddr on google's ip doesn't fail", async () => {33// await exec("google = socket.gethostbyname('google.com')");34// expect(await repr("socket.gethostbyaddr(google)[-1][0] == google")).toBe(35// "True"36// );37// });3839// test("getting an error code via a system call", async () => {40// await exec(41// "try: socket.getaddrinfo('google.com',-10)\nexcept Exception as e: the_error=e"42// );43// expect((await repr("the_error")).startsWith("gaierror")).toBe(true);44// });4546// test("using getaddrinfo with a SOCK_STREAM", async () => {47// expect(48// await repr(49// "socket.getaddrinfo('httpbin.org',80, socket.AF_INET, socket.SOCK_STREAM)"50// )51// ).toContain("AddressFamily.AF_INET");52// });535455