Commit 955de833 authored by Martino Bertoni's avatar Martino Bertoni 🌋
Browse files

updated unittests

parent d70c1698
......@@ -18,6 +18,7 @@ class TestSignaturizer(unittest.TestCase):
if os.path.exists(self.tmp_dir):
shutil.rmtree(self.tmp_dir)
os.mkdir(self.tmp_dir)
os.mkdir(os.path.join(self.tmp_dir, 'vXXX'))
self.cwd = os.getcwd()
os.chdir(self.tmp_dir)
self.server_port = start_http_server()
......@@ -51,21 +52,22 @@ class TestSignaturizer(unittest.TestCase):
pred_ref = DataSignature(tmp_pred_ref)[:]
# export smilespred
version = 'vXXX'
module_file = 'dest_smilespred.tar.gz'
module_destination = os.path.join(
self.tmp_dir, module_file)
self.tmp_dir, version, module_file)
tmp_path_smilespred = os.path.join(self.tmp_dir, 'export_smilespred')
export_smilespred(
os.path.join(s3.model_path, 'smiles_final'),
module_destination, tmp_path=tmp_path_smilespred, clear_tmp=False)
# test intermediate step
module = Signaturizer(tmp_path_smilespred)
module = Signaturizer(tmp_path_smilespred, local=True)
res = module.predict(self.test_smiles)
pred = res.signature[:]
self.assertEqual(pred_ref.tolist(), pred.tolist())
# test final step
base_url = "http://localhost:%d/" % (self.server_port)
module = Signaturizer(module_file, base_url=base_url)
module = Signaturizer(module_file, base_url=base_url, version=version)
res = module.predict(self.test_smiles)
pred = res.signature[:]
self.assertEqual(pred_ref.tolist(), pred.tolist())
......@@ -78,12 +80,12 @@ class TestSignaturizer(unittest.TestCase):
tmp_path_smilespred, module_destination,
tmp_path=tmp_path_savedmodel, clear_tmp=False)
# test intermediate step
module = Signaturizer(tmp_path_savedmodel)
module = Signaturizer(tmp_path_savedmodel, local=True)
res = module.predict(self.test_smiles)
pred = res.signature[:]
self.assertEqual(pred_ref.tolist(), pred.tolist())
# test final step
module = Signaturizer(module_file, base_url=base_url)
module = Signaturizer(module_file, base_url=base_url, version=version)
res = module.predict(self.test_smiles)
pred = res.signature[:]
self.assertEqual(pred_ref.tolist(), pred.tolist())
......@@ -36,7 +36,7 @@ class TestSignaturizer(unittest.TestCase):
pred_ref = pickle.load(open(ref_file, 'rb'))
# load module and predict
module_dir = os.path.join(self.data_dir, 'B1')
module = Signaturizer(module_dir)
module = Signaturizer(module_dir, local=True)
res = module.predict(self.test_smiles)
self.assertEqual(pred_ref.tolist(), res.signature.tolist())
# test saving to file
......@@ -60,16 +60,16 @@ class TestSignaturizer(unittest.TestCase):
B1_path = os.path.join(self.data_dir, 'B1')
module_dirs.append(A1_path)
module_dirs.append(B1_path)
module_A1B1 = Signaturizer(module_dirs)
module_A1B1 = Signaturizer(module_dirs, local=True)
res_A1B1 = module_A1B1.predict(self.test_smiles)
self.assertEqual(res_A1B1.signature.shape[0], 2)
self.assertEqual(res_A1B1.signature.shape[1], 128 * 2)
module_A1 = Signaturizer(A1_path)
module_A1 = Signaturizer(A1_path, local=True)
res_A1 = module_A1.predict(self.test_smiles)
self.assertEqual(res_A1B1.signature[:, :128].tolist(),
res_A1.signature.tolist())
module_B1 = Signaturizer(B1_path)
module_B1 = Signaturizer(B1_path, local=True)
res_B1 = module_B1.predict(self.test_smiles)
self.assertEqual(res_A1B1.signature[:, 128:].tolist(),
res_B1.signature.tolist())
......@@ -82,7 +82,7 @@ class TestSignaturizer(unittest.TestCase):
for comp in res.signature[2]:
self.assertFalse(math.isnan(comp))
def test_predict_global(self):
def test_predict_global_remote(self):
module = Signaturizer('GLOBAL')
res = module.predict(self.test_smiles)
self.assertEqual(res.signature.shape[0], 2)
......@@ -90,7 +90,7 @@ class TestSignaturizer(unittest.TestCase):
def test_overwrite(self):
module_dir = os.path.join(self.data_dir, 'B1')
module = Signaturizer(module_dir)
module = Signaturizer(module_dir, local=True)
destination = os.path.join(self.tmp_dir, 'pred.h5')
module.predict(self.test_smiles, destination)
# repeating writing will result in an exception
......
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