From f914dc21577253f293b50b890ea0ac4bd2fd5d1b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 21 Feb 2022 09:07:31 +0300 Subject: Test partial corrs API with mix of existing and non-existing control traits Test that the partial correlations endpoint handles a mix of existing and non-existing control traits gracefully and issues a warning to the user. Summary of changes: * gn3/computations/partial_correlations.py: Issue a warning for all non-existing control traits * gn3/db/partial_correlations.py: update queries - use `INNER JOIN` for tables instead of comma-separated list of tables * tests/integration/conftest.py: Add `db_conn` fixture to provide a database connection to the tests. This will probably be changed in the future to connect to a temporary database for tests. * tests/integration/test_partial_correlations.py: Add test to check for correct behaviour with a mix of existing and non-existing control traits --- gn3/computations/partial_correlations.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gn3/computations') diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index 1cc969c..3633a59 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -628,6 +628,12 @@ def partial_correlations_entry(# pylint: disable=[R0913, R0914, R0911] return { "status": "not-found", "message": "None of the requested control traits were found."} + for trait in cntrl_traits: + if trait["haveinfo"] == False: + warnings.warn( + (f"Control traits {trait['trait_fullname']} was not found " + "- continuing without it."), + category=UserWarning) group = primary_trait["db"]["group"] primary_trait_data = all_traits_data[primary_trait["trait_name"]] -- cgit v1.2.3