Commits

mopemope  committed 079b6c2

Add lookup test

  • Participants
  • Parent commits 07e95f3

Comments (0)

Files changed (2)

File test/test_lookup.py

+from pytest import *
+from tobikko.core import *
+import socket
+from tobikko import socket as tsocket
+from testutil import *
+
+#print(dir(socket))
+
+HOST = "yahoo.com"
+HOST_IP = "98.137.149.56"
+HOST_IPS = ['69.147.125.65', '72.30.2.43', '98.137.149.56', '209.191.122.70', '67.195.160.76']
+FAIL_HOST = "yahoo.coom"
+FAIL_HOST_IP = "77.77.77.77"
+
+def test_getaddrinfo():
+    print_name()
+    tret = tsocket.getaddrinfo(None, 80)
+    ret = socket.getaddrinfo(None, 80)
+    assert(ret == tret)
+
+def test_getaddrinfo2():
+    print_name()
+    tret = tsocket.getaddrinfo(HOST, 80, 0, tsocket.SOCK_STREAM)
+    ret = socket.getaddrinfo(HOST, 80, 0, socket.SOCK_STREAM)
+    print(tret)
+    print(ret)
+    assert(len(ret) == len(tret))
+
+def test_getaddrinfo3():
+    print_name()
+    tret = tsocket.getaddrinfo(HOST_IP, 80, 0, tsocket.SOCK_STREAM)
+    ret = socket.getaddrinfo(HOST_IP, 80, 0, socket.SOCK_STREAM)
+    print(tret)
+    print(ret)
+    assert(len(ret) == len(tret))
+
+def test_getaddrinfo_fail():
+    print_name()
+    with raises(tsocket.gaierror):
+        tret = tsocket.getaddrinfo(FAIL_HOST, 80)
+
+def test_getfqdn():
+    print_name()
+    tret = tsocket.getfqdn(HOST)
+    ret = socket.getfqdn(HOST)
+    print(tret)
+    print(ret)
+    assert(tret.startswith("ir1.fp.vip"))
+
+def test_getfqdn2():
+    print_name()
+    tret = tsocket.getfqdn(HOST_IP)
+    ret = socket.getfqdn(HOST_IP)
+    print(tret)
+    print(ret)
+    assert(tret.startswith("ir1.fp.vip"))
+
+def test_getfqdn_fail():
+    print_name()
+    tret = tsocket.getfqdn(FAIL_HOST)
+    ret = socket.getfqdn(FAIL_HOST)
+    assert(ret == tret)
+
+def test_gethostbyname():
+    print_name()
+    ret = tsocket.gethostbyname(HOST)
+    assert(ret in HOST_IPS)
+
+def test_gethostbyname2():
+    print_name()
+    ret = tsocket.gethostbyname(HOST_IP)
+    assert(ret in HOST_IPS)
+
+def test_gethostbyname_fail():
+    print_name()
+    with raises(tsocket.gaierror):
+        ret = tsocket.gethostbyname(FAIL_HOST)
+
+def test_gethostbyname_ex():
+    print_name()
+    tret = tsocket.gethostbyname_ex(HOST)
+    ret = socket.gethostbyname_ex(HOST)
+    assert(ret[0] == tret[0])
+    assert(len(ret[2]) == len(tret[2]))
+
+def test_gethostbyname_ex2():
+    print_name()
+    tret = tsocket.gethostbyname_ex(HOST_IP)
+    ret = socket.gethostbyname_ex(HOST_IP)
+    assert(ret[0] == tret[0])
+    assert(len(ret[2]) == len(tret[2]))
+
+def test_gethostbyname_ex_fail():
+    print_name()
+    with raises(tsocket.gaierror):
+        ret = tsocket.gethostbyname_ex(FAIL_HOST)
+
+def test_gethostname():
+    print_name()
+    tret = tsocket.gethostname()
+    ret = socket.gethostname()
+    assert(ret == tret)
+
+def test_gethostbyaddr():
+    print_name()
+    tret = tsocket.gethostbyaddr(HOST)
+    ret = socket.gethostbyaddr(HOST)
+    print(tret)
+    print(ret)
+    assert(tret[0].startswith("ir1.fp.vip"))
+
+def test_gethostbyaddr2():
+    print_name()
+    tret = tsocket.gethostbyaddr(HOST_IP)
+    ret = socket.gethostbyaddr(HOST_IP)
+    print(tret)
+    print(ret)
+    assert(ret == tret)
+
+
+def test_gethostbyaddr3():
+    print_name()
+    with raises(tsocket.gaierror):
+        tret = tsocket.gethostbyaddr(FAIL_HOST)
+
+def test_getnameinfo():
+    print_name()
+    tret = tsocket.getnameinfo((HOST_IP, 80), tsocket.NI_NUMERICHOST);
+    ret = socket.getnameinfo((HOST_IP, 80), socket.NI_NUMERICHOST);
+    assert(ret == tret)
+
+def test_getnameinfo2():
+    print_name()
+    tret = tsocket.getnameinfo((HOST_IP, 80), tsocket.NI_NUMERICSERV);
+    ret = socket.getnameinfo((HOST_IP, 80), socket.NI_NUMERICSERV);
+    assert(ret == tret)
+
+def test_getnameinfo3():
+    print_name()
+    with raises(tsocket.gaierror):
+        ret = tsocket.getnameinfo((HOST, 80), tsocket.NI_NUMERICHOST);
+

