Test Failed
Push — master ( 8acdba...7528b8 )
by Alexander
02:40
created

tests.test_things_cli.ThingsCLICase._test_main()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
"""Module documentation goes here."""
5
6
import unittest
7
import io
8
import sys
9
from things_cli import cli
10
11
12
class ThingsCLICase(unittest.TestCase):
13
    """Class documentation goes here."""
14
15
    things3_cli = cli.ThingsCLI(database='tests/main.sqlite')
16
17
    def _test_main(self, args, expected):
18
        new_out = io.StringIO()
19
        old_out = sys.stdout
20
        try:
21
            sys.stdout = new_out
22
            self.things3_cli.main(args)
23
        finally:
24
            sys.stdout = old_out
25
        self.assertIn(expected, new_out.getvalue())
26
27
    def test_methods(self):
28
        """Invoke all commands."""
29
        parser = self.things3_cli.get_parser()
30
        for command in parser._subparsers._actions[1].choices:  # noqa # pylint: disable=protected-access
31
            if command not in ["feedback", "search"]:
32
                args = parser.parse_args([command])
33
                self._test_main(args, " ")
34
        args = parser.parse_args(['search', 'To-Do'])
35
        self._test_main(args, "To-Do in Today")
36
37
    def test_noparam(self):
38
        """Test no parameter."""
39
        new_out = io.StringIO()
40
        old_out = sys.stdout
41
        with self.assertRaises(SystemExit):
42
            sys.stderr = new_out
43
            self.things3_cli.main()
44
        sys.stderr = old_out
45
        self.assertIn("usage:", new_out.getvalue())
46
        with self.assertRaises(SystemExit):
47
            sys.stderr = new_out
48
            cli.main()
49
        sys.stderr = old_out
50
        self.assertIn("usage:", new_out.getvalue())
51
52
    def test_today(self):
53
        """Test Today."""
54
        args = self.things3_cli.get_parser().parse_args(['-d', 'tests/main.sqlite', 'today'])
55
        new_out = io.StringIO()
56
        old_out = sys.stdout
57
        try:
58
            sys.stdout = new_out
59
            self.things3_cli.main(args)
60
        finally:
61
            sys.stdout = old_out
62
        self.assertIn("To-Do in Today", new_out.getvalue())
63
64
    def test_csv(self):
65
        """Test Next via CSV."""
66
        args = self.things3_cli.get_parser().parse_args(['-d', 'tests/main.sqlite', '-c', 'anytime'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
67
        new_out = io.StringIO()
68
        old_out = sys.stdout
69
        try:
70
            sys.stdout = new_out
71
            self.things3_cli.main(args)
72
        finally:
73
            sys.stdout = old_out
74
        self.assertIn("E18tg5qepzrQk9J6jQtb5C", new_out.getvalue())
75
76
    def test_json(self):
77
        """Test Upcoming via JSON."""
78
        args = self.things3_cli.get_parser().parse_args(['-d', 'tests/main.sqlite', '-j', 'upcoming'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
79
        new_out = io.StringIO()
80
        old_out = sys.stdout
81
        try:
82
            sys.stdout = new_out
83
            self.things3_cli.main(args)
84
        finally:
85
            sys.stdout = old_out
86
        self.assertIn("7F4vqUNiTvGKaCUfv5pqYG", new_out.getvalue())
87
88
89
if __name__ == '__main__':
90
    unittest.main()
91