Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Josef Brandt
Subsampling
Commits
5e54cb68
Commit
5e54cb68
authored
Mar 16, 2020
by
Josef Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save / Load TotalResult object (pickle)
parent
213419d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
input_output.py
input_output.py
+16
-0
tests/test_input_output.py
tests/test_input_output.py
+12
-2
No files found.
input_output.py
View file @
5e54cb68
import
os
import
pickle
from
evaluation
import
TotalResults
def
load_results
(
fname
:
str
)
->
TotalResults
:
res
:
TotalResults
=
None
if
os
.
path
.
exists
(
fname
):
with
open
(
fname
,
"rb"
)
as
fp
:
res
=
pickle
.
load
(
fp
)
return
res
return
None
def
save_results
(
fname
:
str
,
result
:
TotalResults
)
->
None
:
with
open
(
fname
,
"wb"
)
as
fp
:
pickle
.
dump
(
result
,
fp
,
protocol
=-
1
)
def
get_pkls_from_directory
(
dirPath
:
str
)
->
dict
:
...
...
tests/test_input_output.py
View file @
5e54cb68
import
unittest
import
os
import
shutil
from
input_output
import
get_pkls_from_directory
,
get_attributes_from_foldername
from
input_output
import
get_pkls_from_directory
,
get_attributes_from_foldername
,
load_results
,
save_results
from
evaluation
import
TotalResults
class
TestIO
(
unittest
.
TestCase
):
...
...
@@ -29,7 +30,16 @@ class TestIO(unittest.TestCase):
for
folder
in
self
.
folders
:
folderPath
:
str
=
os
.
path
.
join
(
self
.
path
,
folder
)
shutil
.
rmtree
(
folderPath
)
def
test_load_save
(
self
):
newRes
:
TotalResults
=
TotalResults
()
fname
:
str
=
os
.
path
.
join
(
self
.
path
,
'test.res'
)
save_results
(
fname
,
newRes
)
self
.
assertTrue
(
os
.
path
.
exists
(
fname
))
loadedRes
:
TotalResults
=
load_results
(
fname
)
self
.
assertTrue
(
loadedRes
is
not
None
)
self
.
assertEqual
(
type
(
loadedRes
),
TotalResults
)
def
test_read_pkls_from_dir
(
self
):
pklsInFolder
:
dict
=
get_pkls_from_directory
(
self
.
path
)
# the ignore folder is to be skipped
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment