diff --git a/HACKING.rst b/HACKING.rst index 449227384..05a784b2d 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -62,8 +62,8 @@ Example:: if width == 0 and height == 0 and (color == 'red' or emphasis is None): - raise ValueError("I don't think so -- values are %s, %s" % - (width, height)) + raise ValueError("I don't think so -- values are {0}, {1}".format( + width, height)) msg = ('this is a very long string that goes on and on and on and' 'on and on and on...') @@ -232,7 +232,7 @@ template string then do the replacement. Example:: - msg = _("Missing parameter: %s") % ("flavor",) + msg = _("Missing parameter: {0}").format("flavor",) LOG.error(msg) 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:: - msg = _("The server with id %(s_id)s has no key %(m_key)s") - LOG.error(msg % {"s_id": "1234", "m_key": "imageId"}) + msg = _("The server with id {s_id} has no key {m_key}") + LOG.error(msg.format(s_id=1234", m_key=imageId")) Creating Unit Tests diff --git a/tests/functional/wsgi/v1/test_claims.py b/tests/functional/wsgi/v1/test_claims.py index 35372621c..cee79ba2e 100644 --- a/tests/functional/wsgi/v1/test_claims.py +++ b/tests/functional/wsgi/v1/test_claims.py @@ -30,10 +30,10 @@ class TestClaims(base.FunctionalTestBase): super(TestClaims, self).setUp() self.queue = uuid.uuid1() - self.queue_url = ("%(url)s/%(version)s/queues/%(queue)s" % - {'url': self.cfg.marconi.url, - 'version': self.cfg.marconi.version, - 'queue': self.queue}) + self.queue_url = ("{url}/{version}/queues/{queue}".format( + url=self.cfg.marconi.url, + version=self.cfg.marconi.version, + queue=self.queue)) self.client.put(self.queue_url) diff --git a/tests/functional/wsgi/v1/test_messages.py b/tests/functional/wsgi/v1/test_messages.py index 28e3897db..5e086ac33 100644 --- a/tests/functional/wsgi/v1/test_messages.py +++ b/tests/functional/wsgi/v1/test_messages.py @@ -29,10 +29,10 @@ class TestMessages(base.FunctionalTestBase): super(TestMessages, self).setUp() self.queue = uuid.uuid1() - self.queue_url = ("%(url)s/%(version)s/queues/%(queue)s" % - {'url': self.cfg.marconi.url, - 'version': self.cfg.marconi.version, - 'queue': self.queue}) + self.queue_url = ("{url}/{version}/queues/{queue}".format( + url=self.cfg.marconi.url, + version=self.cfg.marconi.version, + queue=self.queue)) self.client.put(self.queue_url) diff --git a/tests/functional/wsgi/v1/test_queues.py b/tests/functional/wsgi/v1/test_queues.py index c44254ef0..2e1723fcc 100644 --- a/tests/functional/wsgi/v1/test_queues.py +++ b/tests/functional/wsgi/v1/test_queues.py @@ -28,8 +28,8 @@ class TestInsertQueue(base.FunctionalTestBase): def setUp(self): super(TestInsertQueue, self).setUp() - self.base_url = '%s/%s' % (self.cfg.marconi.url, - self.cfg.marconi.version) + self.base_url = '{0}/{1}'.format(self.cfg.marconi.url, + self.cfg.marconi.version) self.headers_response_empty = set(['location']) self.client.set_base_url(self.base_url) @@ -138,8 +138,8 @@ class TestQueueMetaData(base.FunctionalTestBase): def setUp(self): super(TestQueueMetaData, self).setUp() - self.base_url = '%s/%s' % (self.cfg.marconi.url, - self.cfg.marconi.version) + self.base_url = '{0}/{1}'.format(self.cfg.marconi.url, + self.cfg.marconi.version) self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1()) self.client.put(self.queue_url) @@ -187,8 +187,8 @@ class TestQueueMisc(base.FunctionalTestBase): def setUp(self): super(TestQueueMisc, self).setUp() - self.base_url = '%s/%s' % (self.cfg.marconi.url, - self.cfg.marconi.version) + self.base_url = '{0}/{1}'.format(self.cfg.marconi.url, + self.cfg.marconi.version) self.client.set_base_url(self.base_url) diff --git a/tests/storage/base.py b/tests/storage/base.py index 87d887c2f..388110142 100644 --- a/tests/storage/base.py +++ b/tests/storage/base.py @@ -36,8 +36,9 @@ class ControllerBaseTest(testing.TestBase): self.skipTest('No driver class specified') if not issubclass(self.controller_class, self.controller_base_class): - self.skipTest('%s is not an instance of %s. Tests not supported' % - (self.controller_class, self.controller_base_class)) + self.skipTest('{0} is not an instance of {1}. ' + 'Tests not supported'.format( + self.controller_class, self.controller_base_class)) self.driver = self.driver_class() self.controller = self.controller_class(self.driver) @@ -570,7 +571,7 @@ def _insert_fixtures(controller, queue_name, project=None, yield { 'ttl': ttl, 'body': { - 'event': 'Event number %s' % n + 'event': 'Event number {0}'.format(n) }} controller.post(queue_name, messages(), diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index 863ab4d9e..2705435e7 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -193,8 +193,10 @@ class MongodbMessageTests(base.MessageControllerTest): messages_per_queue = gc_threshold nogc_messages_per_queue = gc_threshold - 1 - projects = ['gc-test-project-%s' % i for i in range(num_projects)] - queue_names = ['gc-test-%s' % i for i in range(num_queues)] + projects = ['gc-test-project-{0}'.format(i) + 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' messages = [{'ttl': 0, 'body': str(i)} for i in range(messages_per_queue)] diff --git a/tests/transport/wsgi/test_queue_lifecycle.py b/tests/transport/wsgi/test_queue_lifecycle.py index 42a213db2..5fe4e91c1 100644 --- a/tests/transport/wsgi/test_queue_lifecycle.py +++ b/tests/transport/wsgi/test_queue_lifecycle.py @@ -122,9 +122,9 @@ class QueueLifecycleBaseTest(base.TestBase): def test_too_much_metadata(self): self.simulate_put('/v1/queues/fizbat', '7e55e1a7e') self.assertEquals(self.srmock.status, falcon.HTTP_201) - doc = '{"messages": {"ttl": 600}, "padding": "%s"}' - padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 2) + 1 - doc = doc % ('x' * padding_len) + doc = '{{"messages": {{"ttl": 600}}, "padding": "{pad}"}}' + padding_len = self.wsgi_cfg.metadata_max_length - (len(doc) - 10) + 1 + doc = doc.format(pad='x' * padding_len) self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc) self.assertEquals(self.srmock.status, falcon.HTTP_400) @@ -132,9 +132,9 @@ class QueueLifecycleBaseTest(base.TestBase): def test_way_too_much_metadata(self): self.simulate_put('/v1/queues/fizbat', '7e55e1a7e') 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 - doc = doc % ('x' * padding_len) + doc = doc.format(pad='x' * padding_len) self.simulate_put('/v1/queues/fizbat/metadata', '7e55e1a7e', body=doc) self.assertEquals(self.srmock.status, falcon.HTTP_400) @@ -144,9 +144,9 @@ class QueueLifecycleBaseTest(base.TestBase): self.assertEquals(self.srmock.status, falcon.HTTP_201) # Set - doc = '{"messages": {"ttl": 600}, "padding": "%s"}' + doc = '{{"messages": {{"ttl": 600}}, "padding": "{pad}"}}' 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.assertEquals(self.srmock.status, falcon.HTTP_204) diff --git a/tests/transport/wsgi/test_validation.py b/tests/transport/wsgi/test_validation.py index 1266d7a2e..1aecb42e7 100644 --- a/tests/transport/wsgi/test_validation.py +++ b/tests/transport/wsgi/test_validation.py @@ -51,12 +51,13 @@ class ValidationTest(base.TestBase): # Too long metadata_size_uplimit = 64 - doc_tmpl = '{"Dragon Torc":"%s"}' - doc_tmpl_ws = '{ "Dragon Torc" : "%s" }' # with whitespace - envelop_length = len(doc_tmpl % '') + doc_tmpl = '{{"Dragon Torc":"{0}"}}' + doc_tmpl_ws = '{{ "Dragon Torc" : "{0}" }}' # with whitespace + envelop_length = len(doc_tmpl.format('')) 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.project_id, body=doc)