diff options
-rw-r--r-- | doc/source/conf.py | 8 | ||||
-rw-r--r-- | tests/unit/rpc/test_common.py | 8 | ||||
-rw-r--r-- | tests/unit/test_strutils.py | 82 | ||||
-rw-r--r-- | tests/unit/test_wsgi.py | 3 |
4 files changed, 45 insertions, 56 deletions
diff --git a/doc/source/conf.py b/doc/source/conf.py index d126a23..9088cfe 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -24,8 +24,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'Oslo' -copyright = u'2012, OpenStack Foundation' +project = 'Oslo' +copyright = '2012, OpenStack Foundation' # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True @@ -57,8 +57,8 @@ html_last_updated_fmt = os.popen(git_cmd).read() latex_documents = [ ('index', '%s.tex' % project, - u'%s Documentation' % project, - u'OpenStack Foundation', 'manual'), + '%s Documentation' % project, + 'OpenStack Foundation', 'manual'), ] # Example configuration for intersphinx: refer to the Python standard library. diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py index 18951df..1f07ff7 100644 --- a/tests/unit/rpc/test_common.py +++ b/tests/unit/rpc/test_common.py @@ -153,15 +153,15 @@ class RpcCommonTestCase(test_utils.BaseTestCase): 'class': 'FakeUserDefinedException', 'module': self.__class__.__module__, 'tb': ['raise FakeUserDefinedException'], - 'args': (u'fakearg',), - 'kwargs': {u'fakekwarg': u'fake'}, + 'args': ('fakearg',), + 'kwargs': {'fakekwarg': 'fake'}, } serialized = jsonutils.dumps(failure) after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized) self.assertTrue(isinstance(after_exc, FakeUserDefinedException)) - self.assertEqual(after_exc.args, (u'fakearg',)) - self.assertEqual(after_exc.kwargs, {u'fakekwarg': u'fake'}) + self.assertEqual(after_exc.args, ('fakearg',)) + self.assertEqual(after_exc.kwargs, {'fakekwarg': 'fake'}) def test_deserialize_remote_exception_cannot_recreate(self): """Ensure a RemoteError is returned on initialization failure. diff --git a/tests/unit/test_strutils.py b/tests/unit/test_strutils.py index e2c4622..1863c40 100644 --- a/tests/unit/test_strutils.py +++ b/tests/unit/test_strutils.py @@ -16,6 +16,7 @@ # under the License. import mock +import six from openstack.common import strutils from tests import utils @@ -27,44 +28,31 @@ class StrUtilsTest(utils.BaseTestCase): self.assertTrue(strutils.bool_from_string(True)) self.assertFalse(strutils.bool_from_string(False)) - def test_str_bool_from_string(self): - self.assertTrue(strutils.bool_from_string('true')) - self.assertTrue(strutils.bool_from_string('TRUE')) - self.assertTrue(strutils.bool_from_string('on')) - self.assertTrue(strutils.bool_from_string('On')) - self.assertTrue(strutils.bool_from_string('yes')) - self.assertTrue(strutils.bool_from_string('YES')) - self.assertTrue(strutils.bool_from_string('yEs')) - self.assertTrue(strutils.bool_from_string('1')) - - self.assertFalse(strutils.bool_from_string('false')) - self.assertFalse(strutils.bool_from_string('FALSE')) - self.assertFalse(strutils.bool_from_string('off')) - self.assertFalse(strutils.bool_from_string('OFF')) - self.assertFalse(strutils.bool_from_string('no')) - self.assertFalse(strutils.bool_from_string('0')) - self.assertFalse(strutils.bool_from_string('42')) - self.assertFalse(strutils.bool_from_string('This should not be True')) + def _test_bool_from_string(self, c): + self.assertTrue(strutils.bool_from_string(c('true'))) + self.assertTrue(strutils.bool_from_string(c('TRUE'))) + self.assertTrue(strutils.bool_from_string(c('on'))) + self.assertTrue(strutils.bool_from_string(c('On'))) + self.assertTrue(strutils.bool_from_string(c('yes'))) + self.assertTrue(strutils.bool_from_string(c('YES'))) + self.assertTrue(strutils.bool_from_string(c('yEs'))) + self.assertTrue(strutils.bool_from_string(c('1'))) + + self.assertFalse(strutils.bool_from_string(c('false'))) + self.assertFalse(strutils.bool_from_string(c('FALSE'))) + self.assertFalse(strutils.bool_from_string(c('off'))) + self.assertFalse(strutils.bool_from_string(c('OFF'))) + self.assertFalse(strutils.bool_from_string(c('no'))) + self.assertFalse(strutils.bool_from_string(c('0'))) + self.assertFalse(strutils.bool_from_string(c('42'))) + self.assertFalse(strutils.bool_from_string(c( + 'This should not be True'))) + + def test_bool_from_string(self): + self._test_bool_from_string(lambda s: s) def test_unicode_bool_from_string(self): - self.assertTrue(strutils.bool_from_string(u'true')) - self.assertTrue(strutils.bool_from_string(u'TRUE')) - self.assertTrue(strutils.bool_from_string(u'on')) - self.assertTrue(strutils.bool_from_string(u'On')) - self.assertTrue(strutils.bool_from_string(u'yes')) - self.assertTrue(strutils.bool_from_string(u'YES')) - self.assertTrue(strutils.bool_from_string(u'yEs')) - self.assertTrue(strutils.bool_from_string(u'1')) - - self.assertFalse(strutils.bool_from_string(u'false')) - self.assertFalse(strutils.bool_from_string(u'FALSE')) - self.assertFalse(strutils.bool_from_string(u'off')) - self.assertFalse(strutils.bool_from_string(u'OFF')) - self.assertFalse(strutils.bool_from_string(u'no')) - self.assertFalse(strutils.bool_from_string(u'NO')) - self.assertFalse(strutils.bool_from_string(u'0')) - self.assertFalse(strutils.bool_from_string(u'42')) - self.assertFalse(strutils.bool_from_string(u'This should not be True')) + self._test_bool_from_string(six.text_type) def test_other_bool_from_string(self): self.assertFalse(strutils.bool_from_string(mock.Mock())) @@ -76,25 +64,25 @@ class StrUtilsTest(utils.BaseTestCase): def test_safe_decode(self): safe_decode = strutils.safe_decode self.assertRaises(TypeError, safe_decode, True) - self.assertEqual(u'ni\xf1o', safe_decode("ni\xc3\xb1o", - incoming="utf-8")) - self.assertEqual(u"test", safe_decode("dGVzdA==", - incoming='base64')) + self.assertEqual(six.u('ni\xf1o'), safe_decode("ni\xc3\xb1o", + incoming="utf-8")) + self.assertEqual(six.u("test"), safe_decode("dGVzdA==", + incoming='base64')) - self.assertEqual(u"strange", safe_decode('\x80strange', - errors='ignore')) + self.assertEqual(six.u("strange"), safe_decode('\x80strange', + errors='ignore')) - self.assertEqual(u'\xc0', safe_decode('\xc0', - incoming='iso-8859-1')) + self.assertEqual(six.u('\xc0'), safe_decode('\xc0', + incoming='iso-8859-1')) # Forcing incoming to ascii so it falls back to utf-8 - self.assertEqual(u'ni\xf1o', safe_decode('ni\xc3\xb1o', - incoming='ascii')) + self.assertEqual(six.u('ni\xf1o'), safe_decode('ni\xc3\xb1o', + incoming='ascii')) def test_safe_encode(self): safe_encode = strutils.safe_encode self.assertRaises(TypeError, safe_encode, True) - self.assertEqual("ni\xc3\xb1o", safe_encode(u'ni\xf1o', + self.assertEqual("ni\xc3\xb1o", safe_encode(six.u('ni\xf1o'), encoding="utf-8")) self.assertEqual("dGVzdA==\n", safe_encode("test", encoding='base64')) diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py index 94d8092..a3a4d32 100644 --- a/tests/unit/test_wsgi.py +++ b/tests/unit/test_wsgi.py @@ -21,6 +21,7 @@ import urllib2 import mock import routes +import six import webob from openstack.common import exception @@ -189,7 +190,7 @@ class JSONDictSerializerTest(utils.BaseTestCase): def test_object_unicode(self): class TestUnicode: def __unicode__(self): - return u'TestUnicode' + return six.u('TestUnicode') input_dict = dict(cls=TestUnicode()) expected_str = '{"cls":"TestUnicode"}' serializer = wsgi.JSONDictSerializer() |