<commit_before># -*- coding: utf-8 -*-

import sys
from docutils import nodes
from textwrap import dedent
from sphinxcontrib.markdown import md2node

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest


class TestSphinxcontrib(unittest.TestCase):
    def test_simple(self):
        markdown = u"""
        # Headings

        Hello world
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))

        self.assertIsInstance(doc[0], nodes.section)
        self.assertEqual(2, len(doc[0]))
        self.assertIsInstance(doc[0][0], nodes.title)
        self.assertEqual(1, len(doc[0][0]))
        self.assertIsInstance(doc[0][0][0], nodes.Text)
        self.assertEqual('Headings', doc[0][0][0])

        self.assertIsInstance(doc[0][1], nodes.paragraph)
        self.assertEqual(1, len(doc[0][1]))
        self.assertIsInstance(doc[0][1][0], nodes.Text)
        self.assertEqual('Hello world', doc[0][1][0])

    def test_multiple_sections(self):
        markdown = u"""
        # Headings 1

        Hello 1

        ## Headings 1-1

        Hello 1-1

        # Headings 2

        Hello 2

        ## Headings 2-1

        Hello 2-1

        ## Headings 2-2

        Hello 2-2
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(2, len(doc))

        section1 = doc[0]
        self.assertIsInstance(section1, nodes.section)
        self.assertEqual('Headings 1', section1[0].astext())
        self.assertEqual('Hello 1', section1[1].astext())
        self.assertIsInstance(section1[2], nodes.section)
        self.assertEqual('Headings 1-1', section1[2][0].astext())
        self.assertEqual('Hello 1-1', section1[2][1].astext())

        section2 = doc[1]
        self.assertIsInstance(section2, nodes.section)
        self.assertEqual('Headings 2', section2[0].astext())
        self.assertEqual('Hello 2', section2[1].astext())
        self.assertIsInstance(section2[2], nodes.section)
        self.assertEqual('Headings 2-1', section2[2][0].astext())
        self.assertEqual('Hello 2-1', section2[2][1].astext())
        self.assertIsInstance(section2[3], nodes.section)
        self.assertEqual('Headings 2-2', section2[3][0].astext())
        self.assertEqual('Hello 2-2', section2[3][1].astext())

    def test_deep_sections(self):
        markdown = u"""
        # Headings 1
        ## Headings 2
        ### Headings 3
        #### Headings 4
        ##### Headings 5
        ###### Headings 6
        ####### Headings 7
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))

        self.assertIsInstance(doc[0], nodes.section)
        self.assertEqual('Headings 1', doc[0][0].astext())
        self.assertIsInstance(doc[0][1], nodes.section)
        self.assertEqual('Headings 2', doc[0][1][0].astext())
        self.assertIsInstance(doc[0][1][1], nodes.section)
        self.assertEqual('Headings 3', doc[0][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1], nodes.section)
        self.assertEqual('Headings 4', doc[0][1][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1][1], nodes.section)
        self.assertEqual('Headings 5', doc[0][1][1][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1][1][1], nodes.section)
        self.assertEqual('Headings 6', doc[0][1][1][1][1][1][0].astext())

        # 7th level headings is recognized as 6th level in markdown-py
        self.assertIsInstance(doc[0][1][1][1][1][2], nodes.section)
        self.assertEqual('# Headings 7', doc[0][1][1][1][1][2][0].astext())

    def test_bullet_list(self):
        markdown = u"""
        # Headings

        * Item 1
        * Item 2
        * Item 3
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))<commit_msg>Add testcase for setext headers<commit_after># -*- coding: utf-8 -*-

import sys
from docutils import nodes
from textwrap import dedent
from sphinxcontrib.markdown import md2node

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest


