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
e8770af6
Commit
e8770af6
authored
8 months ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Removed tests that interact with _Session class, since no longer trying to use singleton
parent
fa7ebaab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
model_server/base/session.py
+4
-3
4 additions, 3 deletions
model_server/base/session.py
tests/test_session.py
+11
-19
11 additions, 19 deletions
tests/test_session.py
with
15 additions
and
22 deletions
model_server/base/session.py
+
4
−
3
View file @
e8770af6
...
...
@@ -13,6 +13,7 @@ from base.models import Model
logger
=
logging
.
getLogger
(
__name__
)
class
Singleton
(
type
):
_instances
=
{}
...
...
@@ -37,7 +38,7 @@ class CsvTable(object):
self
.
empty
=
False
return
True
class
Session
(
object
,
metaclass
=
Singleton
):
class
_
Session
(
object
,
metaclass
=
Singleton
):
"""
Singleton class for a server session that persists data between API calls
"""
...
...
@@ -99,7 +100,7 @@ class Session(object, metaclass=Singleton):
root_path
=
Path
(
conf
.
defaults
.
root
)
else
:
root_path
=
Path
(
root
)
sid
=
Session
.
create_session_id
(
root_path
)
sid
=
_
Session
.
create_session_id
(
root_path
)
paths
=
{
'
root
'
:
root_path
}
for
pk
in
[
'
inbound_images
'
,
'
outbound_images
'
,
'
logs
'
,
'
tables
'
]:
pa
=
root_path
/
sid
/
conf
.
defaults
.
subdirectories
[
pk
]
...
...
@@ -194,7 +195,7 @@ class Session(object, metaclass=Singleton):
# create singleton instance
session
=
Session
()
session
=
_
Session
()
class
Error
(
Exception
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_session.py
+
11
−
19
View file @
e8770af6
...
...
@@ -3,31 +3,20 @@ import pathlib
from
pydantic
import
BaseModel
import
unittest
import
base.session
from
base.models
import
DummySemanticSegmentationModel
from
base.session
import
session
class
TestGetSessionObject
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
session
.
restart
()
self
.
sesh
=
session
def
tearDown
(
self
)
->
None
:
print
(
'
Tearing down...
'
)
session
.
__class__
.
_instances
=
{}
def
test_session_is_singleton
(
self
):
session
.
__class__
.
_instances
=
{}
self
.
assertEqual
(
len
(
session
.
__class__
.
_instances
),
0
)
s
=
session
.
__class__
()
self
.
assertEqual
(
len
(
session
.
__class__
.
_instances
),
1
)
self
.
assertIs
(
s
,
session
.
__class__
())
self
.
assertEqual
(
len
(
session
.
__class__
.
_instances
),
1
)
def
test_session_logfile_is_valid
(
self
):
self
.
assertTrue
(
exists
(
self
.
sesh
.
logfile
),
'
Session did not create a log file in the correct place
'
)
def
test_changing_session_root_creates_new_directory
(
self
):
from
model_server.conf.defaults
import
root
from
shutil
import
rmtree
old_paths
=
self
.
sesh
.
get_paths
()
newroot
=
root
/
'
subdir
'
...
...
@@ -36,12 +25,6 @@ class TestGetSessionObject(unittest.TestCase):
for
k
in
old_paths
.
keys
():
self
.
assertTrue
(
new_paths
[
k
].
__str__
().
startswith
(
newroot
.
__str__
()))
# this is necessary because logger itself is a singleton class
self
.
tearDown
()
self
.
setUp
()
rmtree
(
newroot
)
self
.
assertFalse
(
newroot
.
exists
(),
'
Could not clean up temporary test subdirectory
'
)
def
test_change_session_subdirectory
(
self
):
old_paths
=
self
.
sesh
.
get_paths
()
print
(
old_paths
)
...
...
@@ -56,6 +39,15 @@ class TestGetSessionObject(unittest.TestCase):
self
.
assertTrue
(
logfile2
.
exists
())
self
.
assertNotEqual
(
logfile1
,
logfile2
,
'
Restarting session does not generate new logfile
'
)
def
test_reimporting_session_uses_same_logfile
(
self
):
logfile1
=
self
.
sesh
.
logfile
self
.
assertTrue
(
logfile1
.
exists
())
session2
=
base
.
session
.
session
logfile2
=
session2
.
logfile
self
.
assertTrue
(
logfile2
.
exists
())
self
.
assertEqual
(
logfile1
,
logfile2
,
'
Reimporting session incorrectly creates new logfile
'
)
def
test_log_warning
(
self
):
msg
=
'
A test warning
'
self
.
sesh
.
log_info
(
msg
)
...
...
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