From 278dfd2c7a130c9bde43548f523d95a5d2a8dc00 Mon Sep 17 00:00:00 2001 From: Andrew Hoover Date: Mon, 30 Oct 2023 08:54:15 -0400 Subject: [PATCH] Test validate_selection; if fail, print logs in CI --- .github/workflows/matcher_ci.yml | 3 +- backend/initialize_db/test_start.sh | 2 +- .../unit_tests/test_validate_selection.py | 28 +++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/matcher_ci.yml b/.github/workflows/matcher_ci.yml index 0ff1b6f..01fa468 100644 --- a/.github/workflows/matcher_ci.yml +++ b/.github/workflows/matcher_ci.yml @@ -20,10 +20,11 @@ jobs: # Tests succeed iff containers exit 0 run: | errors=0 - container_ids=$(sudo sh -c "docker ps | grep -E 'matcher-backend|matcher_backend' | awk '{ print \$1 }'") + container_ids=$(docker ps | grep -E 'matcher-backend|matcher_backend' | awk '{ print $1 }') for container_id in $container_ids; do if [ $(docker wait $container_id) -ne 0 ]; then errors=$((errors+1)) + docker logs $container_id fi done if [ $errors -ne 0 ]; then diff --git a/backend/initialize_db/test_start.sh b/backend/initialize_db/test_start.sh index d02ccfd..80d1377 100644 --- a/backend/initialize_db/test_start.sh +++ b/backend/initialize_db/test_start.sh @@ -14,7 +14,7 @@ metadata=$INITIALIZE_DIR/test_metadata.csv example_queries=$INITIALIZE_DIR/example_queries.json if [[ "$RUN_TESTS" == "true" ]]; then - conda run --no-capture-output -n matcher-api pytest -s ./backend/tests/unit_tests || exit 1 + conda run --no-capture-output -n matcher-api pytest -s -v ./backend/tests/unit_tests || exit 1 # Only run unit tests for now exit 0 fi diff --git a/backend/tests/unit_tests/test_validate_selection.py b/backend/tests/unit_tests/test_validate_selection.py index f16b542..5ffac81 100644 --- a/backend/tests/unit_tests/test_validate_selection.py +++ b/backend/tests/unit_tests/test_validate_selection.py @@ -1,9 +1,27 @@ """Test validate_selection function.""" -import sys from backend.ss_select import validate_selection +from backend.models import SketchedContent -def test_hello_world(): - print("Test validate_selection") - #assert 1 == 0 - return None \ No newline at end of file +def test_validate_selection(): + + mol1_molfile = """ + Ketcher 103023 8282D 1 1.00000 0.00000 0 + + 2 1 0 0 0 0 999 V2000 + 4.9167 -5.8333 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 5.7827 -5.3333 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 1 2 1 0 0 0 +M END +""" + selection_type = 'variable' + sketched_content = SketchedContent.parse_obj({'mol1_molfile': mol1_molfile}) + mol1_selected_atoms = '1' + mol1_selected_bonds = '' + mol2_selected_atoms = '' + mol2_selected_bonds = '' + + result = validate_selection(selection_type, sketched_content, mol1_selected_atoms, + mol1_selected_bonds, mol2_selected_atoms, mol2_selected_bonds) + + assert result == ([1], [], [0], [], 'False', [], [], [], [], 'False')