Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
e6b1dcea
Commit
e6b1dcea
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#52
add type hinting to tests.api.webserver module
parent
a8d394c3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/api/webserver.py
+17
-5
17 additions, 5 deletions
tests/api/webserver.py
with
17 additions
and
5 deletions
tests/api/webserver.py
+
17
−
5
View file @
e6b1dcea
import
asyncio
import
socket
import
ssl
from
typing
import
Tuple
,
Callable
,
Optional
from
aiohttp
import
web
...
...
@@ -7,13 +10,13 @@ from aiohttp import web
# Here is a nice mocking server
class
WebFunctionalSetupMixin
:
def
setUp
(
self
):
def
setUp
(
self
)
->
None
:
self
.
handler
=
None
self
.
runner
=
None
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
self
.
loop
)
def
tearDown
(
self
):
def
tearDown
(
self
)
->
None
:
if
self
.
handler
:
self
.
loop
.
run_until_complete
(
self
.
handler
.
shutdown
())
if
self
.
runner
:
...
...
@@ -24,15 +27,24 @@ class WebFunctionalSetupMixin:
finally
:
asyncio
.
set_event_loop
(
None
)
def
find_unused_port
(
self
):
def
find_unused_port
(
self
)
->
int
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
bind
((
'
127.0.0.1
'
,
0
))
port
=
s
.
getsockname
()[
1
]
s
.
close
()
return
port
async
def
create_server
(
self
,
method
,
path
,
handler
=
None
,
ssl_ctx
=
None
):
async
def
create_server
(
self
,
method
:
str
,
path
:
str
,
handler
:
Optional
[
Callable
]
=
None
,
ssl_ctx
:
Optional
[
ssl
.
SSLContext
]
=
None
)
->
Tuple
[
web
.
Application
,
int
,
str
]:
"""
Create a web server for tests
:param method: HTTP method type
:param path: Url path
:param handler: Callback function
:param ssl_ctx: SSL context (https is used if not None)
:return:
"""
app
=
web
.
Application
()
if
handler
:
app
.
router
.
add_route
(
method
,
path
,
handler
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment