libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1209946 - in /libcloud/branches/py3k: libcloud/common/openstack.py libcloud/compute/drivers/openstack.py libcloud/py3.py test/common/test_cloudstack.py test/compute/test_openstack.py test/file_fixtures.py
Date Sat, 03 Dec 2011 16:43:01 GMT
Author: tomaz
Date: Sat Dec  3 16:43:00 2011
New Revision: 1209946

URL: http://svn.apache.org/viewvc?rev=1209946&view=rev
Log:
All the common + compute tests now pass with Python 3.

Modified:
    libcloud/branches/py3k/libcloud/common/openstack.py
    libcloud/branches/py3k/libcloud/compute/drivers/openstack.py
    libcloud/branches/py3k/libcloud/py3.py
    libcloud/branches/py3k/test/common/test_cloudstack.py
    libcloud/branches/py3k/test/compute/test_openstack.py
    libcloud/branches/py3k/test/file_fixtures.py

Modified: libcloud/branches/py3k/libcloud/common/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/common/openstack.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/common/openstack.py (original)
+++ libcloud/branches/py3k/libcloud/common/openstack.py Sat Dec  3 16:43:00 2011
@@ -16,6 +16,8 @@
 """
 Common utilities for OpenStack
 """
+import sys
+
 from libcloud.py3 import httplib
 from libcloud.py3 import urllib2
 from libcloud.py3 import urlparse

Modified: libcloud/branches/py3k/libcloud/compute/drivers/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/drivers/openstack.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/branches/py3k/libcloud/compute/drivers/openstack.py Sat Dec  3 16:43:00 2011
@@ -26,8 +26,10 @@ except ImportError:
 import os
 
 import warnings
+
 from libcloud.py3 import httplib
 from libcloud.py3 import b
+from libcloud.py3 import next
 
 import base64
 
@@ -1037,8 +1039,8 @@ class OpenStack_1_1_NodeDriver(OpenStack
                 tenantId=api_node.get('tenant_id') or api_node['tenantId'],
                 imageId=api_node['image']['id'],
                 flavorId=api_node['flavor']['id'],
-                uri=(link['href'] for link in api_node['links'] if
-                     link['rel'] == 'self').next(),
+                uri=next(link['href'] for link in api_node['links'] if
+                     link['rel'] == 'self'),
                 metadata=api_node['metadata'],
                 password=api_node.get('adminPass'),
             ),

Modified: libcloud/branches/py3k/libcloud/py3.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/py3.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/py3.py (original)
+++ libcloud/branches/py3k/libcloud/py3.py Sat Dec  3 16:43:00 2011
@@ -15,7 +15,10 @@
 
 # Libcloud Python 2.x and 3.x compatibility layer
 
+from __future__ import absolute_import
+
 import sys
+import types
 
 PY3 = False
 PY25 = False
@@ -34,6 +37,9 @@ if sys.version_info >= (3, 0):
 
     basestring = str
 
+    def method_type(callable, instance, klass):
+        return types.MethodType(callable, instance or klass())
+
     # Taken from django.utils.py3
     bytes = __builtins__['bytes']
     def b(s):
@@ -60,6 +66,8 @@ else:
 
     basestring = unicode = str
 
+    method_type = types.MethodType
+
     # Taken from django.utils.py3
     b = bytes = str
     def byte(n):

Modified: libcloud/branches/py3k/test/common/test_cloudstack.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/test/common/test_cloudstack.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/test/common/test_cloudstack.py (original)
+++ libcloud/branches/py3k/test/common/test_cloudstack.py Sat Dec  3 16:43:00 2011
@@ -1,13 +1,15 @@
-import httplib
 import sys
 import unittest
-import urlparse
 
 try:
     import simplejson as json
 except ImportError:
     import json
 
+from libcloud.py3 import httplib
+from libcloud.py3 import urlparse
+from libcloud.py3 import b
+
 try:
     parse_qsl = urlparse.parse_qsl
 except AttributeError:
