Do simplejson imports in json_rpc lazily, so that the library is only needed
for actually making rpc calls, not just for importing the json_rpc module.

Also adjust the unittest suite runner to add the serviceHandler_unittest
to the long tests, since it requires a build externals run to actually work.

Signed-off-by: John Admanski <[email protected]>

--- autotest/frontend/afe/json_rpc/proxy.py     2010-01-21 17:34:36.000000000 
-0800
+++ autotest/frontend/afe/json_rpc/proxy.py     2010-01-26 14:53:19.000000000 
-0800
@@ -20,9 +20,6 @@
 """
 
 import urllib2
-from simplejson import decoder, encoder
-json_encoder = encoder.JSONEncoder()
-json_decoder = decoder.JSONDecoder()
 
 class JSONRPCException(Exception):
     pass
@@ -39,14 +36,18 @@
         return ServiceProxy(self.__serviceURL, name, self.__headers)
 
     def __call__(self, *args, **kwargs):
-        postdata = json_encoder.encode({"method": self.__serviceName,
-                                        'params': args + (kwargs,),
-                                        'id':'jsonrpc'})
+        # pull in simplejson imports lazily so that the library isn't required
+        # unless you actually need to do encoding and decoding
+        from simplejson import decoder, encoder
+
+        postdata = encoder.encode({"method": self.__serviceName,
+                                   'params': args + (kwargs,),
+                                   'id':'jsonrpc'})
         request = urllib2.Request(self.__serviceURL, data=postdata,
                                   headers=self.__headers)
         respdata = urllib2.urlopen(request).read()
         try:
-            resp = json_decoder.decode(respdata)
+            resp = decoder.decode(respdata)
         except ValueError:
             raise JSONRPCException('Error decoding JSON reponse:\n' + respdata)
         if resp['error'] is not None:
--- autotest/utils/unittest_suite.py    2010-01-22 12:49:54.000000000 -0800
+++ autotest/utils/unittest_suite.py    2010-01-26 14:53:19.000000000 -0800
@@ -27,6 +27,7 @@
     'resources_test.py',
     'logging_manager_test.py',
     'models_test.py',
+    'serviceHandler_unittest.py',
     ))
 
 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to