<commit_before>from unittest import TestCase

from packtools.sps.utils import xml_utils

from packtools.sps.models.article_renditions import ArticleRenditions


def generate_xmltree(extralang1, extralang2=None, extralang3=None):
    xml = """
    <article xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="pt">
        <front>
            <article-meta>
                {0}
            </article-meta>
        </front>
        {1}
        {2}
        <body>
            <sec><p>The Eh measurements... <xref ref-type="fig" rid="f01">Figura 1</xref>:</p></sec>
        </body>
    </article>
    """
    return xml_utils.get_xml_tree(xml.format(extralang1, extralang2, extralang3))


class ArticleRenditionsTest(TestCase):
    def test_article_assets_with_one_language(self):
      data = """<article xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang='es'></article>"""
      xmltree = xml_utils.get_xml_tree(data)

      expected = ['es']
      obtained = [r.language for r in ArticleRenditions(xmltree).article_renditions]

      self.assertListEqual(expected, obtained)


    def test_article_assets_with_two_languages(self):
      snippet = """<sub-article xml:lang='es' article-type='translation'><front-stub></front-stub></sub-article>"""
      xmltree = generate_xmltree(snippet)

      expected = ['pt', 'es']
      obtained = [r.language for r in ArticleRenditions(xmltree).article_renditions]

      self.assertListEqual(expected, obtained)<commit_msg>Cria teste para verificar se os três idiomas do XML são detectados<commit_after>from unittest import TestCase

from packtools.sps.utils import xml_utils

from packtools.sps.models.article_renditions import ArticleRenditions


def generate_xmltree(extralang1, extralang2=None, extralang3=None):
    xml = """
    <article xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="pt">
        <front>
            <article-meta>
                {0}
            </article-meta>
        </front>
        {1}
        {2}
        <body>
            <sec><p>The Eh measurements... <xref ref-type="fig" rid="f01">Figura 1</xref>:</p></sec>
        </body>
    </article>
    """
    return xml_utils.get_xml_tree(xml.format(extralang1, extralang2, extralang3))


class ArticleRenditionsTest(TestCase):
    def test_article_assets_with_one_language(self):
      data = """<article xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang='es'></article>"""
      xmltree = xml_utils.get_xml_tree(data)

      expected = ['es']
      obtained = [r.language for r in ArticleRenditions(xmltree).article_renditions]

      self.assertListEqual(expected, obtained)


    def test_article_assets_with_two_languages(self):
      snippet = """<sub-article xml:lang='es' article-type='translation'><front-stub></front-stub></sub-article>"""
      xmltree = generate_xmltree(snippet)

      expected = ['pt', 'es']
      obtained = [r.language for r in ArticleRenditions(xmltree).article_renditions]

      self.assertListEqual(expected, obtained)


    def test_article_assets_with_three_languages(self):
      snippet = """
      <sub-article xml:lang='es' article-type='translation'><front-stub></front-stub></sub-article>
      <sub-article xml:lang='it' article-type='translation'><front-stub></front-stub></sub-article>
      """
      xmltree = generate_xmltree(snippet)

      expected = ['pt', 'es', 'it']
      obtained = [r.language for r in ArticleRenditions(xmltree).article_renditions]

      self.assertListEqual(expected, obtained)
{'fraction_non_alphanumeric': 0.14097042779213323, 'fraction_numerical': 0.012632787826586276, 'mean_word_length': 3.4213197969543145, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 41}, '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': '5378987', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1132, 'n_words': 193}