예제 #1
0
 def testHTMLWriteNewlines(self):
     """
     html=True causes write() to transate newlines into '<br>\\n'
     """
     s = StringIO()
     gs = GreenStream(s, html=True)
     gs.write(u'\n')
     self.assertEqual(s.getvalue(), '<br>\n')
예제 #2
0
 def testUnidecodeAppveyor(self, mock_unidecode):
     """
     When I'm on Appveyor, I run text through Unidecode
     """
     mock_unidecode.return_value = 'something'
     s = StringIO()
     gs = GreenStream(s, override_appveyor=True)
     gs.write('something')
     self.assertTrue(mock_unidecode.called)
예제 #3
0
 def testUnidecodeDisabled(self, mock_unidecode):
     """
     Unidecode can be disabled
     """
     mock_unidecode.return_value = 'something'
     s = StringIO()
     gs = GreenStream(s, override_appveyor=True, disable_unidecode=True)
     gs.write('something')
     self.assertFalse(mock_unidecode.called)
예제 #4
0
 def testUnidecodeAppveyor(self, mock_unidecode):
     """
     When I'm on Appveyor, I run text through Unidecode
     """
     mock_unidecode.return_value = 'something'
     s = StringIO()
     gs = GreenStream(s, override_appveyor=True)
     gs.write('something')
     self.assertTrue(mock_unidecode.called)
예제 #5
0
 def testDisableWindowsTrue(self):
     """
     disable_windows=True: ANSI color codes are present in the stream
     """
     c = Colors(termcolor=True)
     s = StringIO()
     gs = GreenStream(s, disable_windows=True)
     msg = c.red("some colored string")
     gs.write(msg)
     self.assertEqual(len(gs.stream.getvalue()), len(msg))
예제 #6
0
 def testDisableWindowsTrue(self):
     """
     disable_windows=True: ANSI color codes are present in the stream
     """
     c = Colors(termcolor=True)
     s = StringIO()
     gs = GreenStream(s, disable_windows=True)
     msg = c.red("some colored string")
     gs.write(msg)
     self.assertEqual(len(gs.stream.getvalue()), len(msg))
예제 #7
0
 def testCoverageDetection(self):
     """
     write() detects a coverage percentage flying by
     """
     s = StringIO()
     gs = GreenStream(s)
     gs.write(
         '\n---------------------------------------------------\nTOTAL                   896    367    59%\nRan'
     )
     self.assertEqual(gs.coverage_percent, 59)
예제 #8
0
 def testBadStringType(self):
     "passing the wrong stream type to GreenStream gets auto-converted"
     s = StringIO()
     gs = GreenStream(s)
     msg = "some string"
     if sys.version_info[0] == 3: # pragma: no cover
         bad_str = bytes(msg, 'utf-8')
     else: # pragma: no cover
         bad_str = str(msg)
     gs.write(bad_str)
     self.assertEqual(s.getvalue(), msg)
예제 #9
0
 def testDisableWindowsFalse(self):
     """
     disable_windows=False: Colorama strips ANSI color codes from the stream
     """
     c = Colors(termcolor=True)
     s = StringIO()
     gs = GreenStream(s, override_appveyor=True, disable_windows=False)
     colored_msg = c.red("a")
     gs.write(colored_msg)
     import colorama
     self.assertTrue(issubclass(type(gs.stream),
                     colorama.ansitowin32.StreamWrapper))
예제 #10
0
 def testDisableWindowsFalse(self):
     """
     disable_windows=False: Colorama strips ANSI color codes from the stream
     """
     c = Colors(termcolor=True)
     s = StringIO()
     gs = GreenStream(s, override_appveyor=True, disable_windows=False)
     colored_msg = c.red("a")
     gs.write(colored_msg)
     import colorama
     self.assertTrue(
         issubclass(type(gs.stream), colorama.ansitowin32.StreamWrapper))
예제 #11
0
 def testBadStringType(self):
     """
     passing the wrong stream type to GreenStream gets auto-converted
     """
     s = StringIO()
     gs = GreenStream(s)
     msg = "some string"
     if sys.version_info[0] == 3:  # pragma: no cover
         bad_str = bytes(msg, 'utf-8')
     else:  # pragma: no cover
         bad_str = str(msg)
     gs.write(bad_str)
     self.assertEqual(s.getvalue(), msg)
예제 #12
0
 def testWritelines(self):
     """
     Compatibility function writelines(lines) repeatedly calls write()
     """
     s = StringIO()
     gs = GreenStream(s)
     gs.write = MagicMock()
     gs.writelines(["one", "two", "three"])
     self.assertEqual(len(gs.write.mock_calls), 3)
예제 #13
0
 def testWritelines(self):
     """
     Compatibility function writelines(lines) repeatedly calls write()
     """
     s = StringIO()
     gs = GreenStream(s)
     gs.write = MagicMock()
     gs.writelines(["one", "two", "three"])
     self.assertEqual(len(gs.write.mock_calls), 3)