Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test summarize viz #310

Merged
merged 11 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test:
- q2templates >={{ q2templates }}
- q2-types >={{ q2_types }}
- pytest
- selenium

imports:
- q2_feature_table
Expand Down
88 changes: 87 additions & 1 deletion q2_feature_table/tests/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
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 as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions
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,
Expand Down Expand Up @@ -508,6 +513,87 @@ def test_vega_spec_nandling(self):

self.assertEqual(spec['data'][0]['values'], exp)

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, 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', 'S4'])

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')
input_element = driver.find_element(By.ID, 'text-box')

# Assert the table is correct
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:
self.assertNotIn('danger', element.get_attribute('class'))

# 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 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'))

# 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'))

# 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[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'))

self.assertEqual(input_element.get_attribute('value'), '100604')


class TabulateSampleFrequencyTests(TestCase):

Expand Down
Loading