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

Auxiliary dataframe #38

Merged
merged 28 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ jobs:
- name: Install flake8
run: pip install pyproject-flake8
- name: Run the flake8 linter
run: pflake8 .
# black uses a line length of 88
run: pflake8 --max-line-length 88 .
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "xiplot"
version = "0.2.0"
version = "0.3.0"
authors = [
{ name = "Akihiro Tanaka", email = "akihiro.fin@gmail.com" },
{ name = "Juniper Tyree", email = "juniper.tyree@helsinki.fi" },
Expand Down Expand Up @@ -33,7 +33,16 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["pytest", "black", "dash[testing]", "isort", "pyproject-flake8", "webdriver-manager", "selenium"]
dev = [
"pytest",
"black",
"dash[testing]",
"isort",
"pyproject-flake8",
"webdriver-manager",
"selenium",
"IPython",
]

[project.urls]
homepage = "https://github.com/edahelsinki/xiplot"
Expand Down
90 changes: 39 additions & 51 deletions tests/test_barplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from tests.util_test import render_plot
from tests.util_test import render_plot, start_server
from xiplot.plots.barplot import Barplot
from xiplot.setup import setup_xiplot_dash_app

tmp = Barplot.register_callbacks(
dash.Dash(__name__), lambda x: x, lambda x: x
)[0]


def test_teba001_render_barplot(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Barplot")

plot = driver.find_element(By.CLASS_NAME, "dash-graph")
Expand All @@ -31,11 +26,7 @@ def test_teba001_render_barplot(dash_duo):


def test_teba002_change_axis_value(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Barplot")

driver.find_element(By.CLASS_NAME, "dd-double-left").click()
Expand All @@ -50,8 +41,7 @@ def test_teba002_change_axis_value(dash_duo):

x.send_keys("model-year")
x.send_keys(Keys.RETURN)

time.sleep(1)
time.sleep(0.5)

assert "model-year" in driver.find_element(By.CLASS_NAME, "xtitle").text
assert dash_duo.get_logs() == [], "browser console should contain no error"
Expand All @@ -60,45 +50,48 @@ def test_teba002_change_axis_value(dash_duo):


def test_teba003_set_cluster(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Barplot")

cluster_dd = driver.find_element(
By.XPATH,
"//div[@class='dd-single cluster-comparison']/div[2]",
# Run clustering
driver.find_element(By.XPATH, "//div[@id='control-tabs']/div[3]").click()
feature_dd = driver.find_element(By.ID, "cluster_feature")
feature_dd.find_element(By.TAG_NAME, "input").send_keys("PCA")
time.sleep(0.1)
# The headless driver uses some wierd window size so that the dropdown
# obscures the button. This is why we have cannot just use `click` here:
driver.execute_script(
"arguments[0].click();",
driver.find_element(By.ID, "add_by_keyword-button"),
)
cluster_dd.click()

time.sleep(1)

driver.find_element(
By.XPATH,
"//div[@class='ReactVirtualized__Grid__innerScrollContainer']/div[3]",
).click()

time.sleep(1)
time.sleep(0.1)
driver.find_element(By.ID, "cluster-button").click()
time.sleep(0.5)

cluster_value = driver.find_element(
By.XPATH,
"//div[@class='dd-single cluster-comparison']/div[2]/div[1]/div[1]",
).get_attribute("outerHTML")
# Use clusters
inp = driver.find_element(
By.CSS_SELECTOR, ".dd-single.cluster-comparison input"
)
inp.send_keys("2")
inp.send_keys(Keys.RETURN)
time.sleep(0.5)
try:
cluster_val = driver.find_element(
By.CSS_SELECTOR, ".dd-single.cluster-comparison"
).find_element(By.CSS_SELECTOR, ".Select-value")
except Exception:
# Sometimes the GitHub test is too slow to find ".Select-value"
cluster_val = driver.find_element(
By.CSS_SELECTOR, ".dd-single.cluster-comparison"
)
assert "Cluster #2" in cluster_val.get_attribute("innerHTML")

assert "cluster #2" in cluster_value
assert dash_duo.get_logs() == [], "browser console should contain no error"

driver.close()


def test_teba004_set_order(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Barplot")

comparison_order_dd = driver.find_element(
Expand All @@ -107,8 +100,6 @@ def test_teba004_set_order(dash_duo):
)
comparison_order_dd.click()

time.sleep(1)

dropdown_input = driver.find_element(
By.XPATH,
(
Expand All @@ -117,8 +108,7 @@ def test_teba004_set_order(dash_duo):
),
)
dropdown_input.send_keys("total", Keys.RETURN)

time.sleep(1)
time.sleep(0.5)

assert "total" in driver.find_element(
By.XPATH,
Expand All @@ -130,9 +120,7 @@ def test_teba004_set_order(dash_duo):


def test_create_barplot():
d = {"col1": [1, 2], "col2": [3, 4]}
df = pd.DataFrame(data=d)
output = tmp("col1", "col2", ["all"], "reldiff", ["all", "all"], df, [])
df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
output = tmp("col1", "col2", ["all"], "reldiff", df, pd.DataFrame())
fig = output[0]

assert str(type(fig)) == "<class 'plotly.graph_objs._figure.Figure'>"
13 changes: 3 additions & 10 deletions tests/test_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import time

import dash
import pandas as pd
from selenium.webdriver.common.by import By

from tests.util_test import render_plot
from tests.util_test import render_plot, start_server
from xiplot.plots.heatmap import Heatmap
from xiplot.setup import setup_xiplot_dash_app

tmp = Heatmap.register_callbacks(
dash.Dash(__name__), lambda x: x, lambda x: x
)[0]


def test_tehe001_render_heatmap(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Heatmap")

plot = driver.find_element(By.CLASS_NAME, "dash-graph")
Expand All @@ -32,7 +25,7 @@ def test_tehe001_render_heatmap(dash_duo):
def test_create_heatmap():
d = {"col1": [1, 2], "col2": [3, 4]}
df = pd.DataFrame(data=d)
output = tmp(2, ["col1", "col2"], df, [])
output = tmp(2, ["col1", "col2"], df, pd.DataFrame())
fig = output

assert str(type(fig)) == "<class 'plotly.graph_objs._figure.Figure'>"
29 changes: 7 additions & 22 deletions tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from tests.util_test import render_plot
from tests.util_test import render_plot, start_server
from xiplot.plots.histogram import Histogram
from xiplot.setup import setup_xiplot_dash_app

tmp = Histogram.register_callbacks(
dash.Dash(__name__), lambda x: x, lambda x: x
)[0]


def test_tehi001_render_histogram(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Histogram")

plot = driver.find_element(By.CLASS_NAME, "dash-graph")
Expand All @@ -31,11 +26,7 @@ def test_tehi001_render_histogram(dash_duo):


def test_tehi002_set_axis(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Histogram")

driver.find_element(By.CLASS_NAME, "dd-single").click()
Expand All @@ -47,8 +38,7 @@ def test_tehi002_set_axis(dash_duo):

x.send_keys("mpg")
x.send_keys(Keys.RETURN)

time.sleep(1)
time.sleep(0.5)

assert "mpg" in driver.find_element(By.CLASS_NAME, "xtitle").text
assert dash_duo.get_logs() == [], "browser console should contain no error"
Expand All @@ -57,11 +47,7 @@ def test_tehi002_set_axis(dash_duo):


def test_tehi003_clear_clusters(dash_duo):
driver = dash_duo.driver
dash_duo.start_server(setup_xiplot_dash_app(data_dir="data"))
time.sleep(1)
dash_duo.wait_for_page()

driver = start_server(dash_duo)
render_plot(dash_duo, driver, "Histogram")

cluster_dd = driver.find_element(
Expand All @@ -80,9 +66,8 @@ def test_tehi003_clear_clusters(dash_duo):


def test_create_histogram():
d = {"col1": [1, 2], "col2": [3, 4]}
df = pd.DataFrame(data=d)
output = tmp("col1", "all", ["all", "all"], df, [])
df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
output = tmp("col1", "all", df, pd.DataFrame())
fig = output

assert str(type(fig)) == "<class 'plotly.graph_objs._figure.Figure'>"
2 changes: 1 addition & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from xiplot.plugin import get_plugins_cached
from xiplot.tabs.plugins import get_plugins_cached
from xiplot.utils.dataframe import read_functions, write_functions


Expand Down
Loading