From ed29c2708666bb261eb4ee3dad8bd35cf1cb4663 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Sat, 17 Aug 2024 03:08:06 +0100 Subject: [PATCH] Fix test suite (#796) * Skip tests requiring optional modules when they are absent. The `gilda` and `semsimian` modules are optional dependencies, but the tests that depend do not expect that they may not be present and error out if they cannot be imported. Since they are optional, their absence should not cause the test suite to fail, so this commit ensures that the corresponding tests are properly skipped if the optional modules are not found. closes #794 * Prevent spurious warnings from causing test failure. The `test_annotate_file` command may fail because the `annotate` command may emit some unexpected warnings on STDERR about invalid CURIEs, even if there are no errors and the expected output is normally produced on STDOUT. This commit amends the test so that it ignores any 'WARNING:' line in the STDERR stream produced by the `annotate` command. closes #795. --- tests/test_cli.py | 2 +- .../test_semsimian_implementation.py | 2 ++ tests/test_selector.py | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 3fc048585..00f33bb1c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1522,7 +1522,7 @@ def test_annotate_file(self): ], ) print("STDERR", result.stdout) - err = result.stderr + err = "\n".join([line for line in result.stderr.split("\n") if not line.startswith("WARNING")]) self.assertEqual("", err) self.assertEqual(0, result.exit_code) with open(outfile) as stream: diff --git a/tests/test_implementations/test_semsimian_implementation.py b/tests/test_implementations/test_semsimian_implementation.py index fb1e32973..ce06b4857 100644 --- a/tests/test_implementations/test_semsimian_implementation.py +++ b/tests/test_implementations/test_semsimian_implementation.py @@ -1,6 +1,7 @@ import os import timeit import unittest +from importlib.util import find_spec from linkml_runtime.dumpers import yaml_dumper @@ -31,6 +32,7 @@ @unittest.skipIf(os.name == "nt", "DB path loading inconsistent on Windows") +@unittest.skipIf(find_spec("semsimian") is None, "Semsimian not available") class TestSemSimianImplementation(unittest.TestCase): """Implementation tests for Rust-based semantic similarity.""" diff --git a/tests/test_selector.py b/tests/test_selector.py index 35cb52364..ca75da5e8 100644 --- a/tests/test_selector.py +++ b/tests/test_selector.py @@ -6,8 +6,13 @@ import unittest from pathlib import Path -from gilda.grounder import Grounder -from gilda.term import Term +try: + from gilda.grounder import Grounder + from gilda.term import Term + + have_gilda = True +except ImportError: + have_gilda = False from oaklib.datamodels.text_annotator import TextAnnotationConfiguration from oaklib.implementations.gilda import GildaImplementation @@ -23,6 +28,7 @@ from tests import INPUT_DIR +@unittest.skipIf(not have_gilda, "Gilda not available") class TestResource(unittest.TestCase): def test_from_descriptor(self): # no scheme