Commit 5e54cb68 authored by Josef Brandt's avatar Josef Brandt

Save / Load TotalResult object (pickle)

parent 213419d2
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:
......
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment