コード例 #1
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 def testShouldColorizeWarningLevelAsWell(self):
     '''test that *warning* keyword gets colorized as well'''
     level = 'WARNING'
     trace = "WARNING there could be an error in the application"
     sys.stdout = Writer()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level)+trace+termcolors.reset
     notifier.notify(message,anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #2
0
 def testnotify(self):
     pattern = re.compile(r'hi, this line to be notified')
     trace = "info hi, this line to be notified"
     level = "INFO"
     notifier = notifications.Filter(pattern)
     sys.stdout = Writer()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     output = logcolors.getLevelColor(level)+trace+termcolors.reset
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #3
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 def testshouldFailColorizeWithBackground(self):
     trace = "FATAL there could be an error in the application"
     level = 'WARN'
     sys.stdout = Writer()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     logcolors.parse_config(PropertiesBackGround())
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level)+trace+termcolors.reset
     notifier.notify(message,anylog)
     self.assertNotEqual(output, sys.stdout.captured[0])
コード例 #4
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 def testshouldColorizefirstLevelFoundignoringSecondinSameTrace(self):
     # Test for fix 5
     # Should give priority to FATAL in next trace
     level = 'FATAL'
     trace = "FATAL there could be an error in the application"
     sys.stdout = Writer()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level)+trace+termcolors.reset
     notifier.notify(message,anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #5
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 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 = Writer()
     #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))
コード例 #6
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 def testshouldColorizeMultilineLogTraces(self):
     trace = 'FATAL> something went wrong\nin here as well'
     trace0, trace1 = trace.split('\n')
     level = 'FATAL'
     termcolors = TermColorCodes()
     # now assert trace0 and trace1 are in FATAL level
     sys.stdout = Writer()
     logcolors = LogColors()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     expectedLogTrace0 = logcolors.getLevelColor(level) + \
             trace0 + termcolors.reset
     expectedLogTrace1 = logcolors.getLevelColor(level) + \
             trace1 + termcolors.reset
     message.parse(trace0, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(expectedLogTrace0, sys.stdout.captured[0])
     self.assertEqual('FATAL', message.messageLevel)        
     message.parse(trace1, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(expectedLogTrace1, sys.stdout.captured[2])
     self.assertEqual('FATAL', message.messageLevel)        
コード例 #7
0
ファイル: test_colors.py プロジェクト: CedricGatay/alerta-jul
 def testLogColorsParseConfig(self):
     logcolors = LogColors()
     logcolors.parse_config(PropertiesMock())
     self.assertFalse(hasattr(logcolors,'one'))
     self.assertFalse(hasattr(logcolors,'two'))