<commit_before>import unittest
from lxml import etree

from nm_printing.renderers.line_mode import (
    _compress_whitespace, _strip_outer_whitespace, LineModeRenderer,
)


class TestLineModeRenderer(unittest.TestCase):
    def test_compress_whitespace(self):
        xml = etree.fromstring("""
        <line>
          <span>
            Word \t<bold>bold</bold>
          </span>
        </line>
        """)
        _compress_whitespace(xml)
        self.assertEqual(
            etree.tostring(xml).decode('utf-8'),
            "<line> <span> Word <bold>bold</bold> </span> </line>"
        )

    def test_strip_outer_whitespace(self):
        def test(src, expected):
            xml = etree.fromstring(src)
            _strip_outer_whitespace(xml)
            self.assertEqual(
                etree.tostring(xml).decode('utf-8'),
                expected
            )

        test("<a> </a>", "<a/>")

        test("<a> text</a>", "<a>text</a>")

        test("<a>text </a>", "<a>text</a>")

        test("<a> <b></b> </a>", "<a><b/></a>")

        test("<a><b> </b></a>", "<a><b/></a>")

        test("<a> text <b></b></a>", "<a>text <b/></a>")

        test("<a><b></b> text <c></c></a>", "<a><b/> text <c/></a>")

        test("<a><b></b> text </a>", "<a><b/> text</a>")

    def test_render_hello(self):
        commands = list(LineModeRenderer("""
        <document>
          <line>
            Hello world
          </line>
        </document>
        """).render(prelude=False))

        self.assertEqual(
            commands,
            [
                ('write', "Hello world"),
                ('write', "\n"),
            ]
        )

    def test_default_charset(self):
        commands = set(LineModeRenderer("""<document></document>""").render())
        self.assertIn(('set-charset', 'ascii'), commands)

    def test_charset(self):
        commands = set(LineModeRenderer(
            """<document charset="euc_jp"></document>"""
        ).render())
        self.assertIn(('set-charset', 'euc_jp'), commands)<commit_msg>test NoOp span<commit_after>import unittest
from lxml import etree

from nm_printing.renderers.line_mode import (
    _compress_whitespace, _strip_outer_whitespace, LineModeRenderer,
)


class TestLineModeRenderer(unittest.TestCase):
    def test_compress_whitespace(self):
        xml = etree.fromstring("""
        <line>
          <span>
            Word \t<bold>bold</bold>
          </span>
        </line>
        """)
        _compress_whitespace(xml)
        self.assertEqual(
            etree.tostring(xml).decode('utf-8'),
            "<line> <span> Word <bold>bold</bold> </span> </line>"
        )

    def test_strip_outer_whitespace(self):
        def test(src, expected):
            xml = etree.fromstring(src)
            _strip_outer_whitespace(xml)
            self.assertEqual(
                etree.tostring(xml).decode('utf-8'),
                expected
            )

        test("<a> </a>", "<a/>")

        test("<a> text</a>", "<a>text</a>")

        test("<a>text </a>", "<a>text</a>")

        test("<a> <b></b> </a>", "<a><b/></a>")

        test("<a><b> </b></a>", "<a><b/></a>")

        test("<a> text <b></b></a>", "<a>text <b/></a>")

        test("<a><b></b> text <c></c></a>", "<a><b/> text <c/></a>")

        test("<a><b></b> text </a>", "<a><b/> text</a>")

    def test_render_hello(self):
        commands = list(LineModeRenderer("""
        <document>
          <line>
            Hello world
          </line>
        </document>
        """).render(prelude=False))

        self.assertEqual(
            commands,
            [
                ('write', "Hello world"),
                ('write', "\n"),
            ]
        )

    def test_render_span(self):
        commands = list(LineModeRenderer("""
        <document>
          <line>
            <span>Hello world</span>
          </line>
        </document>
        """).render(prelude=False))

        self.assertEqual(
            commands,
            [
                ('write', "Hello world"),
                ('write', "\n"),
            ]
        )

    def test_default_charset(self):
        commands = set(LineModeRenderer("""<document></document>""").render())
        self.assertIn(('set-charset', 'ascii'), commands)

    def test_charset(self):
        commands = set(LineModeRenderer(
            """<document charset="euc_jp"></document>"""
        ).render())
        self.assertIn(('set-charset', 'euc_jp'), commands)
{'fraction_non_alphanumeric': 0.19287305122494433, 'fraction_numerical': 0.0008908685968819599, 'mean_word_length': 1.8770019218449712, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 0, '>': 147, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '403905', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1390, 'n_words': 241}