Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
ALMF
SVLT
Commits
b219399a
Commit
b219399a
authored
5 months ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Test server now has "dummy" endpoints configured, too
parent
66bae8a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
model_server/conf/testing.py
+45
-1
45 additions, 1 deletion
model_server/conf/testing.py
tests/base/test_api.py
+4
-56
4 additions, 56 deletions
tests/base/test_api.py
with
49 additions
and
57 deletions
model_server/conf/testing.py
+
45
−
1
View file @
b219399a
...
...
@@ -6,21 +6,65 @@ from multiprocessing import Process
from
pathlib
import
Path
from
shutil
import
copyfile
from
fastapi
import
APIRouter
import
numpy
as
np
from
pydantic
import
BaseModel
import
requests
from
urllib3
import
Retry
from
.fastapi
import
app
from
..base.accessors
import
GenericImageDataAccessor
,
InMemoryDataAccessor
from
..base.models
import
SemanticSegmentationModel
,
InstanceSegmentationModel
from
..base.session
import
session
from
..base.accessors
import
generate_file_accessor
"""
Configure additional endpoints for testing
"""
test_router
=
APIRouter
(
prefix
=
'
/testing
'
,
tags
=
[
'
testing
'
])
class
BounceBackParams
(
BaseModel
):
par1
:
str
par2
:
list
@test_router.put
(
'
/bounce_back
'
)
def
list_bounce_back
(
params
:
BounceBackParams
):
return
{
'
success
'
:
True
,
'
params
'
:
{
'
par1
'
:
params
.
par1
,
'
par2
'
:
params
.
par2
}}
@test_router.put
(
'
/accessors/dummy_accessor/load
'
)
def
load_dummy_accessor
()
->
str
:
acc
=
InMemoryDataAccessor
(
np
.
random
.
randint
(
0
,
2
**
8
,
size
=
(
512
,
256
,
3
,
7
),
dtype
=
'
uint8
'
)
)
return
session
.
add_accessor
(
acc
)
@test_router.put
(
'
/models/dummy_semantic/load/
'
)
def
load_dummy_model
()
->
dict
:
mid
=
session
.
load_model
(
DummySemanticSegmentationModel
)
session
.
log_info
(
f
'
Loaded model
{
mid
}
'
)
return
{
'
model_id
'
:
mid
}
@test_router.put
(
'
/models/dummy_instance/load/
'
)
def
load_dummy_model
()
->
dict
:
mid
=
session
.
load_model
(
DummyInstanceSegmentationModel
)
session
.
log_info
(
f
'
Loaded model
{
mid
}
'
)
return
{
'
model_id
'
:
mid
}
app
.
include_router
(
test_router
)
class
TestServerBaseClass
(
unittest
.
TestCase
):
"""
Base class for unittests of API functionality. Implements both server and clients for testing.
"""
app_name
=
'
model_server.
base.api
:app
'
app_name
=
'
model_server.
conf.testing
:app
'
def
setUp
(
self
)
->
None
:
import
uvicorn
...
...
This diff is collapsed.
Click to expand it.
tests/base/test_api.py
+
4
−
56
View file @
b219399a
from
pathlib
import
Path
from
fastapi
import
APIRouter
,
FastAPI
import
numpy
as
np
from
pydantic
import
BaseModel
import
model_server.conf.testing
as
conf
from
model_server.base.accessors
import
InMemoryDataAccessor
from
model_server.base.api
import
app
from
model_server.base.session
import
session
from
model_server.conf.testing
import
DummySemanticSegmentationModel
,
DummyInstanceSegmentationModel
from
model_server.conf.testing
import
TestServerBaseClass
czifile
=
conf
.
meta
[
'
image_files
'
][
'
czifile
'
]
"""
Configure additional endpoints for testing
"""
test_router
=
APIRouter
(
prefix
=
'
/testing
'
,
tags
=
[
'
testing
'
])
class
BounceBackParams
(
BaseModel
):
par1
:
str
par2
:
list
@test_router.put
(
'
/bounce_back
'
)
def
list_bounce_back
(
params
:
BounceBackParams
):
return
{
'
success
'
:
True
,
'
params
'
:
{
'
par1
'
:
params
.
par1
,
'
par2
'
:
params
.
par2
}}
@test_router.put
(
'
/accessors/dummy_accessor/load
'
)
def
load_dummy_accessor
()
->
str
:
acc
=
InMemoryDataAccessor
(
np
.
random
.
randint
(
0
,
2
**
8
,
size
=
(
512
,
256
,
3
,
7
),
dtype
=
'
uint8
'
)
)
return
session
.
add_accessor
(
acc
)
@test_router.put
(
'
/models/dummy_semantic/load/
'
)
def
load_dummy_model
()
->
dict
:
mid
=
session
.
load_model
(
DummySemanticSegmentationModel
)
session
.
log_info
(
f
'
Loaded model
{
mid
}
'
)
return
{
'
model_id
'
:
mid
}
@test_router.put
(
'
/models/dummy_instance/load/
'
)
def
load_dummy_model
()
->
dict
:
mid
=
session
.
load_model
(
DummyInstanceSegmentationModel
)
session
.
log_info
(
f
'
Loaded model
{
mid
}
'
)
return
{
'
model_id
'
:
mid
}
app
.
include_router
(
test_router
)
"""
Implement unit testing on extended base app
"""
class
TestServerTestCase
(
conf
.
TestServerBaseClass
):
app_name
=
'
tests.base.test_api:app
'
class
TestApiFromAutomatedClient
(
TestServerBaseClass
):
input_data
=
czifile
class
TestApiFromAutomatedClient
(
TestServerTestCase
):
def
test_trivial_api_response
(
self
):
resp
=
self
.
_get
(
''
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
...
...
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