def test_hostnameinconfig(self): logfile = 'out.log' fh = open(logfile, 'w') someLogTraces = ['FATAL> something went wrong', 'ERROR> not so wrong', 'WARN> be careful', 'DEBUG> looking behind the scenes', 'INFO> the app is running'] for line in someLogTraces: fh.write(line + '\n') fh.close() logcolors = LogColors() # using default colors termcolors = TermColorCodes() target = None notifier = notifications.Print(PropertiesMock()) message = Message(logcolors, target) log = Log(logfile) log.openLog() sys.stdout = MemoryWriter() hostname = socket.gethostname() for _ in range(len(someLogTraces)): line = log.readLine() line = line.rstrip() level = line.split('>') message.parse(line, log) output = (hostname + ': ' + logcolors.getLevelColor(level[0]) + line + termcolors.reset) notifier.notify(message, log) self.assertTrue(output in sys.stdout.captured) line = log.readLine() self.assertEqual('', line) message.parse(line, log) self.assertFalse(notifier.notify(message, log))
def testshouldHaveItsOwnColor(self): fh = open('config','w') fh.write(self.logname+'='+'green\n') fh.close() properties = Property('config') properties.parse_properties() log = Log(self.logname,properties) log.openLog() self.assertTrue(log.ownOutputColor) log.closeLog() os.remove(self.config)
def testReportResumeForTwoDifferentLogs(self): log = Log('out.log') log2 = Log('out2.log') arrayLogs = [log, log2] fh = log.openLog() logcolors = LogColors() message = Message(logcolors) resume = reporting.Resume(arrayLogs) for anylog in arrayLogs: self.readAndUpdateLines(anylog, message, resume) outlogReport = resume.logsReport[log.path] expectedOutLogErrorReport = 'error> not so wrong' gotLogTrace = outlogReport['ERROR'][0].split('=>> ')[1] self.assertEquals(expectedOutLogErrorReport, gotLogTrace)
def testReportResumeForTwoDifferentLogs(self): log = Log('out.log') log2 = Log('out2.log') arrayLogs = [log, log2] fh = log.openLog() logcolors = LogColors() message = Message(logcolors) resume = reporting.Resume(arrayLogs) for anylog in arrayLogs: self.readAndUpdateLines(anylog, message, resume) outlogReport = resume.logsReport[log.path] expectedOutLogErrorReport = 'error> not so wrong' gotLogTrace = outlogReport['ERROR'][0].split('=>> ')[1] self.assertEquals(expectedOutLogErrorReport, gotLogTrace)
def testMessage(self): logcolors = LogColors() # using default colors termcolors = TermColorCodes() target = None notifier = notifications.Print() message = Message(logcolors, target) log = Log(self.logfile) log.openLog() sys.stdout = MemoryWriter() #testing Colors with default pauseModes for count in range(len(self.someLogTraces)): line = log.readLine() line = line.rstrip() level = line.split('>') message.parse(line, log) output = (logcolors.getLevelColor(level[0]) + line + termcolors.reset) notifier.notify(message, log) self.assertTrue(output in sys.stdout.captured) line = log.readLine() self.assertEqual('', line) message.parse(line, log) self.assertFalse(notifier.notify(message, log))
def openLog(self): log = Log(self.logname) log.openLog() return log