Passed
Push — master ( 2a7579...a2cb78 )
by Alexander
03:00
created

tests.test_things3_cli.Things3CLICase.test_csv()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 1
dl 0
loc 11
rs 9.95
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
import things3.things3_cli as things3_cli
10
11
12
class Things3CLICase(unittest.TestCase):
13
    """Class documentation goes here."""
14
15
    things3_cli = things3_cli.Things3CLI(database='resources/demo.sqlite3')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable things3_cli does not seem to be defined.
Loading history...
16
17
    def test_methods(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
        for command in self.things3_cli.get_parser()._subparsers._actions[1].choices:
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _actions was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
Coding Style Best Practice introduced by
It seems like _subparsers was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
19
            if command != "feedback":
20
                args = self.things3_cli.get_parser().parse_args([command])
21
                new_out = io.StringIO()
22
                old_out = sys.stdout
23
                try:
24
                    sys.stdout = new_out
25
                    self.things3_cli.main(args)
26
                finally:
27
                    sys.stdout = old_out
28
                self.assertIn(" ", new_out.getvalue())
29
30
    def test_today(self):
31
        """Test Today."""
32
        args = self.things3_cli.get_parser().parse_args(['today'])
33
        new_out = io.StringIO()
34
        old_out = sys.stdout
35
        try:
36
            sys.stdout = new_out
37
            self.things3_cli.main(args)
38
        finally:
39
            sys.stdout = old_out
40
        self.assertIn("Today MIT", new_out.getvalue())
41
42
    def test_csv(self):
43
        """Test Next via CSV."""
44
        args = self.things3_cli.get_parser().parse_args(['-c', 'next'])
45
        new_out = io.StringIO()
46
        old_out = sys.stdout
47
        try:
48
            sys.stdout = new_out
49
            self.things3_cli.main(args)
50
        finally:
51
            sys.stdout = old_out
52
        self.assertIn("FBBB5D059751", new_out.getvalue())
53
54
    def test_json(self):
55
        """Test Upcoming via JSON."""
56
        args = self.things3_cli.get_parser().parse_args(['-j', 'upcoming'])
57
        new_out = io.StringIO()
58
        old_out = sys.stdout
59
        try:
60
            sys.stdout = new_out
61
            self.things3_cli.main(args)
62
        finally:
63
            sys.stdout = old_out
64
        self.assertIn("4F7006C4ADF7", new_out.getvalue())
65
66
67
if __name__ == '__main__':
68
    unittest.main()
69