99
1010import subprocess
1111import unittest
12+ import sys
1213import 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