class TestSphinxcontrib(unittest.TestCase):
    def test_simple(self):
        markdown = u"""
        # Headings

        Hello world
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))

        self.assertIsInstance(doc[0], nodes.section)
        self.assertEqual(2, len(doc[0]))
        self.assertIsInstance(doc[0][0], nodes.title)
        self.assertEqual(1, len(doc[0][0]))
        self.assertIsInstance(doc[0][0][0], nodes.Text)
        self.assertEqual('Headings', doc[0][0][0])

        self.assertIsInstance(doc[0][1], nodes.paragraph)
        self.assertEqual(1, len(doc[0][1]))
        self.assertIsInstance(doc[0][1][0], nodes.Text)
        self.assertEqual('Hello world', doc[0][1][0])

    def test_multiple_sections(self):
        markdown = u"""
        # Headings 1

        Hello 1

        ## Headings 1-1

        Hello 1-1

        # Headings 2

        Hello 2

        ## Headings 2-1

        Hello 2-1

        ## Headings 2-2

        Hello 2-2
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(2, len(doc))

        section1 = doc[0]
        self.assertIsInstance(section1, nodes.section)
        self.assertEqual('Headings 1', section1[0].astext())
        self.assertEqual('Hello 1', section1[1].astext())
        self.assertIsInstance(section1[2], nodes.section)
        self.assertEqual('Headings 1-1', section1[2][0].astext())
        self.assertEqual('Hello 1-1', section1[2][1].astext())

        section2 = doc[1]
        self.assertIsInstance(section2, nodes.section)
        self.assertEqual('Headings 2', section2[0].astext())
        self.assertEqual('Hello 2', section2[1].astext())
        self.assertIsInstance(section2[2], nodes.section)
        self.assertEqual('Headings 2-1', section2[2][0].astext())
        self.assertEqual('Hello 2-1', section2[2][1].astext())
        self.assertIsInstance(section2[3], nodes.section)
        self.assertEqual('Headings 2-2', section2[3][0].astext())
        self.assertEqual('Hello 2-2', section2[3][1].astext())

    def test_deep_sections(self):
        markdown = u"""
        # Headings 1
        ## Headings 2
        ### Headings 3
        #### Headings 4
        ##### Headings 5
        ###### Headings 6
        ####### Headings 7
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))

        self.assertIsInstance(doc[0], nodes.section)
        self.assertEqual('Headings 1', doc[0][0].astext())
        self.assertIsInstance(doc[0][1], nodes.section)
        self.assertEqual('Headings 2', doc[0][1][0].astext())
        self.assertIsInstance(doc[0][1][1], nodes.section)
        self.assertEqual('Headings 3', doc[0][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1], nodes.section)
        self.assertEqual('Headings 4', doc[0][1][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1][1], nodes.section)
        self.assertEqual('Headings 5', doc[0][1][1][1][1][0].astext())
        self.assertIsInstance(doc[0][1][1][1][1][1], nodes.section)
        self.assertEqual('Headings 6', doc[0][1][1][1][1][1][0].astext())

        # 7th level headings is recognized as 6th level in markdown-py
        self.assertIsInstance(doc[0][1][1][1][1][2], nodes.section)
        self.assertEqual('# Headings 7', doc[0][1][1][1][1][2][0].astext())

    def test_setext_header(self):
        markdown = u"""
        Headings
        --------

        Hello world
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))

        self.assertIsInstance(doc[0], nodes.section)
        self.assertEqual(2, len(doc[0]))
        self.assertIsInstance(doc[0][0], nodes.title)
        self.assertEqual(1, len(doc[0][0]))
        self.assertIsInstance(doc[0][0][0], nodes.Text)
        self.assertEqual('Headings', doc[0][0][0])

        self.assertIsInstance(doc[0][1], nodes.paragraph)
        self.assertEqual(1, len(doc[0][1]))
        self.assertIsInstance(doc[0][1][0], nodes.Text)
        self.assertEqual('Hello world', doc[0][1][0])

    def test_bullet_list(self):
        markdown = u"""
        # Headings

        * Item 1
        * Item 2
        * Item 3
        """
        doc = md2node(dedent(markdown))
        self.assertIsInstance(doc, nodes.container)
        self.assertEqual(1, len(doc))
{'fraction_non_alphanumeric': 0.16442839408644622, 'fraction_numerical': 0.04548019410901704, 'mean_word_length': 2.6817615288741172, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2228769', 'n_tokens_mistral': 2940, 'n_tokens_neox': 2791, 'n_words': 487}