@@ -42,7 +44,8 @@ class CloudStackCommonTest(unittest.Test
         self.driver.path = '/bad/response'
         try:
             self.connection._sync_request('fake')
-        except Exception, e:
+        except Exception:
+            e = sys.exc_info()[1]
             self.assertTrue(isinstance(e, MalformedResponseError))
             return
         self.assertTrue(False)
@@ -103,7 +106,7 @@ class CloudStackCommonTest(unittest.Test
         connection = CloudStackConnection('fnord', 'abracadabra')
         for case in cases:
             params = connection.add_default_params(case[0])
-            self.assertEqual(connection._make_signature(params), case[1])
+            self.assertEqual(connection._make_signature(params), b(case[1]))
 
 class CloudStackMockHttp(MockHttpTestCase):
     def _response(self, status, result, response):

Modified: libcloud/branches/py3k/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/test/compute/test_openstack.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/test/compute/test_openstack.py (original)
+++ libcloud/branches/py3k/test/compute/test_openstack.py Sat Dec  3 16:43:00 2011
@@ -15,7 +15,10 @@
 import sys
 import unittest
 import types
+
 from libcloud.py3 import httplib
+from libcloud.py3 import method_type
+from libcloud.py3 import u
 
 from libcloud.common.types import InvalidCredsError, MalformedResponseError
 from libcloud.compute.types import Provider
@@ -397,6 +400,7 @@ class OpenStackMockHttp(MockHttpTestCase
     def _v1_0_slug_servers_EX_SHARED_IP_GROUP(self, method, url, body, headers):
         # test_create_node_ex_shared_ip_group
         # Verify that the body contains sharedIpGroupId XML element
+        body = u(body)
         self.assertTrue(body.find('sharedIpGroupId="12345"') != -1)
         body = self.fixtures.load('v1_slug_servers.xml')
         return (httplib.ACCEPTED, body, XML_HEADERS, httplib.responses[httplib.ACCEPTED])
@@ -444,6 +448,7 @@ class OpenStackMockHttp(MockHttpTestCase
         return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
 
     def _v1_0_slug_servers_444222_action(self, method, url, body, headers):
+        body = u(body)
         if body.find('resize') != -1:
             # test_ex_resize_server
             return (httplib.ACCEPTED, "", headers, httplib.responses[httplib.NO_CONTENT])
@@ -811,13 +816,13 @@ class OpenStack_1_1_Auth_2_0_MockHttp(Op
         for name in names1:
             method = methods1[name]
             new_name = name.replace('_v1_0_slug_', '_v1_0_1337_')
-            setattr(self, new_name, types.MethodType(method, self,
+            setattr(self, new_name, method_type(method, self,
                 OpenStack_1_1_Auth_2_0_MockHttp))
 
         for name in names2:
             method = methods2[name]
             new_name = name.replace('_v1_1_slug_', '_v1_0_1337_')
-            setattr(self, new_name, types.MethodType(method, self,
+            setattr(self, new_name, method_type(method, self,
                 OpenStack_1_1_Auth_2_0_MockHttp))
 
 

Modified: libcloud/branches/py3k/test/file_fixtures.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/test/file_fixtures.py?rev=1209946&r1=1209945&r2=1209946&view=diff
==============================================================================
--- libcloud/branches/py3k/test/file_fixtures.py (original)
+++ libcloud/branches/py3k/test/file_fixtures.py Sat Dec  3 16:43:00 2011
@@ -18,6 +18,8 @@ from __future__ import with_statement
 
 import os
 
+from libcloud.py3 import u
+
 FIXTURES_ROOT = {
     'compute': 'compute/fixtures',
     'storage': 'storage/fixtures',
@@ -37,7 +39,7 @@ class FileFixtures(object):
         if os.path.exists(path):
             with open(path, 'r') as fh:
                 content = fh.read()
-            return content
+            return u(content)
         else:
             raise IOError(path)
 



Mime
View raw message