FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-can/test/message_helper.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
/
message_helper.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (57 loc) · 2.45 KB
Breadcrumbs
python-can
/
test
/
message_helper.py
Copy path
File metadata and controls
67 lines (57 loc) · 2.45 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
#!/usr/bin/env python
"""
This module contains a helper for writing test cases that need to compare messages.
"""
from
copy
import
copy
class
ComparingMessagesTestCase
:
"""
Must be extended by a class also extending a unittest.TestCase.
.. note:: This class does not extend unittest.TestCase so it does not get
run as a test itself.
"""
def
__init__
(
self
,
allowed_timestamp_delta
=
0.0
,
preserves_channel
=
True
):
"""
:param float or int or None allowed_timestamp_delta: directly passed to :meth:`can.Message.equals`
:param bool preserves_channel: if True, checks that the channel attribute is preserved
"""
self
.
allowed_timestamp_delta
=
allowed_timestamp_delta
self
.
preserves_channel
=
preserves_channel
def
assertMessageEqual
(
self
,
message_1
,
message_2
):
"""
Checks that two messages are equal, according to the given rules.
"""
if
message_1
.
equals
(
message_2
,
timestamp_delta
=
self
.
allowed_timestamp_delta
):
return
elif
self
.
preserves_channel
:
print
(
f"Comparing: message 1:
{
message_1
!r
}
"
)
print
(
f" message 2:
{
message_2
!r
}
"
)
self
.
fail
(
"messages are unequal with allowed timestamp delta {}"
.
format
(
self
.
allowed_timestamp_delta
)
)
else
:
message_2
=
copy
(
message_2
)
# make sure this method is pure
message_2
.
channel
=
message_1
.
channel
if
message_1
.
equals
(
message_2
,
timestamp_delta
=
self
.
allowed_timestamp_delta
):
return
else
:
print
(
f"Comparing: message 1:
{
message_1
!r
}
"
)
print
(
f" message 2:
{
message_2
!r
}
"
)
self
.
fail
(
"messages are unequal with allowed timestamp delta {} even when ignoring channels"
.
format
(
self
.
allowed_timestamp_delta
)
)
def
assertMessagesEqual
(
self
,
messages_1
,
messages_2
):
"""
Checks the order and content of the individual messages pairwise.
Raises an error if the lengths of the sequences are not equal.
"""
self
.
assertEqual
(
len
(
messages_1
),
len
(
messages_2
),
"the number of messages differs"
)
for
message_1
,
message_2
in
zip
(
messages_1
,
messages_2
):
self
.
assertMessageEqual
(
message_1
,
message_2
)
Back
|
FazBrowse Home
|
New Git URL