Skip to content

Commit 132b8a2

Browse files
committed
fix calling of tests
1 parent c677643 commit 132b8a2

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

can/scripts/logger.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def main():
6868
if len(sys.argv) < 2:
6969
parser.print_help(sys.stderr)
7070
import errno
71-
sys.exit(errno.EINVAL)
72-
return
71+
raise SystemExit(errno.EINVAL)
7372

7473
results = parser.parse_args()
7574

can/scripts/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from __future__ import absolute_import, print_function
1212

13+
import sys
1314
import argparse
1415
from datetime import datetime
1516

@@ -59,8 +60,7 @@ def main():
5960
if len(sys.argv) < 2:
6061
parser.print_help(sys.stderr)
6162
import errno
62-
sys.exit(errno.EINVAL)
63-
return
63+
raise SystemExit(errno.EINVAL)
6464

6565
results = parser.parse_args()
6666

test/test_scripts.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,57 @@
99

1010
import subprocess
1111
import unittest
12+
import sys
1213
import errno
14+
from abc import ABCMeta, abstractmethod
1315

16+
from .config import *
1417

15-
class TestCanScript(object):
18+
class CanScriptTest(unittest.TestCase):
1619

17-
def do_commands_exist(self):
20+
@classmethod
21+
def setUpClass(cls):
22+
# clean out the argument list
23+
sys.argv = sys.argv[:1]
24+
25+
__test__ = False
26+
27+
__metaclass__ = ABCMeta
28+
29+
#@unittest.skipUnless(IS_UNIX, "commands may only be available on unix")
30+
def test_do_commands_exist(self):
1831
"""This test calls each scripts once and veifies that the help
1932
can be read without any errors.
2033
"""
2134
for command in self._commands():
2235
try:
23-
subprocess.check_output(COMMANDS.spli(), stderr=subprocess.STDOUT)
36+
subprocess.check_output(command.split(), stderr=subprocess.STDOUT)
2437
except subprocess.CalledProcessError as e:
2538
self.assertEqual(e.returncode, errno.EINVAL,
26-
'Calling "{}" failed:\n{}'.format(command, e.output))
39+
'Calling "{}" failed (exit code was {} and not EINVAL/22):\n{}'
40+
.format(command, e.returncode, e.output))
2741

28-
def does_not_crash(self):
42+
def test_does_not_crash(self):
2943
# test import
3044
module = self._import()
3145
# test main method
32-
module.main()
46+
with self.assertRaises(SystemExit) as cm:
47+
module.main()
48+
self.assertEqual(cm.exception.code, errno.EINVAL,
49+
'Calling main failed:\n{}'.format(command, e.output))
3350

51+
@abstractmethod
52+
def _commands(self):
53+
pass
3454

35-
class TestLoggerScript(unittest.TestCase, TestCanScript):
55+
@abstractmethod
56+
def _import(self):
57+
pass
58+
59+
60+
class TestLoggerScript(CanScriptTest):
61+
62+
__test__ = True
3663

3764
def _commands(self):
3865
return (
@@ -46,7 +73,9 @@ def _import(self):
4673
return module
4774

4875

49-
class TestPlayerScript(unittest.TestCase, TestCanScript):
76+
class TestPlayerScript(CanScriptTest):
77+
78+
__test__ = True
5079

5180
def _commands(self):
5281
return (

0 commit comments

Comments
 (0)