thingsapi /
things-cli
| 1 | #!/usr/bin/env python3 |
||
| 2 | |||
| 3 | """Module documentation goes here.""" |
||
| 4 | |||
| 5 | import io |
||
| 6 | import sys |
||
| 7 | import unittest |
||
| 8 | |||
| 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[ |
||
|
0 ignored issues
–
show
It seems like
_actions was declared protected and should not be accessed from this context.
Prefixing a member variable 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...
|
|||
| 31 | 1 |
||
|
0 ignored issues
–
show
|
|||
| 32 | ].choices: # noqa # pylint: disable=protected-access |
||
| 33 | if command not in ["feedback", "search", "logtoday", "createdtoday"]: |
||
| 34 | args = parser.parse_args([command]) |
||
| 35 | self._test_main(args, " ") |
||
| 36 | args = parser.parse_args(["-r", command]) |
||
| 37 | self._test_main(args, " ") |
||
| 38 | args = parser.parse_args(["-r", "-o", command]) |
||
| 39 | self._test_main(args, " ") |
||
| 40 | args = parser.parse_args(["-r", "-c", command]) |
||
| 41 | self._test_main(args, ";") |
||
| 42 | args = parser.parse_args(["-r", "-j", command]) |
||
| 43 | self._test_main(args, " ") |
||
| 44 | elif command in ["logtoday"]: |
||
| 45 | args = parser.parse_args([command]) |
||
| 46 | self._test_main(args, "") |
||
| 47 | elif command in ["search"]: |
||
| 48 | args = parser.parse_args([command, "To-Do in Inbox"]) |
||
| 49 | self._test_main(args, "To-Do in Inbox") |
||
| 50 | args = parser.parse_args(["search", "To-Do"]) |
||
| 51 | self._test_main(args, "To-Do in Today") |
||
| 52 | |||
| 53 | def test_noparam(self): |
||
| 54 | """Test no parameter.""" |
||
| 55 | new_out = io.StringIO() |
||
| 56 | old_out = sys.stdout |
||
| 57 | with self.assertRaises(SystemExit): |
||
| 58 | sys.stderr = new_out |
||
| 59 | self.things3_cli.main() |
||
| 60 | sys.stderr = old_out |
||
| 61 | self.assertIn("usage:", new_out.getvalue()) |
||
| 62 | with self.assertRaises(SystemExit): |
||
| 63 | sys.stderr = new_out |
||
| 64 | cli.main() |
||
| 65 | sys.stderr = old_out |
||
| 66 | self.assertIn("usage:", new_out.getvalue()) |
||
| 67 | |||
| 68 | def test_today(self): |
||
| 69 | """Test Today.""" |
||
| 70 | args = self.things3_cli.get_parser().parse_args( |
||
| 71 | ["-d", "tests/main.sqlite", "today"] |
||
| 72 | ) |
||
| 73 | new_out = io.StringIO() |
||
| 74 | old_out = sys.stdout |
||
| 75 | try: |
||
| 76 | sys.stdout = new_out |
||
| 77 | self.things3_cli.main(args) |
||
| 78 | finally: |
||
| 79 | sys.stdout = old_out |
||
| 80 | self.assertIn("To-Do in Today", new_out.getvalue()) |
||
| 81 | |||
| 82 | def test_csv(self): |
||
| 83 | """Test Next via CSV.""" |
||
| 84 | args = self.things3_cli.get_parser().parse_args( |
||
| 85 | ["-d", "tests/main.sqlite", "-c", "anytime"] |
||
| 86 | ) |
||
| 87 | new_out = io.StringIO() |
||
| 88 | old_out = sys.stdout |
||
| 89 | try: |
||
| 90 | sys.stdout = new_out |
||
| 91 | self.things3_cli.main(args) |
||
| 92 | finally: |
||
| 93 | sys.stdout = old_out |
||
| 94 | self.assertIn("E18tg5qepzrQk9J6jQtb5C", new_out.getvalue()) |
||
| 95 | |||
| 96 | def test_json(self): |
||
| 97 | """Test Upcoming via JSON.""" |
||
| 98 | args = self.things3_cli.get_parser().parse_args( |
||
| 99 | ["-d", "tests/main.sqlite", "-j", "upcoming"] |
||
| 100 | ) |
||
| 101 | new_out = io.StringIO() |
||
| 102 | old_out = sys.stdout |
||
| 103 | try: |
||
| 104 | sys.stdout = new_out |
||
| 105 | self.things3_cli.main(args) |
||
| 106 | finally: |
||
| 107 | sys.stdout = old_out |
||
| 108 | self.assertIn("7F4vqUNiTvGKaCUfv5pqYG", new_out.getvalue()) |
||
| 109 | |||
| 110 | |||
| 111 | if __name__ == "__main__": |
||
| 112 | unittest.main() |
||
| 113 |
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: