Port test_template unit test to Python 3
* Fix test_template: replace server_id > 1 with len(server_id) > 1, server_id is a string. On Python 3, str cannot be compared to int, a TypeError is raised. * Replace ConfigParser import with six.moves.configparser * Replace basestring with six.string_types * Replace dict.iteritems() with dict.items(). The iteritems() was removed in Python 3. * Replace a/b with a//b to get integer on Python 3. * tox.ini: add common/test_template.py to Python 3.4 Partially implements: blueprint trove-python3 Change-Id: Ibe2ccdcba7d55edcc014ea00c3b927d8201d6c1b
This commit is contained in:
@@ -33,6 +33,7 @@ commands =
|
||||
python -bb -m testtools.run \
|
||||
trove/tests/unittests/common/test_context.py \
|
||||
trove/tests/unittests/common/test_exception.py \
|
||||
trove/tests/unittests/common/test_template.py \
|
||||
trove/tests/unittests/common/test_wsgi.py
|
||||
|
||||
[testenv:debug]
|
||||
|
||||
@@ -20,9 +20,9 @@ import csv
|
||||
import json
|
||||
import re
|
||||
import six
|
||||
from six.moves.configparser import SafeConfigParser
|
||||
import yaml
|
||||
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
from trove.common import utils as trove_utils
|
||||
|
||||
@@ -69,7 +69,7 @@ class StringConverter(object):
|
||||
# Return known mappings and quoted strings right away.
|
||||
if value in self._object_mappings:
|
||||
return self._object_mappings[value]
|
||||
elif (isinstance(value, basestring) and
|
||||
elif (isinstance(value, six.string_types) and
|
||||
re.match("^'(.*)'|\"(.*)\"$", value)):
|
||||
return value
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from trove.common import exception
|
||||
from trove.common.i18n import _
|
||||
@@ -229,7 +230,7 @@ class QuotaEngine(object):
|
||||
|
||||
if not quota_driver_class:
|
||||
quota_driver_class = CONF.quota_driver
|
||||
if isinstance(quota_driver_class, basestring):
|
||||
if isinstance(quota_driver_class, six.string_types):
|
||||
quota_driver_class = importutils.import_object(quota_driver_class,
|
||||
self._resources)
|
||||
self._driver = quota_driver_class
|
||||
|
||||
@@ -34,7 +34,7 @@ Resources:
|
||||
AWS::CloudFormation::Init:
|
||||
config:
|
||||
files:
|
||||
{% for file, content in files.iteritems() %}
|
||||
{% for file, content in files.items() %}
|
||||
{{ file }}:
|
||||
content: |
|
||||
{{ content | indent(16) }}
|
||||
|
||||
@@ -43,7 +43,7 @@ class TemplateTest(trove_testtools.TestCase):
|
||||
|
||||
def validate_template(self, contents, teststr, test_flavor, server_id):
|
||||
# expected query_cache_size = {{ 8 * flavor_multiplier }}M
|
||||
flavor_multiplier = test_flavor['ram'] / 512
|
||||
flavor_multiplier = test_flavor['ram'] // 512
|
||||
found_group = self._find_in_template(contents, teststr)
|
||||
if not found_group:
|
||||
raise "Could not find text in template"
|
||||
@@ -51,7 +51,7 @@ class TemplateTest(trove_testtools.TestCase):
|
||||
memsize = found_group.split(" ")[2]
|
||||
self.assertEqual("%sM" % (8 * flavor_multiplier), memsize)
|
||||
self.assertIsNotNone(server_id)
|
||||
self.assertTrue(server_id > 1)
|
||||
self.assertTrue(len(server_id) > 1)
|
||||
|
||||
def test_rendering(self):
|
||||
rendered = self.template.render(flavor=self.flavor_dict,
|
||||
|
||||
Reference in New Issue
Block a user