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')
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)
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)
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))
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)
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)
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))
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))
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)
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)