Exemplo n.º 1
0
    def test_conversion_as_command(self, mock_stdout):
        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))

        with patch("sys.stdin", new_callable=lambda: six.StringIO(test_data)):
            main()

        html = mock_stdout.getvalue()

        eq_(len(html), len(expected_data), "Strings are not the same length.")
        eq_(html, expected_data, "Strings are not the same.")
Exemplo n.º 2
0
    def test_conversion(self):
        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 = read_to_unicode(output)

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

        eq_(len(html), len(expected_data))

        for idx in range(len(expected_data)):
            expected = expected_data[idx].strip()
            actual = html[idx].strip()
            self.assertEqual(expected, actual)
Exemplo n.º 3
0
    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))

        def f():
            return StringIO(test_data)

        with patch("sys.stdin", new_callable=f):
            main()

        html = mock_stdout.getvalue()

        self.assertEqual(html, expected_data)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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))
Exemplo n.º 11
0
    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, str)
Exemplo n.º 12
0
    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()

        eq_(len(html), len(expected_data), "Strings are not the same length.")
        eq_(html, expected_data, "Strings are not the same.")
Exemplo n.º 13
0
    def test_produce_headers(self):
        conv = Ansi2HTMLConverter()
        headers = conv.produce_headers().split("\n")

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

        for idx in range(len(expected_data)):
            expected = expected_data[idx].strip()
            actual = headers[idx].strip()
            self.assertEqual(expected, actual)
Exemplo n.º 14
0
    def test_produce_headers(self):
        conv = Ansi2HTMLConverter()
        headers = conv.produce_headers().split("\n")

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

        for idx in range(len(expected_data)):
            expected = expected_data[idx].strip()
            actual = headers[idx].strip()
            self.assertEqual(expected, actual)