summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorTerryHowe <terrylhowe@gmail.com>2015-08-09 07:31:34 -0600
committerTerry Howe <terrylhowe@gmail.com>2015-08-13 22:16:10 +0000
commit6c46355734f7a7278b92645e6a465b6e38096daf (patch)
treedec39284f0e12df083e14f28ef48d44f28ca33f6 /openstackclient/tests
parentd828429d6aeb73976d3a2e422477bee2f4b13b64 (diff)
downloadpython-openstackclient-6c46355734f7a7278b92645e6a465b6e38096daf.tar.gz
Optimize log formatting
There is no way to change the configuration variables we want printed in log messages, so format them in the constructor. This will save us from overridding the format method and a couple cpu cycles every log message. This change also moves the _LOG* variables into the formatter since they aren't really globally needed. Change-Id: I706e9db7da3daec20332f9d1533fe665f2739dea Implements: blueprint logging-migration
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/common/test_context.py62
1 files changed, 25 insertions, 37 deletions
diff --git a/openstackclient/tests/common/test_context.py b/openstackclient/tests/common/test_context.py
index 38a4d833..cc213b13 100644
--- a/openstackclient/tests/common/test_context.py
+++ b/openstackclient/tests/common/test_context.py
@@ -107,40 +107,28 @@ class TestContext(utils.TestCase):
simplefilter.assert_called_with("once")
-class Test_LogContext(utils.TestCase):
- def setUp(self):
- super(Test_LogContext, self).setUp()
-
- def test_context(self):
- ctx = context._LogContext()
- self.assertTrue(ctx)
-
- def test_context_to_dict(self):
- ctx = context._LogContext('cloudsName', 'projectName', 'userNmae')
- ctx_dict = ctx.to_dict()
- self.assertEqual('cloudsName', ctx_dict['clouds_name'])
- self.assertEqual('projectName', ctx_dict['project_name'])
- self.assertEqual('userNmae', ctx_dict['username'])
-
-
-class Test_LogContextFormatter(utils.TestCase):
- def setUp(self):
- super(Test_LogContextFormatter, self).setUp()
- self.ctx = context._LogContext('cloudsName', 'projectName', 'userNmae')
- self.addfmt = "%(clouds_name)s %(project_name)s %(username)s"
-
- def test_contextrrormatter(self):
- ctxfmt = context._LogContextFormatter()
- self.assertTrue(ctxfmt)
-
- def test_context_format(self):
- record = mock.MagicMock()
- logging.Formatter.format = mock.MagicMock()
- logging.Formatter.format.return_value = record
-
- ctxfmt = context._LogContextFormatter(context=self.ctx,
- fmt=self.addfmt)
- addctx = ctxfmt.format(record)
- self.assertEqual('cloudsName', addctx.clouds_name)
- self.assertEqual('projectName', addctx.project_name)
- self.assertEqual('userNmae', addctx.username)
+class TestFileFormatter(utils.TestCase):
+ def test_nothing(self):
+ formatter = context._FileFormatter()
+ self.assertEqual(('%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
+ '%(name)s %(message)s'), formatter.fmt)
+
+ def test_options(self):
+ class Opts(object):
+ cloud = 'cloudy'
+ os_project_name = 'projecty'
+ username = 'usernamey'
+ options = Opts()
+ formatter = context._FileFormatter(options=options)
+ self.assertEqual(('%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
+ '%(name)s [cloudy usernamey projecty] %(message)s'),
+ formatter.fmt)
+
+ def test_config(self):
+ config = mock.Mock()
+ config.config = {'cloud': 'cloudy'}
+ config.auth = {'project_name': 'projecty', 'username': 'usernamey'}
+ formatter = context._FileFormatter(config=config)
+ self.assertEqual(('%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
+ '%(name)s [cloudy usernamey projecty] %(message)s'),
+ formatter.fmt)