libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/7] git commit: Add unittest2 dependency for tests and use it if Python version is not in ['2.7', '3.x'].
Date Tue, 25 Jun 2013 07:00:33 GMT
Updated Branches:
  refs/heads/0.12.x f590c9fdb -> 0e7b2f46d
  refs/heads/make_rackspace_drivers_multi_datacenter_aware 3c7a7f3f6 -> 92f9b7993


Add unittest2 dependency for tests and use it if Python version is not in
['2.7', '3.x'].

Also update some of the affected tests to use unittest2.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/cb8e2f5c
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/cb8e2f5c
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/cb8e2f5c

Branch: refs/heads/make_rackspace_drivers_multi_datacenter_aware
Commit: cb8e2f5c1133a3725bdb1d614d70cf6e2327adde
Parents: 692dd9c
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Sun Jun 23 09:08:56 2013 +0200
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Sun Jun 23 18:53:54 2013 +0200

----------------------------------------------------------------------
 libcloud/test/__init__.py                    |  7 ++++++-
 libcloud/test/loadbalancer/test_rackspace.py | 16 ++++++++--------
 libcloud/utils/py3.py                        |  6 ++++++
 setup.py                                     | 12 ++++++++++++
 tox.ini                                      |  2 ++
 5 files changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb8e2f5c/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index 5351992..86fcc47 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -15,13 +15,18 @@
 
 import sys
 import random
-import unittest
 
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import StringIO
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import parse_qs
 from libcloud.utils.py3 import u
+from libcloud.utils.py3 import unittest2_required
+
+if unittest2_required:
+    import unittest2 as unittest
+else:
+    import unittest
 
 
 XML_HEADERS = {'content-type': 'application/xml'}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb8e2f5c/libcloud/test/loadbalancer/test_rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_rackspace.py b/libcloud/test/loadbalancer/test_rackspace.py
index fda5134..ac94b19 100644
--- a/libcloud/test/loadbalancer/test_rackspace.py
+++ b/libcloud/test/loadbalancer/test_rackspace.py
@@ -15,7 +15,6 @@
 
 import sys
 import datetime
-import unittest
 
 try:
     import simplejson as json
@@ -32,6 +31,7 @@ from libcloud.loadbalancer.drivers.rackspace import RackspaceUKLBDriver
 from libcloud.loadbalancer.drivers.rackspace import RackspaceAccessRuleType
 from libcloud.common.types import LibcloudError
 
+from libcloud.test import unittest
 from libcloud.test import MockHttpTestCase
 from libcloud.test.file_fixtures import LoadBalancerFileFixtures, OpenStackFixtures
 
@@ -1332,7 +1332,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3130(self, method, url, body, headers):
         """ update_balancer(b, protocol='HTTPS'), then get_balancer('3130') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'protocol': 'HTTPS'})
+            self.assertDictEqual(json.loads(body), {'protocol': 'HTTPS'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1344,7 +1344,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3131(self, method, url, body, headers):
         """ update_balancer(b, port=443), then get_balancer('3131') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'port': 1337})
+            self.assertDictEqual(json.loads(body), {'port': 1337})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1356,7 +1356,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3132(self, method, url, body, headers):
         """ update_balancer(b, name='new_lb_name'), then get_balancer('3132') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'name': 'new_lb_name'})
+            self.assertDictEqual(json.loads(body), {'name': 'new_lb_name'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1368,7 +1368,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3133(self, method, url, body, headers):
         """ update_balancer(b, algorithm='ROUND_ROBIN'), then get_balancer('3133') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'algorithm': 'ROUND_ROBIN'})
+            self.assertDictEqual(json.loads(body), {'algorithm': 'ROUND_ROBIN'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1386,7 +1386,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3135(self, method, url, body, headers):
         """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3135') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'protocol': 'IMAPv2'})
+            self.assertDictEqual(json.loads(body), {'protocol': 'IMAPv2'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1398,7 +1398,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3136(self, method, url, body, headers):
         """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3136') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'protocol': 'IMAPv3'})
+            self.assertDictEqual(json.loads(body), {'protocol': 'IMAPv3'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))
@@ -1410,7 +1410,7 @@ class RackspaceLBMockHttp(MockHttpTestCase):
     def _v1_0_slug_loadbalancers_3137(self, method, url, body, headers):
         """ update_balancer(b, protocol='IMAPv3'), then get_balancer('3137') """
         if method == "PUT":
-            self.assertEqual(json.loads(body), {'protocol': 'IMAPv4'})
+            self.assertDictEqual(json.loads(body), {'protocol': 'IMAPv4'})
             return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
         elif method == "GET":
             response_body = json.loads(self.fixtures.load("v1_slug_loadbalancers_3xxx.json"))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb8e2f5c/libcloud/utils/py3.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/py3.py b/libcloud/utils/py3.py
index 18055f0..0d6987d 100644
--- a/libcloud/utils/py3.py
+++ b/libcloud/utils/py3.py
@@ -26,6 +26,7 @@ from xml.etree import ElementTree as ET
 
 PY2 = False
 PY25 = False
+PY27 = False
 PY3 = False
 PY32 = False
 
@@ -35,6 +36,9 @@ if sys.version_info >= (2, 0) and sys.version_info < (3, 0):
 if sys.version_info >= (2, 5) and sys.version_info <= (2, 6):
     PY25 = True
 
+if sys.version_info >= (2, 7) and sys.version_info <= (2, 8):
+    PY27 = True
+
 if sys.version_info >= (3, 0):
     PY3 = True
 
@@ -141,3 +145,5 @@ if PY25:
         if not rel_list:
             return posixpath.curdir
         return posixpath.join(*rel_list)
+
+unittest2_required = not (PY27 or PY3)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb8e2f5c/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index 61629f2..1adee5d 100644
--- a/setup.py
+++ b/setup.py
@@ -31,6 +31,8 @@ except ImportError:
 
 import libcloud.utils.misc
 from libcloud.utils.dist import get_packages, get_data_files
+from libcloud.utils.py3 import unittest2_required
+
 libcloud.utils.misc.SHOW_DEPRECATION_WARNING = False
 
 
@@ -88,6 +90,16 @@ class TestCommand(Command):
                   'pip install mock')
             sys.exit(1)
 
+        if unittest2_required:
+            try:
+                import unittest2
+                unittest2
+            except ImportError:
+                print('Missing "unittest2" library. unittest2 is library is needed '
+                      'to run the tests. You can install it using pip: '
+                      'pip install unittest2')
+                sys.exit(1)
+
         status = self._run_tests()
         sys.exit(status)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb8e2f5c/tox.ini
----------------------------------------------------------------------
diff --git a/tox.ini b/tox.ini
index b6d070b..7212a7e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,12 +5,14 @@ setenv =
 
 [testenv]
 deps = mock
+       unittest2
        lockfile
        paramiko
 commands = python setup.py test
 
 [testenv:py25]
 deps = mock
+       unittest2
        lockfile
        ssl
        simplejson


Mime
View raw message