Skip to content

Commit d998c4f

Browse files
committed
better tests for scripts
1 parent 6020d5f commit d998c4f

1 file changed

Lines changed: 40 additions & 17 deletions

File tree

test/test_scripts.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# coding: utf-8
33

44
"""
5-
This module tests that the scripts are callable.
5+
This module tests that the scripts are all callable.
66
"""
77

88
from __future__ import absolute_import
@@ -11,32 +11,55 @@
1111
import unittest
1212

1313

14-
#: these are commands that should return successfully
15-
COMMANDS = (
16-
"can_logger.py --help",
17-
"python -m can.logger --help",
18-
"python -m can.scripts.logger --help",
19-
20-
"can_player.py --help",
21-
"python -m can.player --help",
22-
"python -m can.scripts.player --help",
23-
24-
# TODO add #390
25-
)
26-
27-
28-
class TestCanScripts(unittest.TestCase):
14+
class TestCanScript(object):
2915

3016
def do_commands_exist(self):
3117
"""This test calls each scripts once and veifies that the help
3218
can be read without any errors.
3319
"""
34-
for command in COMMANDS:
20+
for command in self._commands():
3521
try:
3622
subprocess.check_output(COMMANDS.spli(), stderr=subprocess.STDOUT)
3723
except subprocess.CalledProcessError as e:
3824
self.fail('Calling "{}" failed:\n{}'.format(command, e.output))
3925

26+
def does_not_crash(self):
27+
# test import
28+
module = self._import()
29+
# test main method
30+
module.main()
31+
32+
33+
class TestLoggerScript(unittest.TestCase, TestCanScript):
34+
35+
def _commands(self):
36+
return (
37+
"can_logger.py --help",
38+
"python -m can.logger --help",
39+
"python -m can.scripts.logger --help"
40+
)
41+
42+
def _import(self):
43+
import can.scripts.logger as module
44+
return module
45+
46+
47+
class TestPlayerScript(unittest.TestCase, TestCanScript):
48+
49+
def _commands(self):
50+
return (
51+
"can_player.py --help",
52+
"python -m can.player --help",
53+
"python -m can.scripts.player --help"
54+
)
55+
56+
def _import(self):
57+
import can.scripts.player as module
58+
return module
59+
60+
61+
# TODO add #390
62+
4063

4164
if __name__ == '__main__':
4265
unittest.main()

0 commit comments

Comments
 (0)