-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add dataframe filtering and sorting tests (#1369)
Co-authored-by: Barret Schloerke <[email protected]>
- Loading branch information
1 parent
eb65d62
commit 7cd9e5e
Showing
7 changed files
with
315 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tests/playwright/shiny/components/data_frame/html_columns_df/df_organization/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pandas as pd | ||
import seaborn as sns | ||
|
||
from shiny import App, Inputs, Outputs, Session, reactive, render, ui | ||
|
||
df = pd.DataFrame( | ||
sns.load_dataset( # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] | ||
"iris" | ||
) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] | ||
) | ||
|
||
distinct_df = df.drop_duplicates(subset=["species"]) | ||
app_ui = ui.page_fluid( | ||
ui.row( | ||
ui.column( | ||
6, | ||
ui.h2("Iris Dataset"), | ||
), | ||
ui.column(2, ui.input_action_button("reset_df", "Reset Dataframe")), | ||
), | ||
ui.output_data_frame("iris_df"), | ||
ui.h2("Data view indices"), | ||
ui.output_text_verbatim("data_view_indices"), | ||
ui.h2("Indices when view_selected=True"), | ||
ui.output_text_verbatim("data_view_selected_true"), | ||
ui.h2("Indices when view_selected=False"), | ||
ui.output_text_verbatim("data_view_selected_false"), | ||
ui.h2("Show selected cell"), | ||
ui.output_text_verbatim("cell_selection"), | ||
) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session) -> None: | ||
|
||
@render.data_frame | ||
def iris_df(): | ||
return render.DataGrid( | ||
data=distinct_df, # pyright: ignore[reportUnknownArgumentType] | ||
filters=True, | ||
selection_mode="rows", | ||
) | ||
|
||
@render.code # pyright: ignore[reportArgumentType] | ||
def data_view_indices(): | ||
return iris_df._input_data_view_indices() | ||
|
||
@render.code # pyright: ignore[reportArgumentType] | ||
def data_view_selected_false(): # pyright: ignore[reportUnknownParameterType] | ||
return iris_df.data_view( | ||
selected=False | ||
).index.values # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] | ||
|
||
@render.code # pyright: ignore[reportArgumentType] | ||
def data_view_selected_true(): # pyright: ignore[reportUnknownParameterType] | ||
return iris_df.data_view( | ||
selected=True | ||
).index.values # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] | ||
|
||
@render.code # pyright: ignore[reportArgumentType] | ||
def cell_selection(): # pyright: ignore[reportUnknownParameterType] | ||
return iris_df.input_cell_selection()["rows"] # pyright: ignore | ||
|
||
@reactive.Effect | ||
@reactive.event(input.reset_df) | ||
def reset_df(): | ||
iris_df._reset_reactives() | ||
|
||
|
||
app = App(app_ui, server) |
77 changes: 77 additions & 0 deletions
77
...right/shiny/components/data_frame/html_columns_df/df_organization/test_df_organization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from conftest import ShinyAppProc | ||
from controls import InputActionButton, OutputCode, OutputDataFrame | ||
from playwright.sync_api import Page | ||
|
||
|
||
def test_dataframe_organization_methods(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
data_frame = OutputDataFrame(page, "iris_df") | ||
input_view_indices = OutputCode(page, "data_view_indices") | ||
input_view_selected_true = OutputCode(page, "data_view_selected_true") | ||
input_view_selected_false = OutputCode(page, "data_view_selected_false") | ||
input_cell_selection = OutputCode(page, "cell_selection") | ||
reset_df = InputActionButton(page, "reset_df") | ||
|
||
# assert value of unsorted table | ||
input_view_indices.expect_value("(0, 1, 2)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[ 0 50 100]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# sort column by number descending | ||
data_frame.set_column_sort(col=0) | ||
input_view_indices.expect_value("(1, 2, 0)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[ 50 100 0]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# sort column by number ascending | ||
data_frame.set_column_sort(col=0) | ||
input_view_indices.expect_value("(0, 2, 1)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[ 0 100 50]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# sort column by text ascending | ||
data_frame.set_column_sort(col=4) | ||
input_view_indices.expect_value("(0, 1, 2)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[ 0 50 100]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# sort column by text descending | ||
data_frame.set_column_sort(col=4) | ||
input_view_indices.expect_value("(2, 1, 0)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[100 50 0]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# reset dataframe | ||
reset_df.click() | ||
|
||
# filter using numbers | ||
data_frame.set_column_filter(col=0, text=["6", "7"]) | ||
input_view_indices.expect_value("(1, 2)") | ||
input_view_selected_true.expect_value("[]") | ||
input_view_selected_false.expect_value("[ 50 100]") | ||
input_cell_selection.expect_value("()") | ||
|
||
# reset dataframe | ||
reset_df.click() | ||
|
||
# select multiple rows | ||
data_frame.select_rows([0, 2]) | ||
input_view_indices.expect_value("(0, 1, 2)") | ||
input_view_selected_true.expect_value("[ 0 100]") | ||
input_view_selected_false.expect_value("[ 0 50 100]") | ||
input_cell_selection.expect_value("(0, 2)") | ||
|
||
# reset dataframe | ||
reset_df.click() | ||
|
||
# select single row | ||
data_frame.select_rows([0]) | ||
input_view_indices.expect_value("(0, 1, 2)") | ||
input_view_selected_true.expect_value("[0]") | ||
input_view_selected_false.expect_value("[ 0 50 100]") | ||
input_cell_selection.expect_value("(0,)") |
32 changes: 32 additions & 0 deletions
32
tests/playwright/shiny/components/data_frame/html_columns_df/tabbing/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pandas as pd | ||
import seaborn as sns | ||
|
||
from shiny import App, Inputs, Outputs, Session, render, ui | ||
|
||
df = pd.DataFrame( | ||
sns.load_dataset( | ||
"iris" | ||
) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] | ||
) | ||
app_ui = ui.page_fluid( | ||
ui.h2("Iris Dataset"), | ||
ui.output_data_frame("iris_df"), | ||
) | ||
|
||
df["sepal_length"] = df["sepal_length"].apply(lambda x: ui.HTML(f"<u>{x}</u>")) # type: ignore | ||
df["sepal_width"] = df["sepal_width"].apply(lambda x: ui.HTML(f"<u>{x}</u>")) # type: ignore | ||
df["petal_width"] = df["petal_width"].apply(lambda x: ui.HTML(f"<u>{x}</u>")) # type: ignore | ||
df["species"] = df["species"].apply(lambda x: ui.HTML(f"<u>{x}</u>")) # type: ignore | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session) -> None: | ||
|
||
@render.data_frame | ||
def iris_df(): | ||
return render.DataGrid( | ||
data=df.head(), # pyright: ignore[reportUnknownArgumentType] | ||
editable=True, | ||
) | ||
|
||
|
||
app = App(app_ui, server) |
20 changes: 20 additions & 0 deletions
20
tests/playwright/shiny/components/data_frame/html_columns_df/tabbing/test_tabbing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from conftest import ShinyAppProc | ||
from controls import OutputDataFrame | ||
from playwright.sync_api import Page | ||
|
||
|
||
def test_validate_html_columns(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
data_frame = OutputDataFrame(page, "iris_df") | ||
# Data frame with html content in the first two columns; Edit a cell in the third column and try to hit `shift + tab`. It should not submit the edit in the current cell and stay at the current cell (not moving to the second or first column) | ||
data_frame.expect_cell("1.4", row=0, col=2) | ||
data_frame.save_cell("152", row=0, col=2, save_key="Shift+Tab") | ||
data_frame.expect_cell("1.4", row=0, col=2) | ||
data_frame.expect_cell_class("cell-edit-editing", row=0, col=2) | ||
|
||
# Data frame with html content in the last two columns; Edit a cell in the third from last column and try to hit `tab`. It should not submit the edit in the current cell and stay at the current cell (not moving to the last two columns) | ||
data_frame.expect_cell("1.4", row=0, col=2) | ||
data_frame.save_cell("152", row=0, col=2, save_key="Tab") | ||
data_frame.expect_cell("1.4", row=0, col=2) | ||
data_frame.expect_cell_class("cell-edit-editing", row=0, col=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters