From d82e67f2eb756e1e2e8b7c19630dd4a2d6aeaa17 Mon Sep 17 00:00:00 2001 From: "Mark W. Eichin" Date: Fri, 24 Apr 2009 05:21:41 +0000 Subject: test that the file descriptor ZGetFD returns is actually a socket --- lib/zephyr_tests.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/zephyr_tests.txt') diff --git a/lib/zephyr_tests.txt b/lib/zephyr_tests.txt index 906399a..a30cb88 100644 --- a/lib/zephyr_tests.txt +++ b/lib/zephyr_tests.txt @@ -176,6 +176,17 @@ Trivial test of ZOpenPort and ZClosePort: >>> st = _z.ZOpenPort(port) >>> assert st == 0 >>> assert _z.ZGetFD() != -1 + >>> zsock = zephyr_tests.getsockname(_z.ZGetFD()) + >>> assert zsock + >>> from socket import AF_INET + >>> assert zsock.sa_family.value == AF_INET, zsock.sa_family + +(Here we're actually using getsockname as an "is that file descriptor + a socket" test; the wrapper is weak in that it can't check for + ENOTSOCK without requiring Python 2.6, so it just throws an exception + on any return of -1. If ctypes.cast worked on sockaddr, we could + also cast it to sockaddr_in and look at the address and port...) + >>> assert port != 0 >>> zephyr_tests.ctypes_pprint(_z.ZGetDestAddr()) ... # doctest: +ELLIPSIS @@ -184,8 +195,6 @@ Trivial test of ZOpenPort and ZClosePort: sin_addr 127.0.0.1 sin_zero [ignored] -TODO: consider checking that ZGetFD is returning a socket on that port. - >>> assert _z.ZClosePort() == 0 >>> assert _z.ZGetFD() == -1 -- cgit v1.2.3