FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-can/test/test_scripts.py at develop · feuerball/python-can · GitHub
feuerball
/
python-can
Public
forked from
hardbyte/python-can
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-can
/
test
/
test_scripts.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (101 loc) · 3.3 KB
Breadcrumbs
python-can
/
test
/
test_scripts.py
Copy path
File metadata and controls
129 lines (101 loc) · 3.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
"""
This module tests that the scripts are all callable.
"""
import
subprocess
import
unittest
import
sys
import
errno
from
abc
import
ABCMeta
,
abstractmethod
from
.
config
import
*
class
CanScriptTest
(
unittest
.
TestCase
,
metaclass
=
ABCMeta
):
@
classmethod
def
setUpClass
(
cls
):
# clean up the argument list so the call to the main() functions
# in test_does_not_crash() succeeds
sys
.
argv
=
sys
.
argv
[:
1
]
def
test_do_commands_exist
(
self
):
"""This test calls each scripts once and verifies that the help
can be read without any other errors, like the script not being
found.
"""
for
command
in
self
.
_commands
():
try
:
subprocess
.
check_output
(
command
.
split
(),
stderr
=
subprocess
.
STDOUT
,
encoding
=
"utf-8"
,
shell
=
IS_WINDOWS
,
)
except
subprocess
.
CalledProcessError
as
e
:
return_code
=
e
.
returncode
output
=
e
.
output
else
:
return_code
=
0
output
=
"-- NO OUTPUT --"
allowed
=
[
0
,
errno
.
EINVAL
]
self
.
assertIn
(
return_code
,
allowed
,
'Calling "{}" failed (exit code was {} and not SUCCESS/0 or EINVAL/22):
\n
{}'
.
format
(
command
,
return_code
,
output
),
)
def
test_does_not_crash
(
self
):
# test import
module
=
self
.
_import
()
# test main method
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
module
.
main
()
self
.
assertEqual
(
cm
.
exception
.
code
,
errno
.
EINVAL
)
@
abstractmethod
def
_commands
(
self
):
"""Returns an Iterable of commands that should "succeed", meaning they exit
normally (exit code 0) or with the exit code for invalid arguments: EINVAL/22.
"""
pass
@
abstractmethod
def
_import
(
self
):
"""Returns the modue of the script that has a main() function."""
pass
class
TestLoggerScript
(
CanScriptTest
):
def
_commands
(
self
):
commands
=
[
"python -m can.logger --help"
,
"python scripts/can_logger.py --help"
,
]
if
IS_UNIX
:
commands
+=
[
"can_logger.py --help"
]
return
commands
def
_import
(
self
):
import
can
.
logger
as
module
return
module
class
TestPlayerScript
(
CanScriptTest
):
def
_commands
(
self
):
commands
=
[
"python -m can.player --help"
,
"python scripts/can_player.py --help"
,
]
if
IS_UNIX
:
commands
+=
[
"can_player.py --help"
]
return
commands
def
_import
(
self
):
import
can
.
player
as
module
return
module
class
TestLogconvertScript
(
CanScriptTest
):
def
_commands
(
self
):
commands
=
[
"python -m can.logconvert --help"
,
"python scripts/can_logconvert.py --help"
,
]
if
IS_UNIX
:
commands
+=
[
"can_logconvert.py --help"
]
return
commands
def
_import
(
self
):
import
can
.
logconvert
as
module
return
module
# TODO add #390
# this excludes the base class from being executed as a test case itself
del
CanScriptTest
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL