コード例 #1
0
 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))
コード例 #2
0
    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))