From 2da94fa05b467d32a952a37e6b1bdee989189292 Mon Sep 17 00:00:00 2001 From: Aliaksandr Dziarkach <18146690+AliaksandrDziarkach@users.noreply.github.com> Date: Fri, 4 Aug 2023 13:57:49 +0300 Subject: [PATCH] Fix integration test to avoid garbage (#1212) --- api/tests/integration/tests/bingo/basic.py | 22 ++++++--------- .../integration/tests/bingo/bingo_settings.py | 2 +- api/tests/integration/tests/bingo/ext_fp.py | 2 +- .../integration/tests/bingo/gross_test.py | 2 +- .../integration/tests/bingo/molecules.py | 2 +- .../integration/tests/bingo/part_test.py | 9 ++++--- .../integration/tests/bingo/reactions.py | 2 +- .../integration/tests/bingo/threads_test.py | 27 +++++++------------ .../tests/rendering/render_charged_pseudo.py | 4 ++- .../tests/todo/bingo_get_indigo_object_bug.py | 4 ++- 10 files changed, 34 insertions(+), 42 deletions(-) diff --git a/api/tests/integration/tests/bingo/basic.py b/api/tests/integration/tests/bingo/basic.py index 6994b397f9..f528f929bb 100644 --- a/api/tests/integration/tests/bingo/basic.py +++ b/api/tests/integration/tests/bingo/basic.py @@ -45,15 +45,13 @@ def searchSim(bingo, q, minSim, maxSim, metric=None): indigo = Indigo() - -if dir_exists(joinPathPy("out/basic", __file__)): - rmdir(joinPathPy("out/basic", __file__)) -makedirs(joinPathPy("out/basic", __file__)) +db_dir = joinPathPy("out/basic", __file__) +if dir_exists(db_dir): + rmdir(db_dir) +makedirs(db_dir) print("*** Creating temporary database ****") -bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("out", "basic"), "molecule", "" -) +bingo = Bingo.createDatabaseFile(indigo, db_dir, "molecule", "") print(bingo.version()) m = indigo.loadMolecule("C1CCCCC1") bingo.insert(m) @@ -79,7 +77,7 @@ def searchSim(bingo, q, minSim, maxSim, metric=None): bingo.close() print("*** Loading existing database ****") -bingo = Bingo.loadDatabaseFile(indigo, joinPathPy("out", "basic"), "") +bingo = Bingo.loadDatabaseFile(indigo, db_dir, "") m = indigo.loadMolecule("C1CCCCC1") searchSim(bingo, m, 0.9, 1, "tanimoto") searchSim(bingo, m, 0.9, 1, "tversky") @@ -115,9 +113,7 @@ def searchSim(bingo, q, minSim, maxSim, metric=None): print("*** Simple exact search ****") -bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("out", "basic"), "molecule" -) +bingo = Bingo.createDatabaseFile(indigo, db_dir, "molecule") mol1 = indigo.loadMolecule( "ICCCCOC(=O)C1=CC([N+]([O-])=O)=C([N+]([O-])=O)C=C1" ) @@ -129,9 +125,7 @@ def searchSim(bingo, q, minSim, maxSim, metric=None): bingo.close() print("*** Simple enumerate id ****") -bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("out/basic", __file__), "molecule" -) +bingo = Bingo.createDatabaseFile(indigo, db_dir, "molecule") mol = indigo.loadMolecule("CCCC") bingo.insert(mol) bingo.insert(mol) diff --git a/api/tests/integration/tests/bingo/bingo_settings.py b/api/tests/integration/tests/bingo/bingo_settings.py index 30f351a8c8..d0a3c2341a 100644 --- a/api/tests/integration/tests/bingo/bingo_settings.py +++ b/api/tests/integration/tests/bingo/bingo_settings.py @@ -32,7 +32,7 @@ ) bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("tempdb", __file__), "molecule", "" + indigo, joinPathPy("out/tempdb", __file__), "molecule", "" ) print("*** Insert molecules ***") diff --git a/api/tests/integration/tests/bingo/ext_fp.py b/api/tests/integration/tests/bingo/ext_fp.py index a9cba7a4b3..9fef983d82 100644 --- a/api/tests/integration/tests/bingo/ext_fp.py +++ b/api/tests/integration/tests/bingo/ext_fp.py @@ -36,7 +36,7 @@ def searchSimExt(bingo, q, minSim, maxSim, ext_fp, metric=None): indigo = Indigo() bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("extfp", __file__), "molecule", "" + indigo, joinPathPy("out/extfp", __file__), "molecule", "" ) print(bingo.version()) m = indigo.loadMolecule("C1CCCCC1") diff --git a/api/tests/integration/tests/bingo/gross_test.py b/api/tests/integration/tests/bingo/gross_test.py index 95d878e670..cc6ec59b5d 100644 --- a/api/tests/integration/tests/bingo/gross_test.py +++ b/api/tests/integration/tests/bingo/gross_test.py @@ -10,7 +10,7 @@ indigo = Indigo() bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("db_gross_mol", __file__), "molecule", "" + indigo, joinPathPy("out/db_gross_mol", __file__), "molecule", "" ) for idx, mol in enumerate( diff --git a/api/tests/integration/tests/bingo/molecules.py b/api/tests/integration/tests/bingo/molecules.py index 5de98b95ec..97df42885e 100644 --- a/api/tests/integration/tests/bingo/molecules.py +++ b/api/tests/integration/tests/bingo/molecules.py @@ -70,7 +70,7 @@ def searchExact(bingo, q, options=""): indigo = Indigo() bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("db_molecule", __file__), "molecule", "" + indigo, joinPathPy("out/db_molecule", __file__), "molecule", "" ) index = 0 diff --git a/api/tests/integration/tests/bingo/part_test.py b/api/tests/integration/tests/bingo/part_test.py index ff50301c3f..5bd428a146 100644 --- a/api/tests/integration/tests/bingo/part_test.py +++ b/api/tests/integration/tests/bingo/part_test.py @@ -64,9 +64,12 @@ def makeSearchExact(db, pid, query, options, output=None): outPrint("PID {0}) Total count {1}".format(pid, cnt), pid, output) +db_dir = joinPathPy("out/mol_part_db", __file__) + + def partCreate(): bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("mol_part_db", __file__), "molecule", "mt_size:2000" + indigo, db_dir, "molecule", "mt_size:2000" ) insertSmi(bingo, dataPath("molecules/basic/sample_100000.smi")) @@ -75,9 +78,7 @@ def partCreate(): def partTest(size, searchType="sub"): - bingo = Bingo.loadDatabaseFile( - indigo, joinPathPy("mol_part_db", __file__), "" - ) + bingo = Bingo.loadDatabaseFile(indigo, db_dir, "") index = 0 for m in indigo.iterateSDFile( diff --git a/api/tests/integration/tests/bingo/reactions.py b/api/tests/integration/tests/bingo/reactions.py index ebed8f159e..0cde370f13 100644 --- a/api/tests/integration/tests/bingo/reactions.py +++ b/api/tests/integration/tests/bingo/reactions.py @@ -67,7 +67,7 @@ def searchExact(bingo, q, options=""): indigo = Indigo() bingo = Bingo.createDatabaseFile( - indigo, joinPathPy("db_reaction", __file__), "reaction", "" + indigo, joinPathPy("out/db_reaction", __file__), "reaction", "" ) index = 0 diff --git a/api/tests/integration/tests/bingo/threads_test.py b/api/tests/integration/tests/bingo/threads_test.py index 8aedb7ea36..21feeace0c 100644 --- a/api/tests/integration/tests/bingo/threads_test.py +++ b/api/tests/integration/tests/bingo/threads_test.py @@ -8,6 +8,9 @@ ) from env_indigo import * # noqa +db_dir1 = joinPathPy("out/mol_test_db1", __file__) +db_dir2 = joinPathPy("out/mol_test_db2", __file__) + def outPrint(s, pid, output): # output = None @@ -90,12 +93,8 @@ def makeSearchExact(db, pid, query, options, output=None): def consTest(): - bingo1 = Bingo.createDatabaseFile( - indigo, joinPathPy("mol_test_db1", __file__), "molecule", "" - ) - bingo2 = Bingo.createDatabaseFile( - indigo, joinPathPy("mol_test_db2", __file__), "molecule", "" - ) + bingo1 = Bingo.createDatabaseFile(indigo, db_dir1, "molecule", "") + bingo2 = Bingo.createDatabaseFile(indigo, db_dir2, "molecule", "") insertProc(bingo1, 0, "sample_2000_2.smi") insertProc(bingo1, 0, "sample_2000_2.smi") @@ -134,9 +133,7 @@ def insertThr(db, pid, samples, output=None): def paralSameTest(): - bingo1 = Bingo.createDatabaseFile( - indigo, joinPathPy("mol_test_db1", __file__), "molecule", "" - ) + bingo1 = Bingo.createDatabaseFile(indigo, db_dir1, "molecule", "") thrs = [] @@ -173,13 +170,13 @@ def paralSameTest(): def paralBigTest(): bingo1 = Bingo.createDatabaseFile( indigo, - joinPathPy("mol_test_db1", __file__), + db_dir1, "molecule", "read_only:false", ) bingo2 = Bingo.createDatabaseFile( indigo, - joinPathPy("mol_test_db2", __file__), + db_dir2, "molecule", "read_only:false", ) @@ -328,12 +325,8 @@ def paralBigTest(): def difIndigoTest(): indigo1 = Indigo() indigo2 = Indigo() - bingo1 = Bingo.createDatabaseFile( - indigo1, joinPathPy("mol_test_db1", __file__), "molecule", "" - ) - bingo2 = Bingo.createDatabaseFile( - indigo2, joinPathPy("mol_test_db2", __file__), "molecule", "" - ) + bingo1 = Bingo.createDatabaseFile(indigo1, db_dir1, "molecule", "") + bingo2 = Bingo.createDatabaseFile(indigo2, db_dir2, "molecule", "") t1 = threading.Thread(target=insertThr, args=(bingo1, [2, 3])) t2 = threading.Thread(target=insertThr, args=(bingo2, [1, 4, 5])) diff --git a/api/tests/integration/tests/rendering/render_charged_pseudo.py b/api/tests/integration/tests/rendering/render_charged_pseudo.py index d930a9f716..c4f5328d45 100644 --- a/api/tests/integration/tests/rendering/render_charged_pseudo.py +++ b/api/tests/integration/tests/rendering/render_charged_pseudo.py @@ -32,7 +32,9 @@ mol = indigo.loadQueryMoleculeFromFile(file) indigo.setOption("render-output-format", "svg") -renderer.renderToFile(mol, joinPathPy(out_dir + filename + "_q.svg", __file__)) +renderer.renderToFile( + mol, joinPathPy(out_dir + "/" + filename + "_q.svg", __file__) +) print(checkImageSimilarity("%s" % (filename + "_q.svg"))) indigo.setOption("render-output-format", "png") diff --git a/api/tests/integration/tests/todo/bingo_get_indigo_object_bug.py b/api/tests/integration/tests/todo/bingo_get_indigo_object_bug.py index 52418e2251..36b5a11bb3 100644 --- a/api/tests/integration/tests/todo/bingo_get_indigo_object_bug.py +++ b/api/tests/integration/tests/todo/bingo_get_indigo_object_bug.py @@ -9,7 +9,9 @@ from env_indigo import * indigo = Indigo() -bingo = Bingo.createDatabaseFile(indigo, "get_indigo_object_bug", "molecule") +bingo = Bingo.createDatabaseFile( + indigo, joiinPathPy("out/get_indigo_object_bug", __file__), "molecule" +) for item in ("C1=CC=CC=C1", "C1=CN=CC=C1"): bingo.insert(indigo.loadMolecule(item)) result = bingo.searchSim(