FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python2-osc/pythonosc/test/parsing/test_osc_types.py at python2 · ryokomy/python2-osc · GitHub
ryokomy
/
python2-osc
Public
forked from
mwicat/python2-osc
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python2-osc
/
pythonosc
/
test
/
parsing
/
test_osc_types.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
214 lines (153 loc) · 6.36 KB
Breadcrumbs
python2-osc
/
pythonosc
/
test
/
parsing
/
test_osc_types.py
Copy path
File metadata and controls
214 lines (153 loc) · 6.36 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
"""Unit tests for the osc_types module."""
from
decimal
import
Decimal
import
unittest
from
pythonosc
.
parsing
import
ntp
from
pythonosc
.
parsing
import
osc_types
class
TestString
(
unittest
.
TestCase
):
def
test_get_string
(
self
):
cases
=
{
b"A
\x00
\x00
\x00
"
: (
"A"
,
4
),
b"AB
\x00
\x00
"
: (
"AB"
,
4
),
b"ABC
\x00
"
: (
"ABC"
,
4
),
b"ABCD
\x00
\x00
\x00
\x00
"
: (
"ABCD"
,
8
),
b"ABCD
\x00
\x00
\x00
\x00
GARBAGE"
: (
"ABCD"
,
8
),
}
for
dgram
,
expected
in
cases
.
items
():
self
.
assertEqual
(
expected
,
osc_types
.
get_string
(
dgram
,
0
))
def
test_get_string_raises_on_wrong_dgram
(
self
):
cases
=
[
b"
\x00
\x00
\x00
\x00
"
,
b'blablaba'
,
b''
,
b'
\x00
'
,
True
,
]
for
case
in
cases
:
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_string
,
case
,
0
)
def
test_get_string_raises_when_datagram_too_short
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_string
,
b'abc
\x00
'
,
1
)
def
test_get_string_raises_on_wrong_start_index_negative
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_string
,
b'abc
\x00
'
,
-
1
)
class
TestInteger
(
unittest
.
TestCase
):
def
test_get_integer
(
self
):
cases
=
{
b"
\x00
\x00
\x00
\x00
"
: (
0
,
4
),
b"
\x00
\x00
\x00
\x01
"
: (
1
,
4
),
b"
\x00
\x00
\x00
\x02
"
: (
2
,
4
),
b"
\x00
\x00
\x00
\x03
"
: (
3
,
4
),
b"
\x00
\x00
\x01
\x00
"
: (
256
,
4
),
b"
\x00
\x01
\x00
\x00
"
: (
65536
,
4
),
b"
\x01
\x00
\x00
\x00
"
: (
16777216
,
4
),
b"
\x00
\x00
\x00
\x01
GARBAGE"
: (
1
,
4
),
}
for
dgram
,
expected
in
cases
.
items
():
self
.
assertEqual
(
expected
,
osc_types
.
get_int
(
dgram
,
0
))
def
test_get_integer_raises_on_type_error
(
self
):
cases
=
[
b''
,
True
]
for
case
in
cases
:
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_int
,
case
,
0
)
def
test_get_integer_raises_on_wrong_start_index
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_int
,
b'
\x00
\x00
\x00
\x11
'
,
1
)
def
test_get_integer_raises_on_wrong_start_index_negative
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_int
,
b'
\x00
\x00
\x00
\x00
'
,
-
1
)
def
test_datagram_too_short
(
self
):
dgram
=
b'
\x00
'
*
3
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_int
,
dgram
,
2
)
class
TestFloat
(
unittest
.
TestCase
):
def
test_get_float
(
self
):
cases
=
{
b"
\x00
\x00
\x00
\x00
"
: (
0.0
,
4
),
b"?
\x80
\x00
\x00
'"
: (
1.0
,
4
),
b'@
\x00
\x00
\x00
'
: (
2.0
,
4
),
b"
\x00
\x00
\x00
\x00
GARBAGE"
: (
0.0
,
4
),
}
for
dgram
,
expected
in
cases
.
items
():
self
.
assertAlmostEqual
(
expected
,
osc_types
.
get_float
(
dgram
,
0
))
def
test_get_float_raises_on_wrong_dgram
(
self
):
cases
=
[
True
]
for
case
in
cases
:
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_float
,
case
,
0
)
def
test_get_float_raises_on_type_error
(
self
):
cases
=
[
None
]
for
case
in
cases
:
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_float
,
case
,
0
)
def
test_datagram_too_short_pads
(
self
):
dgram
=
b'
\x00
'
*
2
self
.
assertEqual
((
0
,
4
),
osc_types
.
get_float
(
dgram
,
0
))
class
TestBlob
(
unittest
.
TestCase
):
def
test_get_blob
(
self
):
cases
=
{
b"
\x00
\x00
\x00
\x00
"
: (
b""
,
4
),
b"
\x00
\x00
\x00
\x08
stuff
\x00
\x00
\x00
"
: (
b"stuff
\x00
\x00
\x00
"
,
12
),
b"
\x00
\x00
\x00
\x04
\x00
\x00
\x00
\x00
"
: (
b"
\x00
\x00
\x00
\x00
"
,
8
),
b"
\x00
\x00
\x00
\x02
\x00
\x00
\x00
\x00
"
: (
b"
\x00
\x00
"
,
8
),
b"
\x00
\x00
\x00
\x08
stuff
\x00
\x00
\x00
datagramcontinues"
: (
b"stuff
\x00
\x00
\x00
"
,
12
),
}
for
dgram
,
expected
in
cases
.
items
():
self
.
assertEqual
(
expected
,
osc_types
.
get_blob
(
dgram
,
0
))
def
test_get_blob_raises_on_wrong_dgram
(
self
):
cases
=
[
b''
,
True
,
b"
\x00
\x00
\x00
\x08
"
]
for
case
in
cases
:
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_blob
,
case
,
0
)
def
test_get_blob_raises_on_wrong_start_index
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_blob
,
b'
\x00
\x00
\x00
\x11
'
,
1
)
def
test_get_blob_raises_too_short_buffer
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_blob
,
b'
\x00
\x00
\x00
\x11
\x00
\x00
'
,
1
)
def
test_get_blog_raises_on_wrong_start_index_negative
(
self
):
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_blob
,
b'
\x00
\x00
\x00
\x00
'
,
-
1
)
class
TestNTPTimestamp
(
unittest
.
TestCase
):
def
test_immediately_dgram
(
self
):
dgram
=
ntp
.
IMMEDIATELY
self
.
assertEqual
(
osc_types
.
IMMEDIATELY
,
osc_types
.
get_date
(
dgram
,
0
)[
0
])
def
test_origin_of_time
(
self
):
dgram
=
b'
\x00
'
*
8
self
.
assertGreater
(
0
,
osc_types
.
get_date
(
dgram
,
0
)[
0
])
def
test_datagram_too_short
(
self
):
dgram
=
b'
\x00
'
*
8
self
.
assertRaises
(
osc_types
.
ParseError
,
osc_types
.
get_date
,
dgram
,
2
)
def
test_write_date
(
self
):
self
.
assertEqual
(
b'
\x83
\xaa
~
\x83
\x00
\x00
\x05
9'
,
osc_types
.
write_date
(
Decimal
(
'3.1337'
)))
class
TestBuildMethods
(
unittest
.
TestCase
):
def
test_string
(
self
):
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x00
'
,
osc_types
.
write_string
(
''
))
self
.
assertEqual
(
b'A
\x00
\x00
\x00
'
,
osc_types
.
write_string
(
'A'
))
self
.
assertEqual
(
b'AB
\x00
\x00
'
,
osc_types
.
write_string
(
'AB'
))
self
.
assertEqual
(
b'ABC
\x00
'
,
osc_types
.
write_string
(
'ABC'
))
self
.
assertEqual
(
b'ABCD
\x00
\x00
\x00
\x00
'
,
osc_types
.
write_string
(
'ABCD'
))
def
test_string_raises
(
self
):
self
.
assertRaises
(
osc_types
.
BuildError
,
osc_types
.
write_string
,
123
)
def
test_int
(
self
):
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x00
'
,
osc_types
.
write_int
(
0
))
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x01
'
,
osc_types
.
write_int
(
1
))
def
test_int_raises
(
self
):
self
.
assertRaises
(
osc_types
.
BuildError
,
osc_types
.
write_int
,
'no int'
)
def
test_float
(
self
):
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x00
'
,
osc_types
.
write_float
(
0.0
))
self
.
assertEqual
(
b'?
\x00
\x00
\x00
'
,
osc_types
.
write_float
(
0.5
))
self
.
assertEqual
(
b'?
\x80
\x00
\x00
'
,
osc_types
.
write_float
(
1.0
))
self
.
assertEqual
(
b'?
\x80
\x00
\x00
'
,
osc_types
.
write_float
(
1
))
def
test_float_raises
(
self
):
self
.
assertRaises
(
osc_types
.
BuildError
,
osc_types
.
write_float
,
'no float'
)
def
test_blob
(
self
):
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x02
\x00
\x01
\x00
\x00
'
,
osc_types
.
write_blob
(
b'
\x00
\x01
'
))
self
.
assertEqual
(
b'
\x00
\x00
\x00
\x04
\x00
\x01
\x02
\x03
'
,
osc_types
.
write_blob
(
b'
\x00
\x01
\x02
\x03
'
))
def
test_blob_raises
(
self
):
self
.
assertRaises
(
osc_types
.
BuildError
,
osc_types
.
write_blob
,
b''
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL