|
2 | 2 | # coding: utf-8 |
3 | 3 |
|
4 | 4 | """ |
5 | | -This module tests that the scripts are callable. |
| 5 | +This module tests that the scripts are all callable. |
6 | 6 | """ |
7 | 7 |
|
8 | 8 | from __future__ import absolute_import |
|
11 | 11 | import unittest |
12 | 12 |
|
13 | 13 |
|
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): |
29 | 15 |
|
30 | 16 | def do_commands_exist(self): |
31 | 17 | """This test calls each scripts once and veifies that the help |
32 | 18 | can be read without any errors. |
33 | 19 | """ |
34 | | - for command in COMMANDS: |
| 20 | + for command in self._commands(): |
35 | 21 | try: |
36 | 22 | subprocess.check_output(COMMANDS.spli(), stderr=subprocess.STDOUT) |
37 | 23 | except subprocess.CalledProcessError as e: |
38 | 24 | self.fail('Calling "{}" failed:\n{}'.format(command, e.output)) |
39 | 25 |
|
| 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 | + |
40 | 63 |
|
41 | 64 | if __name__ == '__main__': |
42 | 65 | unittest.main() |
0 commit comments