FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python2-osc/pythonosc/test/test_dispatcher.py at python2 · jeffThompson/python2-osc · GitHub
jeffThompson
/
python2-osc
Public
forked from
mwicat/python2-osc
Notifications
You must be signed in to change notification settings
Fork
0
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
/
test_dispatcher.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (95 loc) · 4.31 KB
Breadcrumbs
python2-osc
/
pythonosc
/
test
/
test_dispatcher.py
Copy path
File metadata and controls
123 lines (95 loc) · 4.31 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
import
unittest
from
pythonosc
import
dispatcher
class
TestDispatcher
(
unittest
.
TestCase
):
def
setUp
(
self
):
super
(
TestDispatcher
,
self
).
setUp
()
self
.
dispatcher
=
dispatcher
.
Dispatcher
()
def
sortAndAssertSequenceEqual
(
self
,
expected
,
result
):
return
self
.
assertSequenceEqual
(
sorted
(
expected
),
sorted
(
result
))
def
test_empty_by_default
(
self
):
self
.
sortAndAssertSequenceEqual
([],
self
.
dispatcher
.
handlers_for_address
(
'/test'
))
def
test_use_default_handler_when_set_and_no_match
(
self
):
handler
=
object
()
self
.
dispatcher
.
set_default_handler
(
handler
)
self
.
sortAndAssertSequenceEqual
([
dispatcher
.
Handler
(
handler
, [])],
self
.
dispatcher
.
handlers_for_address
(
'/test'
))
def
test_simple_map_and_match
(
self
):
handler
=
object
()
self
.
dispatcher
.
map
(
'/test'
,
handler
,
1
,
2
,
3
)
self
.
dispatcher
.
map
(
'/test2'
,
handler
)
self
.
sortAndAssertSequenceEqual
(
[
dispatcher
.
Handler
(
handler
, [
1
,
2
,
3
])],
self
.
dispatcher
.
handlers_for_address
(
'/test'
))
self
.
sortAndAssertSequenceEqual
(
[
dispatcher
.
Handler
(
handler
, [])],
self
.
dispatcher
.
handlers_for_address
(
'/test2'
))
def
test_example_from_spec
(
self
):
addresses
=
[
"/first/this/one"
,
"/second/1"
,
"/second/2"
,
"/third/a"
,
"/third/b"
,
"/third/c"
,
]
for
index
,
address
in
enumerate
(
addresses
):
self
.
dispatcher
.
map
(
address
,
index
)
for
index
,
address
in
enumerate
(
addresses
):
self
.
sortAndAssertSequenceEqual
(
[(
index
, [])],
self
.
dispatcher
.
handlers_for_address
(
address
))
self
.
sortAndAssertSequenceEqual
(
[(
1
, []), (
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/second/?"
))
self
.
sortAndAssertSequenceEqual
(
[(
3
, []), (
4
, []), (
5
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/third/*"
))
def
test_do_not_match_over_slash
(
self
):
self
.
dispatcher
.
map
(
'/foo/bar/1'
,
1
)
self
.
dispatcher
.
map
(
'/foo/bar/2'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[],
self
.
dispatcher
.
handlers_for_address
(
"/*"
))
def
test_match_middle_star
(
self
):
self
.
dispatcher
.
map
(
'/foo/bar/1'
,
1
)
self
.
dispatcher
.
map
(
'/foo/bar/2'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[(
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo/*/2"
))
def
test_match_multiple_stars
(
self
):
self
.
dispatcher
.
map
(
'/foo/bar/1'
,
1
)
self
.
dispatcher
.
map
(
'/foo/bar/2'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[(
1
, []), (
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/*/*/*"
))
def
test_match_address_contains_plus_as_character
(
self
):
self
.
dispatcher
.
map
(
'/footest/bar+tender/1'
,
1
)
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo*/bar+*/*"
))
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo*/bar*/*"
))
def
test_call_correct_dispatcher_on_star
(
self
):
self
.
dispatcher
.
map
(
'/a+b'
,
1
)
self
.
dispatcher
.
map
(
'/aaab'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[(
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
'/aaab'
))
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
'/a+b'
))
def
test_map_star
(
self
):
self
.
dispatcher
.
map
(
'/starbase/*'
,
1
)
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/starbase/bar"
))
def
test_map_root_star
(
self
):
self
.
dispatcher
.
map
(
'/*'
,
1
)
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/anything/matches"
))
def
test_map_double_stars
(
self
):
self
.
dispatcher
.
map
(
'/foo/*/bar/*'
,
1
)
self
.
sortAndAssertSequenceEqual
(
[(
1
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo/wild/bar/wild"
))
self
.
sortAndAssertSequenceEqual
(
[],
self
.
dispatcher
.
handlers_for_address
(
"/foo/wild/nomatch/wild"
))
def
test_multiple_handlers
(
self
):
self
.
dispatcher
.
map
(
'/foo/bar'
,
1
)
self
.
dispatcher
.
map
(
'/foo/bar'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[
dispatcher
.
Handler
(
1
, []),
dispatcher
.
Handler
(
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo/bar"
))
def
test_multiple_handlers_with_wildcard_map
(
self
):
self
.
dispatcher
.
map
(
'/foo/bar'
,
1
)
self
.
dispatcher
.
map
(
'/*'
,
2
)
self
.
sortAndAssertSequenceEqual
(
[
dispatcher
.
Handler
(
1
, []),
dispatcher
.
Handler
(
2
, [])],
self
.
dispatcher
.
handlers_for_address
(
"/foo/bar"
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL