Source

parsehelp / tests / parsehelp_test.py

# -*- coding: utf-8 -*-

from os.path import join
from parsehelp.core.test import BaseTestCase
from parsehelp.core.test import TESTDATA
from parsehelp import parse_help


class TestParseHelp(BaseTestCase):
    def assert_help(self, help_file, data):
        help_file_contents = ''
        with open(help_file) as f:
            help_file_contents = f.read()
        result = parse_help(help_file_contents)
        self.assert_equals(data, result)

    def get_help_contents(self, filename):
        rv = u''
        help_file = join(TESTDATA, 'helps', filename + '.txt')
        with open(help_file) as f:
            rv = f.read()
        return rv

    def test_should_parse_help_from_pip(self):
        # do
        result = parse_help(self.get_help_contents('pip'))

        self.assert_is(type(result), dict)
        self.assert_in('options', result)
        # self.assert_help(
        #     result,
        #     {'options':
        #          [{'keys': ['--version'],
        #            'description': u"show program's version number and exit"}]})