File: test_parse.py

package info (click to toggle)
tldr-py 0.7.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: python: 503; makefile: 13; sh: 13
file content (59 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import unittest

from unittest import mock

from tldr.parser import parse_page


class TestParse(unittest.TestCase):
    def test_parse_page(self):
        mock_page = (
            '#node\n\n'
            '> Main node command\n\n'
            '- Call an interactive node shell\n\n'
            '`node`\n\n'
            '- Execute node on a JS file\n\n'
            '`node {{FILENAME}}.js`\n\n'
        )
        self._assert_mock_read(mock_page)

    def test_parse_new_syntax_page(self):
        mock_page = (
            'node\n'
            '====\n\n'
            '> Main node command\n\n'
            'Call an interactive node shell\n\n'
            '    node\n\n'
            'Execute node on a JS file\n\n'
            '    node {{FILENAME}}.js\n\n'
        )
        self._assert_mock_read(mock_page)

    def _assert_mock_read(self, page_content):
        mock_config = {
            'colors': {
                'command': 'cyan',
                'description': 'blue',
                'usage': 'green'
            },
            'platform': 'linux',
            'repo_directory': '/tmp/tldr'
        }
        expected_result = (
            '\n'
            '\x1b[0m\x1b[34m  Main node command\n'
            '\x1b[0m\n\x1b[0m\x1b[32m- Call an interactive node shell'
            '\n\x1b[0m\n\x1b[0m\x1b[36m  node\n'
            '\x1b[0m\n\x1b[0m\x1b[32m- Execute node on a JS file\n'
            '\x1b[0m\n\x1b[0m\x1b[36m  node {{FILENAME}}.js\n'
            '\x1b[0m\n\x1b[0m'
        )
        with mock.patch('tldr.parser.get_config', return_value=mock_config):
            with mock.patch('io.open', mock.mock_open(read_data=page_content)):
                result = parse_page('/repo_directory/pages/common/node.md')
                assert ''.join(result) == expected_result