예제 #1
0
    def test_ignore_lines(self, block_start, block_end,
                          expected_ignored_lines):

        text = textwrap.dedent('''\
    ```
    Filler
    ```

    ```Same line```

    <pre>{% html %}
    Output
    multiline{% endhtml %}</pre>

    ```python
    Downer
    ```
    ''')

        filters = [
            parser.IgnoreLineInBlock(start, end)
            for start, end in zip(block_start, block_end)
        ]

        ignored_lines = []
        for line in text.splitlines():
            if any(filter_block(line) for filter_block in filters):
                ignored_lines.append(line)

        self.assertEqual('\n'.join(ignored_lines), expected_ignored_lines)
예제 #2
0
    def test_clean_text(self):
        text = textwrap.dedent('''\
    ```
    Ignore lines here.
    ```
    Useful information.
    Don't ignore.
    ```python
    Ignore here too.
    ```
    Stuff.
    ```Not useful.```
    ''')

        filters = [parser.IgnoreLineInBlock('```', '```')]

        clean_text = []
        for line in text.splitlines():
            if not any(filter_block(line) for filter_block in filters):
                clean_text.append(line)

        expected_clean_text = 'Useful information.\nDon\'t ignore.\nStuff.'

        self.assertEqual('\n'.join(clean_text), expected_clean_text)