From e3ded044c6357c95d6f15ba6c2478e74972d80e6 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:12:53 -0700 Subject: [PATCH 01/11] Add selenium test --- q2_feature_table/tests/test_summarize.py | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index 5221b7b..f6e8cf2 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -508,6 +508,67 @@ def test_vega_spec_nandling(self): self.assertEqual(spec['data'][0]['values'], exp) + def test_summarize_viz(self): + from selenium import webdriver + from selenium.webdriver.chrome.options import Options + from selenium.webdriver.common.by import By + + chrome_options = Options() + chrome_options.add_argument("--headless=new") + driver = webdriver.Chrome(options=chrome_options) + + table = biom.Table(np.array([[0, 1, 3], + [1, 1, 2], + [400, 450, 500], + [1000, 10000, 100000], + [52, 42, 99]]), + ['O1', 'O2', '03', '04', 'O5'], + ['S1', 'S2', 'S3']) + + with tempfile.TemporaryDirectory() as output_dir: + summarize(output_dir, table) + driver.get( + "file://" + f"{os.path.join(output_dir, 'sample-frequency-detail.html')}") + + element_list = driver.find_element( + By.ID, 'table-body').find_elements(By.TAG_NAME, 'tr') + # Reverse this so the lower values are first + element_list.reverse() + input_element = driver.find_element(By.ID, 'text-box') + + # Assert the table is correct + self.assertEqual(element_list[0].text, 'S1 1,453') + self.assertEqual(element_list[1].text, 'S2 10,494') + self.assertEqual(element_list[2].text, 'S3 100,604') + + # None should have danger to begin + for element in element_list: + self.assertNotIn('danger', element.get_attribute('class')) + + # There was already a 0 in the text box so this actually made the + # depth 10000 and so on for every other send + input_element.send_keys('1000') + + self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertNotIn('danger', element_list[1].get_attribute('class')) + self.assertNotIn('danger', element_list[2].get_attribute('class')) + + input_element.send_keys('0') + + self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertIn('danger', element_list[1].get_attribute('class')) + self.assertNotIn('danger', element_list[2].get_attribute('class')) + + # Ensure the box cannot go over the largest + input_element.send_keys('0') + + self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertIn('danger', element_list[1].get_attribute('class')) + self.assertNotIn('danger', element_list[2].get_attribute('class')) + + self.assertEqual(input_element.get_attribute('value'), '100604') + class TabulateSampleFrequencyTests(TestCase): From f34966de76caaf460cbed96889085f283257ca16 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:14:33 -0700 Subject: [PATCH 02/11] Add selenium to deps --- ci/recipe/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index 695c0ed..79ca085 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -31,6 +31,7 @@ requirements: - qiime2 {{ qiime2_epoch }}.* - q2templates {{ qiime2_epoch }}.* - q2-types {{ qiime2_epoch }}.* + - selenium test: requires: From b04fe1ea6cc8aae6eec752f233de64cec3669e96 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:19:10 -0700 Subject: [PATCH 03/11] No point reversing --- q2_feature_table/tests/test_summarize.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index f6e8cf2..0c40d1f 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -533,14 +533,12 @@ def test_summarize_viz(self): element_list = driver.find_element( By.ID, 'table-body').find_elements(By.TAG_NAME, 'tr') - # Reverse this so the lower values are first - element_list.reverse() input_element = driver.find_element(By.ID, 'text-box') # Assert the table is correct - self.assertEqual(element_list[0].text, 'S1 1,453') + self.assertEqual(element_list[2].text, 'S1 1,453') self.assertEqual(element_list[1].text, 'S2 10,494') - self.assertEqual(element_list[2].text, 'S3 100,604') + self.assertEqual(element_list[0].text, 'S3 100,604') # None should have danger to begin for element in element_list: @@ -550,22 +548,22 @@ def test_summarize_viz(self): # depth 10000 and so on for every other send input_element.send_keys('1000') - self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertIn('danger', element_list[2].get_attribute('class')) self.assertNotIn('danger', element_list[1].get_attribute('class')) - self.assertNotIn('danger', element_list[2].get_attribute('class')) + self.assertNotIn('danger', element_list[0].get_attribute('class')) input_element.send_keys('0') - self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertIn('danger', element_list[2].get_attribute('class')) self.assertIn('danger', element_list[1].get_attribute('class')) - self.assertNotIn('danger', element_list[2].get_attribute('class')) + self.assertNotIn('danger', element_list[0].get_attribute('class')) # Ensure the box cannot go over the largest input_element.send_keys('0') - self.assertIn('danger', element_list[0].get_attribute('class')) + self.assertIn('danger', element_list[2].get_attribute('class')) self.assertIn('danger', element_list[1].get_attribute('class')) - self.assertNotIn('danger', element_list[2].get_attribute('class')) + self.assertNotIn('danger', element_list[0].get_attribute('class')) self.assertEqual(input_element.get_attribute('value'), '100604') From 57625b4bd9d8a2f8255917fcf2efea04df446da0 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:31:58 -0700 Subject: [PATCH 04/11] Move to test dep --- ci/recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index 79ca085..79390ce 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -31,7 +31,6 @@ requirements: - qiime2 {{ qiime2_epoch }}.* - q2templates {{ qiime2_epoch }}.* - q2-types {{ qiime2_epoch }}.* - - selenium test: requires: @@ -39,6 +38,7 @@ test: - q2templates >={{ q2templates }} - q2-types >={{ q2_types }} - pytest + - selenium imports: - q2_feature_table From 8b8ce084520e033af6e6aa88e1670597685dd8a3 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:53:10 -0700 Subject: [PATCH 05/11] Maybe add the manager specifically --- ci/recipe/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index 79390ce..256ff9e 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -39,6 +39,7 @@ test: - q2-types >={{ q2_types }} - pytest - selenium + - selenium-manager imports: - q2_feature_table From 4a8413ddca17cb21d3d3030bf6075f20e8a166ab Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Tue, 4 Jun 2024 16:59:25 -0700 Subject: [PATCH 06/11] Revert back to what worked for now --- ci/recipe/meta.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index 256ff9e..79ca085 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -31,6 +31,7 @@ requirements: - qiime2 {{ qiime2_epoch }}.* - q2templates {{ qiime2_epoch }}.* - q2-types {{ qiime2_epoch }}.* + - selenium test: requires: @@ -38,8 +39,6 @@ test: - q2templates >={{ q2templates }} - q2-types >={{ q2_types }} - pytest - - selenium - - selenium-manager imports: - q2_feature_table From 3173adc5bdee4211ffad2e5bb2ddf5afbdba42b9 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Wed, 5 Jun 2024 11:29:52 -0700 Subject: [PATCH 07/11] Swap it back to a test dep with changes to alp --- ci/recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/recipe/meta.yaml b/ci/recipe/meta.yaml index 79ca085..79390ce 100644 --- a/ci/recipe/meta.yaml +++ b/ci/recipe/meta.yaml @@ -31,7 +31,6 @@ requirements: - qiime2 {{ qiime2_epoch }}.* - q2templates {{ qiime2_epoch }}.* - q2-types {{ qiime2_epoch }}.* - - selenium test: requires: @@ -39,6 +38,7 @@ test: - q2templates >={{ q2templates }} - q2-types >={{ q2_types }} - pytest + - selenium imports: - q2_feature_table From 19446702ed04ef9c15493108381779ca64a21190 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Wed, 5 Jun 2024 15:25:07 -0700 Subject: [PATCH 08/11] Update comments --- q2_feature_table/tests/test_summarize.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index 0c40d1f..2c9b444 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -544,21 +544,25 @@ def test_summarize_viz(self): for element in element_list: self.assertNotIn('danger', element.get_attribute('class')) - # There was already a 0 in the text box so this actually made the - # depth 10000 and so on for every other send + # This is not setting the value in the box, it is sending these key + # presses to the box. There is already a 0 in the box, so we are + # adding these digits to that 0 making the value in the box 10000 input_element.send_keys('1000') self.assertIn('danger', element_list[2].get_attribute('class')) self.assertNotIn('danger', element_list[1].get_attribute('class')) self.assertNotIn('danger', element_list[0].get_attribute('class')) + # Add another 0 to the box making the value 100000 input_element.send_keys('0') self.assertIn('danger', element_list[2].get_attribute('class')) self.assertIn('danger', element_list[1].get_attribute('class')) self.assertNotIn('danger', element_list[0].get_attribute('class')) - # Ensure the box cannot go over the largest + # Send another 0 to the box and ensure the box cannot go over the + # largest frequency. This would make the value 1000000, but it + # should be artificially capped to 100604 input_element.send_keys('0') self.assertIn('danger', element_list[2].get_attribute('class')) From 93e3cdcabb3322a82fb085b39ecdf89ac3cb4501 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Thu, 6 Jun 2024 16:29:41 -0700 Subject: [PATCH 09/11] Move imports --- q2_feature_table/tests/test_summarize.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index 2c9b444..340d37f 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -11,16 +11,20 @@ import tempfile import re import json +import csv import skbio import biom import pandas as pd import numpy as np +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.common.by import By + import qiime2 from q2_types.feature_data import DNAIterator from qiime2.plugin.testing import TestPluginBase from qiime2 import Artifact, Metadata -import csv from q2_feature_table import ( tabulate_seqs, summarize, @@ -509,10 +513,6 @@ def test_vega_spec_nandling(self): self.assertEqual(spec['data'][0]['values'], exp) def test_summarize_viz(self): - from selenium import webdriver - from selenium.webdriver.chrome.options import Options - from selenium.webdriver.common.by import By - chrome_options = Options() chrome_options.add_argument("--headless=new") driver = webdriver.Chrome(options=chrome_options) From 142e3ab27449cea2a59eebb0436ca4cf166b74f1 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Thu, 6 Jun 2024 16:49:29 -0700 Subject: [PATCH 10/11] Add headless firefox test --- q2_feature_table/tests/test_summarize.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index 340d37f..8798ea8 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -18,7 +18,8 @@ import pandas as pd import numpy as np from selenium import webdriver -from selenium.webdriver.chrome.options import Options +from selenium.webdriver.chrome.options import Options as ChromeOptions +from selenium.webdriver.firefox.options import Options as FirefoxOptions from selenium.webdriver.common.by import By import qiime2 @@ -512,11 +513,21 @@ def test_vega_spec_nandling(self): self.assertEqual(spec['data'][0]['values'], exp) - def test_summarize_viz(self): - chrome_options = Options() - chrome_options.add_argument("--headless=new") - driver = webdriver.Chrome(options=chrome_options) + def test_summarize_viz_chrome(self): + chrome_options = ChromeOptions() + chrome_options.add_argument("-headless") + with webdriver.Chrome(options=chrome_options) as driver: + self._selenium_test(driver) + + def test_summarize_viz_firefox(self): + firefox_options = FirefoxOptions() + firefox_options.add_argument("-headless") + + with webdriver.Firefox(options=firefox_options) as driver: + self._selenium_test(driver) + + def _selenium_test(self, driver): table = biom.Table(np.array([[0, 1, 3], [1, 1, 2], [400, 450, 500], From ca21649c4ef9d69ba43fbfe107718db306a54b23 Mon Sep 17 00:00:00 2001 From: Oddant1 Date: Thu, 13 Jun 2024 11:49:30 -0700 Subject: [PATCH 11/11] Add a value with no , to the test --- q2_feature_table/tests/test_summarize.py | 34 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/q2_feature_table/tests/test_summarize.py b/q2_feature_table/tests/test_summarize.py index 8798ea8..c183ee6 100644 --- a/q2_feature_table/tests/test_summarize.py +++ b/q2_feature_table/tests/test_summarize.py @@ -528,13 +528,13 @@ def test_summarize_viz_firefox(self): self._selenium_test(driver) def _selenium_test(self, driver): - table = biom.Table(np.array([[0, 1, 3], - [1, 1, 2], - [400, 450, 500], - [1000, 10000, 100000], - [52, 42, 99]]), + table = biom.Table(np.array([[0, 0, 1, 3], + [1, 1, 1, 2], + [100, 400, 450, 500], + [500, 1000, 10000, 100000], + [50, 52, 42, 99]]), ['O1', 'O2', '03', '04', 'O5'], - ['S1', 'S2', 'S3']) + ['S1', 'S2', 'S3', 'S4']) with tempfile.TemporaryDirectory() as output_dir: summarize(output_dir, table) @@ -547,9 +547,10 @@ def _selenium_test(self, driver): input_element = driver.find_element(By.ID, 'text-box') # Assert the table is correct - self.assertEqual(element_list[2].text, 'S1 1,453') - self.assertEqual(element_list[1].text, 'S2 10,494') - self.assertEqual(element_list[0].text, 'S3 100,604') + self.assertEqual(element_list[3].text, 'S1 651') + self.assertEqual(element_list[2].text, 'S2 1,453') + self.assertEqual(element_list[1].text, 'S3 10,494') + self.assertEqual(element_list[0].text, 'S4 100,604') # None should have danger to begin for element in element_list: @@ -557,9 +558,18 @@ def _selenium_test(self, driver): # This is not setting the value in the box, it is sending these key # presses to the box. There is already a 0 in the box, so we are - # adding these digits to that 0 making the value in the box 10000 - input_element.send_keys('1000') + # adding these digits to that 0 making the value in the box 1000 + input_element.send_keys('100') + + self.assertIn('danger', element_list[3].get_attribute('class')) + self.assertNotIn('danger', element_list[2].get_attribute('class')) + self.assertNotIn('danger', element_list[1].get_attribute('class')) + self.assertNotIn('danger', element_list[0].get_attribute('class')) + + # Add another 0 to the box making the value 10000 + input_element.send_keys('0') + self.assertIn('danger', element_list[3].get_attribute('class')) self.assertIn('danger', element_list[2].get_attribute('class')) self.assertNotIn('danger', element_list[1].get_attribute('class')) self.assertNotIn('danger', element_list[0].get_attribute('class')) @@ -567,6 +577,7 @@ def _selenium_test(self, driver): # Add another 0 to the box making the value 100000 input_element.send_keys('0') + self.assertIn('danger', element_list[3].get_attribute('class')) self.assertIn('danger', element_list[2].get_attribute('class')) self.assertIn('danger', element_list[1].get_attribute('class')) self.assertNotIn('danger', element_list[0].get_attribute('class')) @@ -576,6 +587,7 @@ def _selenium_test(self, driver): # should be artificially capped to 100604 input_element.send_keys('0') + self.assertIn('danger', element_list[3].get_attribute('class')) self.assertIn('danger', element_list[2].get_attribute('class')) self.assertIn('danger', element_list[1].get_attribute('class')) self.assertNotIn('danger', element_list[0].get_attribute('class'))