How to use the ansi2html.util.read_to_unicode function in ansi2html

To help you get started, we’ve selected a few ansi2html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_conversion(self):
        for input_filename, expected_output_filename in (
                ("ansicolor.txt", "ansicolor.html"),
                ("ansicolor_eix.txt", "ansicolor_eix.html"),
                ):
            with open(join(_here, input_filename), "rb") as input:
                test_data = "".join(read_to_unicode(input))

            with open(join(_here, expected_output_filename), "rb") as output:
                expected_data = [e.rstrip('\n') for e in read_to_unicode(output)]

            html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True).split("\n")
            if html and html[-1] == '':
                html = html[:-1]

            self.assertEqual(
                '\n'.join(html),
                '\n'.join(expected_data))
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_unicode(self):
        """ Ensure that the converter returns unicode(py2)/str(py3) objs. """

        with open(join(_here, "ansicolor.txt"), "rb") as input:
            test_data = "".join(read_to_unicode(input))

        html = Ansi2HTMLConverter().convert(test_data).split("\n")

        for chunk in html:
            assert isinstance(chunk, six.text_type)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_conversion(self):
        for input_filename, expected_output_filename in (
                ("ansicolor.txt", "ansicolor.html"),
                ("ansicolor_eix.txt", "ansicolor_eix.html"),
                ):
            with open(join(_here, input_filename), "rb") as input:
                test_data = "".join(read_to_unicode(input))

            with open(join(_here, expected_output_filename), "rb") as output:
                expected_data = [e.rstrip('\n') for e in read_to_unicode(output)]

            html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True).split("\n")
            if html and html[-1] == '':
                html = html[:-1]

            self.assertEqual(
                '\n'.join(html),
                '\n'.join(expected_data))
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
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)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
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)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_produce_headers(self):
        conv = Ansi2HTMLConverter()
        headers = conv.produce_headers()

        inputfile = join(_here, "produce_headers.txt")
        with open(inputfile, "rb") as produce_headers:
            expected_data = read_to_unicode(produce_headers)

        self.assertMultiLineEqual(headers, ''.join(expected_data))
github sethsec / celerystalk / lib / report.py View on Github external
def convert_file_contents_to_html2(normalized_output_file):
    #conv = Ansi2HTMLConverter()
    with open(normalized_output_file, "rb") as scan_file:
        test_data = "".join(read_to_unicode(scan_file))
        #expected_data = [e.rstrip('\n') for e in read_to_unicode(scan_file)]
        html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True)

    return html