Skip to content

Commit

Permalink
Fix flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jan 19, 2017
1 parent 01abf4c commit 7e99337
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 4 additions & 2 deletions python/lsst/log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ def handle(self, record):
logging.Handler.handle(self, record)

def emit(self, record):
Log.getLogger(record.name).logMsg(self.translateLevel(record.levelno), record.filename,
record.funcName, record.lineno, record.msg % record.args)
Log.getLogger(record.name).logMsg(self.translateLevel(record.levelno),
record.filename, record.funcName,
record.lineno,
record.msg % record.args)

def translateLevel(self, levelno):
"""
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/log/logLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ import os
if self.isEnabledFor(level):
frame = inspect.currentframe().f_back # calling method
frame = frame.f_back # original log location
filename=os.path.split(frame.f_code.co_filename)[1]
funcname=inspect.stack()[2][3]
filename = os.path.split(frame.f_code.co_filename)[1]
funcname = inspect.stack()[2][3]
if use_format:
msg=fmt.format(*args, **kwargs) if args or kwargs else fmt
msg = fmt.format(*args, **kwargs) if args or kwargs else fmt
else:
msg=fmt % args if args else fmt
msg = fmt % args if args else fmt
self.logMsg(level, filename, funcname, frame.f_lineno, msg)
}
}
26 changes: 13 additions & 13 deletions tests/testLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def testBasicFormat(self):
with TestLog.StdoutCapture(self.outputFilename):
log.configure()
log.logf(log.getDefaultLoggerName(), log.INFO,
"This is {{INFO}} Item 1: {item[1]}", item=["a", "b", "c"])
"This is {{INFO}} Item 1: {item[1]}",
item=["a", "b", "c"])
log.infof(u"This is {unicode} INFO")
log.tracef("This is TRACE")
log.debugf("This is DEBUG")
Expand Down Expand Up @@ -163,7 +164,7 @@ def testContext(self):
log.debug("This is DEBUG 3")
ctx.setLevel(log.INFO)
self.assertEqual(ctx.getLevel(), log.INFO)
self.assert_(ctx.isEnabledFor(log.INFO))
self.assertTrue(ctx.isEnabledFor(log.INFO))
log.trace("This is TRACE 3a")
log.info("This is INFO 3a")
log.debug("This is DEBUG 3a")
Expand Down Expand Up @@ -244,7 +245,7 @@ def testPattern(self):
DEBUG component testPattern (testLog.py:{0[7]}) testLog.py({0[7]}) - This is DEBUG 4 - {{{{y,foo}}}}
INFO root testPattern (testLog.py:{0[8]}) testLog.py({0[8]}) - This is INFO 5 - {{{{y,foo}}}}
DEBUG root testPattern (testLog.py:{0[9]}) testLog.py({0[9]}) - This is DEBUG 5 - {{{{y,foo}}}}
""".format([x + 208 for x in (0, 1, 8, 9, 14, 15, 18, 19, 22, 23)], __name__)) # noqa line too long
""".format([x + 209 for x in (0, 1, 8, 9, 14, 15, 18, 19, 22, 23)], __name__)) # noqa E501 line too long

def testMDCPutPid(self):
"""
Expand All @@ -259,22 +260,24 @@ def testMDCPutPid(self):
log4j.appender.CA=ConsoleAppender
log4j.appender.CA.layout=PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-5p PID:%X{{PID}} %c %C %M (%F:%L) %l - %m%n
""")
""") # noqa E501 line too long
self.assertGreaterEqual(pid, 0, "Failed to fork")

msg = "This is INFO"
if pid == 0:
self.tempDir = tempfile.mkdtemp()
self.outputFilename = os.path.join(self.tempDir, "log-child.out")
self.outputFilename = os.path.join(self.tempDir,
"log-child.out")
msg += " in child process"
elif pid > 0:
child_pid, child_status = os.wait()
self.assertEqual(child_status, 0, "Child returns incorrect code")
self.assertEqual(child_status, 0,
"Child returns incorrect code")
msg += " in parent process"

with TestLog.StdoutCapture(self.outputFilename):
log.info(msg)
line = 276
line = 279
finally:
log.MDCRemove("PID")

Expand Down Expand Up @@ -398,7 +401,8 @@ def testLoggerLevel(self):
log4j.appender.CA.layout=PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-5p %c (%F)- %m%n
""")
self.assertEqual(log.Log.getLevel(log.Log.getDefaultLogger()), log.TRACE)
self.assertEqual(log.Log.getLevel(log.Log.getDefaultLogger()),
log.TRACE)
logger = log.Log.getLogger("a.b")
self.assertEqual(logger.getName(), "a.b")
logger.trace("This is TRACE")
Expand Down Expand Up @@ -449,9 +453,5 @@ def testMsgWithPercentS(self):
""")


####################################################################################
def main():
unittest.main()

if __name__ == "__main__":
main()
unittest.main()

0 comments on commit 7e99337

Please sign in to comment.