FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-osc/pythonosc/test/test_osc_server.py at main · Ifytech18/python-osc · GitHub
Ifytech18
/
python-osc
Public
forked from
attwad/python-osc
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
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-osc
/
pythonosc
/
test
/
test_osc_server.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (97 loc) · 4.03 KB
Breadcrumbs
python-osc
/
pythonosc
/
test
/
test_osc_server.py
Copy path
File metadata and controls
116 lines (97 loc) · 4.03 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
import
unittest
import
unittest
.
mock
from
pythonosc
import
dispatcher
,
osc_server
_SIMPLE_PARAM_INT_MSG
=
b"/SYNC
\x00
\x00
\x00
"
b",i
\x00
\x00
"
b"
\x00
\x00
\x00
\x04
"
# Regression test for a datagram that should NOT be stripped, ever...
_SIMPLE_PARAM_INT_9
=
b"/debug
\x00
\x00
,i
\x00
\x00
\x00
\x00
\x00
\t
"
_SIMPLE_MSG_NO_PARAMS
=
b"/SYNC
\x00
\x00
\x00
"
class
TestOscServer
(
unittest
.
TestCase
):
def
test_is_valid_request
(
self
):
self
.
assertTrue
(
osc_server
.
_is_valid_request
((
b"#bundle
\x00
foobar"
,)))
self
.
assertTrue
(
osc_server
.
_is_valid_request
((
b"/address/1/2/3,foobar"
,)))
self
.
assertFalse
(
osc_server
.
_is_valid_request
((
b""
,)))
class
TestUDPHandler
(
unittest
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
self
.
dispatcher
=
dispatcher
.
Dispatcher
()
# We do not want to create real UDP connections during unit tests.
self
.
server
=
unittest
.
mock
.
Mock
(
spec
=
osc_server
.
BlockingOSCUDPServer
)
# Need to attach property mocks to types, not objects... weird.
type(
self
.
server
).
dispatcher
=
unittest
.
mock
.
PropertyMock
(
return_value
=
self
.
dispatcher
)
self
.
client_address
=
(
"127.0.0.1"
,
8080
)
def
test_no_match
(
self
):
mock_meth
=
unittest
.
mock
.
MagicMock
()
mock_meth
.
return_value
=
None
self
.
dispatcher
.
map
(
"/foobar"
,
mock_meth
)
osc_server
.
_UDPHandler
(
[
_SIMPLE_PARAM_INT_MSG
,
None
],
self
.
client_address
,
self
.
server
)
self
.
assertFalse
(
mock_meth
.
called
)
def
test_match_with_args
(
self
):
mock_meth
=
unittest
.
mock
.
MagicMock
()
mock_meth
.
return_value
=
None
self
.
dispatcher
.
map
(
"/SYNC"
,
mock_meth
,
1
,
2
,
3
)
osc_server
.
_UDPHandler
(
[
_SIMPLE_PARAM_INT_MSG
,
None
],
self
.
client_address
,
self
.
server
)
mock_meth
.
assert_called_with
(
"/SYNC"
, [
1
,
2
,
3
],
4
)
def
test_match_int9
(
self
):
mock_meth
=
unittest
.
mock
.
MagicMock
()
mock_meth
.
return_value
=
None
self
.
dispatcher
.
map
(
"/debug"
,
mock_meth
)
osc_server
.
_UDPHandler
(
[
_SIMPLE_PARAM_INT_9
,
None
],
self
.
client_address
,
self
.
server
)
self
.
assertTrue
(
mock_meth
.
called
)
mock_meth
.
assert_called_with
(
"/debug"
,
9
)
def
test_match_without_args
(
self
):
mock_meth
=
unittest
.
mock
.
MagicMock
()
mock_meth
.
return_value
=
None
self
.
dispatcher
.
map
(
"/SYNC"
,
mock_meth
)
osc_server
.
_UDPHandler
(
[
_SIMPLE_MSG_NO_PARAMS
,
None
],
self
.
client_address
,
self
.
server
)
mock_meth
.
assert_called_with
(
"/SYNC"
)
def
test_match_default_handler
(
self
):
mock_meth
=
unittest
.
mock
.
MagicMock
()
mock_meth
.
return_value
=
None
self
.
dispatcher
.
set_default_handler
(
mock_meth
)
osc_server
.
_UDPHandler
(
[
_SIMPLE_MSG_NO_PARAMS
,
None
],
self
.
client_address
,
self
.
server
)
mock_meth
.
assert_called_with
(
"/SYNC"
)
def
test_response_no_args
(
self
):
def
respond
(
*
args
,
**
kwargs
):
return
"/SYNC"
mock_sock
=
unittest
.
mock
.
Mock
()
mock_sock
.
sendto
=
unittest
.
mock
.
Mock
()
self
.
dispatcher
.
map
(
"/SYNC"
,
respond
)
osc_server
.
_UDPHandler
(
(
_SIMPLE_PARAM_INT_MSG
,
mock_sock
),
self
.
client_address
,
self
.
server
)
mock_sock
.
sendto
.
assert_called_with
(
b"/SYNC
\00
\00
\00
,
\00
\00
\00
"
, (
"127.0.0.1"
,
8080
)
)
def
test_response_with_args
(
self
):
def
respond
(
*
args
,
**
kwargs
):
return
(
"/SYNC"
,
1
,
"2"
,
3.0
,
)
self
.
dispatcher
.
map
(
"/SYNC"
,
respond
)
mock_sock
=
unittest
.
mock
.
Mock
()
mock_sock
.
sendto
=
unittest
.
mock
.
Mock
()
self
.
dispatcher
.
map
(
"/SYNC"
,
respond
)
osc_server
.
_UDPHandler
(
(
_SIMPLE_PARAM_INT_MSG
,
mock_sock
),
self
.
client_address
,
self
.
server
)
mock_sock
.
sendto
.
assert_called_with
(
b"/SYNC
\00
\00
\00
,isf
\x00
\x00
\x00
\x00
\x00
\x00
\x00
\x01
2
\x00
\x00
\x00
@@
\x00
\x00
"
,
(
"127.0.0.1"
,
8080
),
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL