From 207dda1992680602f26bdaaefaaecd407c959cda Mon Sep 17 00:00:00 2001 From: Anthony Simard Date: Wed, 4 Sep 2024 14:48:44 -0700 Subject: [PATCH] TEST: more robust testing for volatility plot (#187) --- ci/recipe/meta.yaml | 1 + q2_longitudinal/_longitudinal.py | 14 +++++-- q2_longitudinal/assets/volatility/index.html | 3 ++ q2_longitudinal/tests/test_longitudinal.py | 43 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index ecb4ee0..bf052a7 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -39,6 +39,7 @@ test: - q2-sample-classifier >={{ q2_sample_classifier }} - q2templates >={{ q2templates }} - q2-feature-table >={{ q2_feature_table }} + - selenium - pytest imports: diff --git a/q2_longitudinal/_longitudinal.py b/q2_longitudinal/_longitudinal.py index 33562c9..cb51736 100644 --- a/q2_longitudinal/_longitudinal.py +++ b/q2_longitudinal/_longitudinal.py @@ -6,6 +6,7 @@ # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- +import json import os.path import pkg_resources @@ -420,9 +421,16 @@ def _volatility(output_dir, metadata, state_column, individual_id_column, metadata.save(os.path.join(output_dir, 'data.tsv')) copy_tree(os.path.join(TEMPLATES, 'volatility'), output_dir) index = os.path.join(TEMPLATES, 'volatility', 'index.html') - q2templates.render(index, output_dir, - context={'vega_spec': vega_spec, - 'is_feat_vol_plot': is_feat_vol_plot}) + # Render in svg for testing so we can assert things about the plot. Use a + # canvas for the real runs to reduce resource usage + renderer = \ + json.dumps('svg' if 'PYTEST_CURRENT_TEST' in os.environ else 'canvas') + q2templates.render( + index, + output_dir, + context={'vega_spec': vega_spec, + 'is_feat_vol_plot': is_feat_vol_plot, + 'renderer': renderer}) def volatility(output_dir: str, diff --git a/q2_longitudinal/assets/volatility/index.html b/q2_longitudinal/assets/volatility/index.html index 46b6ccb..5322ae8 100644 --- a/q2_longitudinal/assets/volatility/index.html +++ b/q2_longitudinal/assets/volatility/index.html @@ -126,14 +126,17 @@

Feature Stats Subplot Controls

{% set loading_selector = '#loading' %} {% include 'js-error-handler.html' %} +