[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Add more unittests for bridgedb.util module.
commit 145db3c76f60cf47fb76b6c82049d99ebc2368d6
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Tue Feb 24 08:33:23 2015 +0000
Add more unittests for bridgedb.util module.
---
lib/bridgedb/test/test_util.py | 42 ++++++++++++++++++++++++++++++++++++++++
lib/bridgedb/util.py | 2 +-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/lib/bridgedb/test/test_util.py b/lib/bridgedb/test/test_util.py
index 065c401..272c5b7 100644
--- a/lib/bridgedb/test/test_util.py
+++ b/lib/bridgedb/test/test_util.py
@@ -15,6 +15,7 @@ from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
+import logging
import os
from twisted.mail.smtp import Address
@@ -43,6 +44,15 @@ class MiscLoggingUtilTests(unittest.TestCase):
self.assertEqual(len(logHandlers), 1)
self.assertTrue('console' not in logHandlers)
+ def test_getLogHandlers_disable_logfile(self):
+ """util._getLogHandlers() should return ['console'] if stderr logging
+ is disabled.
+ """
+ logHandlers = util._getLogHandlers(logToFile=False)
+ self.assertIsInstance(logHandlers, list)
+ self.assertEqual(len(logHandlers), 1)
+ self.assertTrue('rotating' not in logHandlers)
+
def test_getRotatingFileHandler(self):
"""_getRotatingFileHandler() should create a file with 0600
permissions (os.ST_WRITE | os.ST_APPEND).
@@ -100,3 +110,35 @@ class LevenshteinDistanceTests(unittest.TestCase):
fuzzyMatch = 4
distance = util.levenshteinDistance(email1.local, email2.local)
self.assertLessEqual(distance, fuzzyMatch)
+
+
+class JustifiedLogFormatterTests(unittest.TestCase):
+ """Unittests for :class:`bridgedb.util.JustifiedLogFormatter`."""
+
+ def setUp(self):
+ # name, level, path, lineno, message, args, exc_info
+ self.record = logging.LogRecord('name', logging.INFO, '/foo/bar/baz',
+ 12345, 'This is a message', None, None)
+
+ def test_util_JustifiedLogFormatter(self):
+ formatter = util.JustifiedLogFormatter()
+ self.assertIsInstance(formatter, logging.Formatter)
+
+ def test_util_JustifiedLogFormatter_logThreads(self):
+ formatter = util.JustifiedLogFormatter(logThreads=True)
+ self.assertIsInstance(formatter, logging.Formatter)
+
+ def test_util_JustifiedLogFormatter_formatCallingFuncName(self):
+ formatter = util.JustifiedLogFormatter()
+ record = formatter._formatCallingFuncName(self.record)
+ self.assertIsInstance(formatter, logging.Formatter)
+ self.assertIsInstance(record, logging.LogRecord)
+
+ def test_util_JustifiedLogFormatter_format(self):
+ formatter = util.JustifiedLogFormatter()
+ formatted = formatter.format(self.record)
+ self.assertIsInstance(formatter, logging.Formatter)
+ self.assertIsInstance(formatted, basestring)
+ self.assertNotEqual(formatted, '')
+ self.assertTrue('INFO' in formatted)
+ self.assertTrue('This is a message' in formatted)
diff --git a/lib/bridgedb/util.py b/lib/bridgedb/util.py
index 63fd5e6..4253d4e 100644
--- a/lib/bridgedb/util.py
+++ b/lib/bridgedb/util.py
@@ -62,7 +62,7 @@ def _getRotatingFileHandler(filename, mode='a', maxBytes=1000000, backupCount=0,
os.chown(filename, uid, gid)
try:
os.chmod(filename, os.ST_WRITE | os.ST_APPEND)
- except AttributeError:
+ except AttributeError: # pragma: no cover
logging.error("""
XXX FIXME: Travis chokes on `os.ST_WRITE` saying that the module doesn't
have that attribute, for some reason:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits