File: basic.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 (55 lines) | stat: -rw-r--r-- 1,711 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os
from os import path
import unittest

from click.testing import CliRunner
from tldr import cli
from unittest import mock


ROOT = path.dirname(path.realpath(__file__))


class BasicTestCase(unittest.TestCase):
    def setUp(self):
        self.repo_dir = path.join(ROOT, 'mock_tldr')
        self.config_path = path.join(self.repo_dir, '.tldrrc')
        os.environ['TLDR_CONFIG_DIR'] = self.repo_dir
        self.runner = CliRunner()
        self.call_init_command()

    def tearDown(self):
        if path.exists(self.config_path):
            os.remove(self.config_path)

    def call_init_command(self, repo_dir=path.join(ROOT, 'mock_tldr'),
                          platform='linux'):
        with mock.patch('click.prompt', side_effect=[repo_dir, platform]):
            result = self.runner.invoke(cli.init)
        return result

    def call_update_command(self):
        with mock.patch('tldr.cli.build_index', return_value=None):
            result = self.runner.invoke(cli.update)
        return result

    def call_find_command(self, command_name, platform):
        command_args = (
            [command_name, '--on', platform] if platform else [command_name])
        result = self.runner.invoke(cli.find, command_args)
        return result

    def call_reindex_command(self):
        result = self.runner.invoke(cli.reindex)
        return result

    def call_locate_command(self, command_name, platform):
        command_args = (
            [command_name, '--on', platform] if platform else [command_name])
        result = self.runner.invoke(cli.locate, command_args)
        return result