Commits

jordilin  committed 4d18f6b

using mock patch decorator

  • Participants
  • Parent commits 575fbce

Comments (0)

Files changed (1)

File log4client/tests/test_cornermark.py

 from log4tailer import notifications
 from log4tailer.termcolorcodes import TermColorCodes
 from .utils import MemoryWriter
+from mock import patch
 
 
 class PropertiesStub(object):
     return 5
 
 
-def patch_term_num_cols(notifier):
-    notifier.term_num_cols = tcols_callback
-
-
 class TestCornerMark(unittest.TestCase):
     """The purpose of the corner mark is to have an small square in the bottom
     right corner of the terminal to indicate something went wrong.
         cornermark = notifications.CornerMark(10)
         self.assertTrue(getattr(cornermark, 'notify'))
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testWillMarkForSpecifiedTime(self):
-        level = 'FATAL'
         trace = "FATAL there could be an error in the application"
         sys.stdout = MemoryWriter()
         logcolors = LogColors()
         notifier = notifications.CornerMark(10)
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        patch_term_num_cols(notifier)
         padding = self.ttcols - len(notifier.MARK)
         output = padding * " " + termcolors.backgroundemph + notifier.MARK +\
                 termcolors.reset
         notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testWillMarkforSpecifiedTimeandNotAfterwards(self):
-        level = 'FATAL'
         trace = "FATAL there could be an error in the application"
         sys.stdout = MemoryWriter()
         logcolors = LogColors()
         padding = self.ttcols - len(notifier.MARK)
         output = padding * " " + termcolors.backgroundemph + notifier.MARK +\
                 termcolors.reset
-        patch_term_num_cols(notifier)
         notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])
         trace = "INFO this is an info trace"
         notifier.notify(message, anylog)
         self.assertFalse(sys.stdout.captured)
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testNotMarkMarkedNotMark(self):
         trace = "INFO this is an info trace"
         sys.stdout = MemoryWriter()
         padding = self.ttcols - len(notifier.MARK)
         output = padding * " " + termcolors.backgroundemph + notifier.MARK +\
                 termcolors.reset
-        patch_term_num_cols(notifier)
         notifier.notify(message, anylog)
         self.assertFalse(sys.stdout.captured)
 
             return 0
 
         notifier.timer.corner_mark_ellapsed = belowgap
-        level = 'FATAL'
         trace = "FATAL there could be an error in the application"
         message.parse(trace, anylog)
         notifier.notify(message, anylog)
         notifier.notify(message, anylog)
         self.assertFalse(sys.stdout.captured)
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testMarkedFATALMarkedWARNING(self):
         trace = "FATAL this is a fatal trace"
         sys.stdout = MemoryWriter()
                 termcolors.reset
         trace = "WARN this is just a warn"
         message.parse(trace, anylog)
-        patch_term_num_cols(notifier)
         notifier.notify(message, anylog)
         self.assertEquals(output, sys.stdout.captured[2])
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testMarkedTARGET(self):
         logfile = "/any/path/out.log"
         trace = "this is a targeted log trace"
         output = padding * " " + termcolors.oncyanemph + notifier.MARK +\
                 termcolors.reset
         message.parse(trace, anylog)
-        patch_term_num_cols(notifier)
         notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])
 
+    @patch('log4tailer.notifications.term_num_cols', tcols_callback)
     def testMarkedTARGETOverMarkableLevel(self):
         logfile = "/any/path/out.log"
         trace = "this is a FATAL targeted log trace"
         output = padding * " " + termcolors.oncyanemph + notifier.MARK +\
                 termcolors.reset
         message.parse(trace, anylog)
-        patch_term_num_cols(notifier)
         notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])