diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-07-16 16:15:47 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-07-16 16:15:47 -0400 |
commit | 6a4976e8a9915680fbc91f90bed8fcfa79cba5cf (patch) | |
tree | bbb7740d1c897b14e28fbd4d784115f46130f38c | |
parent | e11e7c2d1e908d99179f0382da4ac0b4d49bd7aa (diff) | |
parent | 81525fd93541b41d31b6da13df61a0494cc1e7f6 (diff) | |
download | vyos-cloud-init-6a4976e8a9915680fbc91f90bed8fcfa79cba5cf.tar.gz vyos-cloud-init-6a4976e8a9915680fbc91f90bed8fcfa79cba5cf.zip |
fix 'make test' in python 2.6
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | tests/unittests/helpers.py | 24 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_cloudsigma.py | 5 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_gce.py | 5 |
4 files changed, 31 insertions, 4 deletions
@@ -6,6 +6,7 @@ - SmartOS test: do not require existance of /dev/ttyS1. [LP: #1316597] - doc: fix user-groups doc to reference plural ssh-authorized-keys (LP: #1327065) [Joern Heissler] + - fix 'make test' in python 2.6 0.7.5: - open 0.7.5 - Add a debug log message around import failures diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py index 5bed13cc..970eb8cb 100644 --- a/tests/unittests/helpers.py +++ b/tests/unittests/helpers.py @@ -52,6 +52,30 @@ if PY26: standardMsg = standardMsg % (value) self.fail(self._formatMessage(msg, standardMsg)) + def assertDictContainsSubset(self, expected, actual, msg=None): + missing = [] + mismatched = [] + for k, v in expected.iteritems(): + if k not in actual: + missing.append(k) + elif actual[k] != v: + mismatched.append('%r, expected: %r, actual: %r' + % (k, v, actual[k])) + + if len(missing) == 0 and len(mismatched) == 0: + return + + standardMsg = '' + if missing: + standardMsg = 'Missing: %r' % ','.join(m for m in missing) + if mismatched: + if standardMsg: + standardMsg += '; ' + standardMsg += 'Mismatched values: %s' % ','.join(mismatched) + + self.fail(self._formatMessage(msg, standardMsg)) + + else: class TestCase(unittest.TestCase): pass diff --git a/tests/unittests/test_datasource/test_cloudsigma.py b/tests/unittests/test_datasource/test_cloudsigma.py index f92e07b7..eadb3cb7 100644 --- a/tests/unittests/test_datasource/test_cloudsigma.py +++ b/tests/unittests/test_datasource/test_cloudsigma.py @@ -1,10 +1,11 @@ # coding: utf-8 import copy -from unittest import TestCase from cloudinit.cs_utils import Cepko from cloudinit.sources import DataSourceCloudSigma +from tests.unittests import helpers as test_helpers + SERVER_CONTEXT = { "cpu": 1000, @@ -36,7 +37,7 @@ class CepkoMock(Cepko): return self -class DataSourceCloudSigmaTest(TestCase): +class DataSourceCloudSigmaTest(test_helpers.TestCase): def setUp(self): self.datasource = DataSourceCloudSigma.DataSourceCloudSigma("", "", "") self.datasource.is_running_in_cloudsigma = lambda: True diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py index d91bd531..1979a0de 100644 --- a/tests/unittests/test_datasource/test_gce.py +++ b/tests/unittests/test_datasource/test_gce.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import unittest import httpretty import re @@ -25,6 +24,8 @@ from cloudinit import settings from cloudinit import helpers from cloudinit.sources import DataSourceGCE +from tests.unittests import helpers as test_helpers + GCE_META = { 'instance/id': '123', 'instance/zone': 'foo/bar', @@ -54,7 +55,7 @@ def _request_callback(method, uri, headers): return (404, headers, '') -class TestDataSourceGCE(unittest.TestCase): +class TestDataSourceGCE(test_helpers.TestCase): def setUp(self): self.ds = DataSourceGCE.DataSourceGCE( |