From 880e7898aa3a78c3251490d371a275d85c375278 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Sun, 23 Feb 2014 15:36:20 +0800 Subject: [PATCH] Replace str with six.text_type in tests Replace str with six.text_type in necessary places, so that lazy translation can be enabled in subsequent patches. Change-Id: I40732ec7e9f53b3cb487880965797253452f95cd --- heat/tests/test_engine_api_utils.py | 5 +++-- heat/tests/test_fault_middleware.py | 8 ++++++-- heat/tests/test_hot.py | 10 ++++++---- heat/tests/test_template_format.py | 3 ++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index cfc5b0263..5d0546ce8 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -16,6 +16,7 @@ import json import uuid import mock +import six from heat.common.identifier import EventIdentifier from heat.common import template_format @@ -54,7 +55,7 @@ class EngineApiTest(HeatTestCase): def test_timeout_extract_negative(self): p = {'timeout_mins': '-100'} error = self.assertRaises(ValueError, api.extract_args, p) - self.assertIn('Invalid timeout value', str(error)) + self.assertIn('Invalid timeout value', six.text_type(error)) def test_timeout_extract_not_present(self): args = api.extract_args({}) @@ -70,7 +71,7 @@ class EngineApiTest(HeatTestCase): error = self.assertRaises(ValueError, api.extract_args, p) self.assertEqual( 'Unexpected adopt data "foo". Adopt data must be a dict.', - str(error)) + six.text_type(error)) def test_adopt_stack_data_extract_not_present(self): args = api.extract_args({}) diff --git a/heat/tests/test_fault_middleware.py b/heat/tests/test_fault_middleware.py index ce82904af..cb5dbbf97 100644 --- a/heat/tests/test_fault_middleware.py +++ b/heat/tests/test_fault_middleware.py @@ -11,6 +11,8 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from heat.common import exception as heat_exc from heat.openstack.common.rpc import common as rpc_common from heat.tests.common import HeatTestCase @@ -80,7 +82,8 @@ class FaultMiddlewareTest(HeatTestCase): serialized) wrapper = fault.FaultWrapper(None) msg = wrapper._error(remote_error) - expected_message, expected_traceback = str(remote_error).split('\n', 1) + expected_message, expected_traceback = six.text_type(remote_error).\ + split('\n', 1) expected = {'code': 404, 'error': {'message': expected_message, 'traceback': expected_traceback, @@ -132,7 +135,8 @@ class FaultMiddlewareTest(HeatTestCase): wrapper = fault.FaultWrapper(None) msg = wrapper._error(remote_error) - expected_message, expected_traceback = str(remote_error).split('\n', 1) + expected_message, expected_traceback = six.text_type(remote_error).\ + split('\n', 1) expected = {'code': 404, 'error': {'message': expected_message, 'traceback': expected_traceback, diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index e50eb5757..49f76d434 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -11,6 +11,8 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from heat.common import exception from heat.common import identifier from heat.common import template_format @@ -412,7 +414,7 @@ class HOTemplateTest(HeatTestCase): snippet, tmpl, stack) self.assertEqual( 'Argument to "get_file" must be a string', - str(notStrErr)) + six.text_type(notStrErr)) def test_get_file_missing_files(self): """Test get_file function with no matching key in files section.""" @@ -429,7 +431,7 @@ class HOTemplateTest(HeatTestCase): self.assertEqual( ('No content found in the "files" section for ' 'get_file path: file:///tmp/foo.yaml'), - str(missingErr)) + six.text_type(missingErr)) def test_get_file_nested_does_not_resolve(self): """Test get_file function does not resolve nested calls.""" @@ -465,11 +467,11 @@ class HOTemplateTest(HeatTestCase): #Hot template test keyError = self.assertRaises(KeyError, tmpl.__getitem__, 'parameters') - self.assertIn(err_str, str(keyError)) + self.assertIn(err_str, six.text_type(keyError)) #CFN template test keyError = self.assertRaises(KeyError, tmpl.__getitem__, 'Parameters') - self.assertIn(err_str, str(keyError)) + self.assertIn(err_str, six.text_type(keyError)) def test_parameters_section_not_iterable(self): """ diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index a059ce5d3..ae05ca2fe 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -16,6 +16,7 @@ import os import mock import testtools import yaml +import six from heat.common import config from heat.common import exception @@ -83,7 +84,7 @@ class YamlMinimalTest(HeatTestCase): parse_ex = self.assertRaises(ValueError, template_format.parse, tmpl_str) - self.assertIn(msg_str, str(parse_ex)) + self.assertIn(msg_str, six.text_type(parse_ex)) def test_long_yaml(self): template = {'HeatTemplateFormatVersion': '2012-12-12'}