make file closing more robust
[python/dscho.git] / Lib / test / test_xmlrpc_net.py
blobf6ebbf01928bd5a2c8a3cdcc94d56d9b15465980
1 #!/usr/bin/env python
3 import errno
4 import socket
5 import sys
6 import unittest
7 from test import support
9 import xmlrpc.client as xmlrpclib
11 class CurrentTimeTest(unittest.TestCase):
13 def test_current_time(self):
14 # Get the current time from xmlrpc.com. This code exercises
15 # the minimal HTTP functionality in xmlrpclib.
16 server = xmlrpclib.ServerProxy("http://time.xmlrpc.com/RPC2")
17 try:
18 t0 = server.currentTime.getCurrentTime()
19 except socket.error as e:
20 print(" test_current_time: skipping test, got error: %s" % e,
21 file=sys.stderr)
22 return
24 # Perform a minimal sanity check on the result, just to be sure
25 # the request means what we think it means.
26 t1 = xmlrpclib.DateTime()
28 dt0 = xmlrpclib._datetime_type(t0.value)
29 dt1 = xmlrpclib._datetime_type(t1.value)
30 if dt0 > dt1:
31 delta = dt0 - dt1
32 else:
33 delta = dt1 - dt0
34 # The difference between the system time here and the system
35 # time on the server should not be too big.
36 self.assert_(delta.days <= 1)
39 def test_main():
40 support.requires("network")
41 support.run_unittest(CurrentTimeTest)
43 if __name__ == "__main__":
44 test_main()