File test/test_socket_mod.py

 
 HOST = "yahoo.com"
 HOST_IP = "98.137.149.56"
-HOST_IPS = ['69.147.125.65', '72.30.2.43', '98.137.149.56', '209.191.122.70', '67.195.160.76']
 FAIL_HOST = "yahoo.coom"
-FAIL_HOST_IP = "77.77.77.77"
 
 def test_create_connection():
     print_name()
     with raises(tsocket.gaierror):
         ts = tsocket.create_connection((FAIL_HOST, 80))
 
-def test_getaddrinfo():
-    print_name()
-    tret = tsocket.getaddrinfo(None, 80)
-    ret = socket.getaddrinfo(None, 80)
-    assert(ret == tret)
-
-def test_getaddrinfo2():
-    print_name()
-    tret = tsocket.getaddrinfo(HOST, 80, 0, tsocket.SOCK_STREAM)
-    ret = socket.getaddrinfo(HOST, 80, 0, socket.SOCK_STREAM)
-    print(tret)
-    print(ret)
-    assert(len(ret) == len(tret))
-
-def test_getaddrinfo3():
-    print_name()
-    tret = tsocket.getaddrinfo(HOST_IP, 80, 0, tsocket.SOCK_STREAM)
-    ret = socket.getaddrinfo(HOST_IP, 80, 0, socket.SOCK_STREAM)
-    print(tret)
-    print(ret)
-    assert(len(ret) == len(tret))
-
-def test_getaddrinfo_fail():
-    print_name()
-    with raises(tsocket.gaierror):
-        tret = tsocket.getaddrinfo(FAIL_HOST, 80)
-
-def test_getfqdn():
-    print_name()
-    tret = tsocket.getfqdn(HOST)
-    ret = socket.getfqdn(HOST)
-    print(tret)
-    print(ret)
-    assert(tret.startswith("ir1.fp.vip"))
-
-def test_getfqdn2():
-    print_name()
-    tret = tsocket.getfqdn(HOST_IP)
-    ret = socket.getfqdn(HOST_IP)
-    print(tret)
-    print(ret)
-    assert(tret.startswith("ir1.fp.vip"))
-
-def test_getfqdn_fail():
-    print_name()
-    tret = tsocket.getfqdn(FAIL_HOST)
-    ret = socket.getfqdn(FAIL_HOST)
-    assert(ret == tret)
-
-def test_gethostbyname():
-    print_name()
-    ret = tsocket.gethostbyname(HOST)
-    assert(ret in HOST_IPS)
-
-def test_gethostbyname2():
-    print_name()
-    ret = tsocket.gethostbyname(HOST_IP)
-    assert(ret in HOST_IPS)
-
-def test_gethostbyname_fail():
-    print_name()
-    with raises(tsocket.gaierror):
-        ret = tsocket.gethostbyname(FAIL_HOST)
-
-def test_gethostbyname_ex():
-    print_name()
-    tret = tsocket.gethostbyname_ex(HOST)
-    ret = socket.gethostbyname_ex(HOST)
-    assert(ret[0] == tret[0])
-    assert(len(ret[2]) == len(tret[2]))
-
-def test_gethostbyname_ex2():
-    print_name()
-    tret = tsocket.gethostbyname_ex(HOST_IP)
-    ret = socket.gethostbyname_ex(HOST_IP)
-    assert(ret[0] == tret[0])
-    assert(len(ret[2]) == len(tret[2]))
-
-def test_gethostbyname_ex_fail():
-    print_name()
-    with raises(tsocket.gaierror):
-        ret = tsocket.gethostbyname_ex(FAIL_HOST)
-
-def test_gethostname():
-    print_name()
-    tret = tsocket.gethostname()
-    ret = socket.gethostname()
-    assert(ret == tret)
-
-def test_gethostbyaddr():
-    print_name()
-    tret = tsocket.gethostbyaddr(HOST)
-    ret = socket.gethostbyaddr(HOST)
-    print(tret)
-    print(ret)
-    assert(tret[0].startswith("ir1.fp.vip"))
-
-def test_gethostbyaddr2():
-    print_name()
-    tret = tsocket.gethostbyaddr(HOST_IP)
-    ret = socket.gethostbyaddr(HOST_IP)
-    print(tret)
-    print(ret)
-    assert(ret == tret)
-
-
-def test_gethostbyaddr3():
-    print_name()
-    with raises(tsocket.gaierror):
-        tret = tsocket.gethostbyaddr(FAIL_HOST)
-
-def test_getnameinfo():
-    print_name()
-    tret = tsocket.getnameinfo((HOST_IP, 80), tsocket.NI_NUMERICHOST);
-    ret = socket.getnameinfo((HOST_IP, 80), socket.NI_NUMERICHOST);
-    assert(ret == tret)
-
-def test_getnameinfo2():
-    print_name()
-    tret = tsocket.getnameinfo((HOST_IP, 80), tsocket.NI_NUMERICSERV);
-    ret = socket.getnameinfo((HOST_IP, 80), socket.NI_NUMERICSERV);
-    assert(ret == tret)
-
-def test_getnameinfo3():
-    print_name()
-    with raises(tsocket.gaierror):
-        ret = tsocket.getnameinfo((HOST, 80), tsocket.NI_NUMERICHOST);
-
 def test_socketpair():
     print_name()
     s = socket.socketpair()