Use format instead of % for string formatting
As part of keeping Marconi forward compatible, this change replaces the usage of % for string formatting with .format. Change-Id: Ie2b1c95f4527339953aa57cceb9b39b0988bef26
This commit is contained in:
parent
98d5487e4c
commit
34f1d68f2e
10
HACKING.rst
10
HACKING.rst
@ -62,8 +62,8 @@ Example::
|
|||||||
|
|
||||||
if width == 0 and height == 0 and (color == 'red' or
|
if width == 0 and height == 0 and (color == 'red' or
|
||||||
emphasis is None):
|
emphasis is None):
|
||||||
raise ValueError("I don't think so -- values are %s, %s" %
|
raise ValueError("I don't think so -- values are {0}, {1}".format(
|
||||||
(width, height))
|
width, height))
|
||||||
|
|
||||||
msg = ('this is a very long string that goes on and on and on and'
|
msg = ('this is a very long string that goes on and on and on and'
|
||||||
'on and on and on...')
|
'on and on and on...')
|
||||||
@ -232,7 +232,7 @@ template string then do the replacement.
|
|||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
msg = _("Missing parameter: %s") % ("flavor",)
|
msg = _("Missing parameter: {0}").format("flavor",)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
|
|
||||||
If you have multiple variables to place in the string, use keyword parameters.
|
If you have multiple variables to place in the string, use keyword parameters.
|
||||||
@ -240,8 +240,8 @@ This helps our translators reorder parameters when needed.
|
|||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
msg = _("The server with id %(s_id)s has no key %(m_key)s")
|
msg = _("The server with id {s_id} has no key {m_key}")
|
||||||
LOG.error(msg % {"s_id": "1234", "m_key": "imageId"})
|
LOG.error(msg.format(s_id=1234", m_key=imageId"))
|
||||||
|
|
||||||
|
|
||||||
Creating Unit Tests
|
Creating Unit Tests
|
||||||
|
@ -30,10 +30,10 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
super(TestClaims, self).setUp()
|
super(TestClaims, self).setUp()
|
||||||
|
|
||||||
self.queue = uuid.uuid1()
|
self.queue = uuid.uuid1()
|
||||||
self.queue_url = ("%(url)s/%(version)s/queues/%(queue)s" %
|
self.queue_url = ("{url}/{version}/queues/{queue}".format(
|
||||||
{'url': self.cfg.marconi.url,
|
url=self.cfg.marconi.url,
|
||||||
'version': self.cfg.marconi.version,
|
version=self.cfg.marconi.version,
|
||||||
'queue': self.queue})
|
queue=self.queue))
|
||||||
|
|
||||||
self.client.put(self.queue_url)
|
self.client.put(self.queue_url)
|
||||||
|
|
||||||
|
@ -29,10 +29,10 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
super(TestMessages, self).setUp()
|
super(TestMessages, self).setUp()
|
||||||
|
|
||||||
self.queue = uuid.uuid1()
|
self.queue = uuid.uuid1()
|
||||||
self.queue_url = ("%(url)s/%(version)s/queues/%(queue)s" %
|
self.queue_url = ("{url}/{version}/queues/{queue}".format(
|
||||||
{'url': self.cfg.marconi.url,
|
url=self.cfg.marconi.url,
|
||||||
'version': self.cfg.marconi.version,
|
version=self.cfg.marconi.version,
|
||||||
'queue': self.queue})
|
queue=self.queue))
|
||||||
|
|
||||||
self.client.put(self.queue_url)
|
self.client.put(self.queue_url)
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestInsertQueue, self).setUp()
|
super(TestInsertQueue, self).setUp()
|
||||||
self.base_url = '%s/%s' % (self.cfg.marconi.url,
|
self.base_url = '{0}/{1}'.format(self.cfg.marconi.url,
|
||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
self.headers_response_empty = set(['location'])
|
self.headers_response_empty = set(['location'])
|
||||||
self.client.set_base_url(self.base_url)
|
self.client.set_base_url(self.base_url)
|
||||||
@ -138,8 +138,8 @@ class TestQueueMetaData(base.FunctionalTestBase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQueueMetaData, self).setUp()
|
super(TestQueueMetaData, self).setUp()
|
||||||
|
|
||||||
self.base_url = '%s/%s' % (self.cfg.marconi.url,
|
self.base_url = '{0}/{1}'.format(self.cfg.marconi.url,
|
||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
|
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
|
||||||
self.client.put(self.queue_url)
|
self.client.put(self.queue_url)
|
||||||
@ -187,8 +187,8 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQueueMisc, self).setUp()
|
super(TestQueueMisc, self).setUp()
|
||||||
|
|
||||||
self.base_url = '%s/%s' % (self.cfg.marconi.url,
|
self.base_url = '{0}/{1}'.format(self.cfg.marconi.url,
|
||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
self.client.set_base_url(self.base_url)
|
self.client.set_base_url(self.base_url)
|
||||||
|
|
||||||
|
@ -36,8 +36,9 @@ class ControllerBaseTest(testing.TestBase):
|
|||||||
self.skipTest('No driver class specified')
|
self.skipTest('No driver class specified')
|
||||||
|
|
||||||
if not issubclass(self.controller_class, self.controller_base_class):
|
if not issubclass(self.controller_class, self.controller_base_class):
|
||||||
self.skipTest('%s is not an instance of %s. Tests not supported' %
|
self.skipTest('{0} is not an instance of {1}. '
|
||||||
(self.controller_class, self.controller_base_class))
|
'Tests not supported'.format(
|
||||||
|
self.controller_class, self.controller_base_class))
|
||||||
|
|
||||||
self.driver = self.driver_class()
|
self.driver = self.driver_class()
|
||||||
self.controller = self.controller_class(self.driver)
|
self.controller = self.controller_class(self.driver)
|
||||||
@ -570,7 +571,7 @@ def _insert_fixtures(controller, queue_name, project=None,
|
|||||||
yield {
|
yield {
|
||||||
'ttl': ttl,
|
'ttl': ttl,
|
||||||
'body': {
|
'body': {
|
||||||
'event': 'Event number %s' % n
|
'event': 'Event number {0}'.format(n)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
controller.post(queue_name, messages(),
|
controller.post(queue_name, messages(),
|
||||||
|
@ -193,8 +193,10 @@ class MongodbMessageTests(base.MessageControllerTest):
|
|||||||
messages_per_queue = gc_threshold
|
messages_per_queue = gc_threshold
|
||||||
nogc_messages_per_queue = gc_threshold - 1
|
nogc_messages_per_queue = gc_threshold - 1
|
||||||
|
|
||||||
projects = ['gc-test-project-%s' % i for i in range(num_projects)]
|
projects = ['gc-test-project-{0}'.format(i)
|
||||||
queue_names = ['gc-test-%s' % i for i in range(num_queues)]
|
for i in range(num_projects)]
|
||||||
|
|
||||||
|
queue_names = ['gc-test-{0}'.format(i) for i in range(num_queues)]
|
||||||
client_uuid = 'b623c53c-cf75-11e2-84e1-a1187188419e'
|
client_uuid = 'b623c53c-cf75-11e2-84e1-a1187188419e'
|
||||||
messages = [{'ttl': 0, 'body': str(i)}
|
messages = [{'ttl': 0, 'body': str(i)}
|
||||||
for i in range(messages_per_queue)]
|
for i in range(messages_per_queue)]
|
||||||
|
@ -122,9 +122,9 @@ class QueueLifecycleBaseTest(base.TestBase):
|
|||||||
def test_too_much_metadata(self):
|
def test_too_much_metadata(self):
|
||||||
self.simulate_put('/v1/queues/fizbat', '7e55e1a7e')
|
self.simulate_put('/v1/queues/fizbat', '7e55e1a7e')
|
||||||
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
||||||
doc = '{"messages": {"ttl": 600}, "padding": "%s"}'
|
doc = '{{"messages": {{"ttl": 600}}, "padding": "{pad}"}}'
|
||||||
padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 2) + 1
|
padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 10) + 1
|
||||||
doc = doc % ('x' * padding_len)
|
doc = doc.format(pad='x' * padding_len)
|
||||||
|
|
||||||
self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc)
|
self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc)
|
||||||
self.assertEquals(self.srmock.status, falcon.HTTP_400)
|
self.assertEquals(self.srmock.status, falcon.HTTP_400)
|
||||||
@ -132,9 +132,9 @@ class QueueLifecycleBaseTest(base.TestBase):
|
|||||||
def test_way_too_much_metadata(self):
|
def test_way_too_much_metadata(self):
|
||||||
self.simulate_put('/v1/queues/fizbat', '7e55e1a7e')
|
self.simulate_put('/v1/queues/fizbat', '7e55e1a7e')
|
||||||
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
||||||
doc = '{"messages": {"ttl": 600}, "padding": "%s"}'
|
doc = '{{"messages": {{"ttl": 600}}, "padding": "{pad}"}}'
|
||||||
padding_len = self.wsgi_cfg.metadata_max_length * 100
|
padding_len = self.wsgi_cfg.metadata_max_length * 100
|
||||||
doc = doc % ('x' * padding_len)
|
doc = doc.format(pad='x' * padding_len)
|
||||||
|
|
||||||
self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc)
|
self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc)
|
||||||
self.assertEquals(self.srmock.status, falcon.HTTP_400)
|
self.assertEquals(self.srmock.status, falcon.HTTP_400)
|
||||||
@ -144,9 +144,9 @@ class QueueLifecycleBaseTest(base.TestBase):
|
|||||||
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
self.assertEquals(self.srmock.status, falcon.HTTP_201)
|
||||||
|
|
||||||
# Set
|
# Set
|
||||||
doc = '{"messages": {"ttl": 600}, "padding": "%s"}'
|
doc = '{{"messages": {{"ttl": 600}}, "padding": "{pad}"}}'
|
||||||
padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 2)
|
padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 2)
|
||||||
doc = doc % ('x' * padding_len)
|
doc = doc.format(pad='x' * padding_len)
|
||||||
self.simulate_put('/v1/queues/fizbat/metadata', '480924', body=doc)
|
self.simulate_put('/v1/queues/fizbat/metadata', '480924', body=doc)
|
||||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||||
|
|
||||||
|
@ -51,12 +51,13 @@ class ValidationTest(base.TestBase):
|
|||||||
# Too long
|
# Too long
|
||||||
metadata_size_uplimit = 64
|
metadata_size_uplimit = 64
|
||||||
|
|
||||||
doc_tmpl = '{"Dragon Torc":"%s"}'
|
doc_tmpl = '{{"Dragon Torc":"{0}"}}'
|
||||||
doc_tmpl_ws = '{ "Dragon Torc" : "%s" }' # with whitespace
|
doc_tmpl_ws = '{{ "Dragon Torc" : "{0}" }}' # with whitespace
|
||||||
envelop_length = len(doc_tmpl % '')
|
envelop_length = len(doc_tmpl.format(''))
|
||||||
|
|
||||||
for tmpl in doc_tmpl, doc_tmpl_ws:
|
for tmpl in doc_tmpl, doc_tmpl_ws:
|
||||||
doc = tmpl % ('0' * (metadata_size_uplimit - envelop_length + 1))
|
gen = '0' * (metadata_size_uplimit - envelop_length + 1)
|
||||||
|
doc = tmpl.format(gen)
|
||||||
self.simulate_put(self.queue_path + '/metadata',
|
self.simulate_put(self.queue_path + '/metadata',
|
||||||
self.project_id,
|
self.project_id,
|
||||||
body=doc)
|
body=doc)
|
||||||
|
Loading…
Reference in New Issue
Block a user