Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_conversion_as_command(self, mock_stdout, mock_argv):
with open(join(_here, "ansicolor.txt"), "rb") as input:
test_data = "".join(read_to_unicode(input))
with open(join(_here, "ansicolor.html"), "rb") as output:
expected_data = "".join(read_to_unicode(output))
if six.PY3:
f = lambda: six.StringIO(test_data)
else:
f = lambda: six.StringIO(test_data.encode('utf-8'))
with patch("sys.stdin", new_callable=f):
main()
html = mock_stdout.getvalue()
self.assertEqual(html, expected_data)
def test_inline_as_command(self, mock_stdout, mock_argv):
test_input = textwrap.dedent(six.u("""
this is
a test
"""))
with patch("sys.stdin", new_callable=lambda: six.StringIO(test_input)):
main()
eq_(mock_stdout.getvalue(), test_input)
def test_partial_as_command(self, mock_stdout, mock_argv):
rainbow = '\x1b[1m\x1b[40m\x1b[31mr\x1b[32ma\x1b[33mi\x1b[34mn\x1b[35mb\x1b[36mo\x1b[37mw\x1b[0m\n'
with patch("sys.stdin", new_callable=lambda: six.StringIO(rainbow)):
main()
html = mock_stdout.getvalue().strip()
if hasattr(html, 'decode'):
html = html.decode('utf-8')
expected = (six.u('<span class="ansi1"></span>') +
six.u('<span class="ansi1 ansi40"></span>') +
six.u('<span class="ansi1 ansi31 ansi40">r</span>') +
six.u('<span class="ansi1 ansi32 ansi40">a</span>') +
six.u('<span class="ansi1 ansi33 ansi40">i</span>') +
six.u('<span class="ansi1 ansi34 ansi40">n</span>') +
six.u('<span class="ansi1 ansi35 ansi40">b</span>') +
six.u('<span class="ansi1 ansi36 ansi40">o</span>') +
six.u('<span class="ansi1 ansi37 ansi40">w</span>'))
assert isinstance(html, six.text_type)