Skip to content

Commit

Permalink
merge... but playwright still not passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Oct 2, 2024
2 parents bfc07a1 + dc3eb10 commit 580c14d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source = .

omit =
# TODO
app.py
dp_creator_ii/app/*

# More strict: Check transitions between lines, not just individual lines.
# TODO: branch = True
Expand Down
23 changes: 23 additions & 0 deletions dp_creator_ii/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from shiny import App, ui

from dp_creator_ii.app import analysis_panel, dataset_panel, results_panel


app_ui = ui.page_bootstrap(
ui.navset_tab(
dataset_panel.dataset_ui(),
analysis_panel.analysis_ui(),
results_panel.results_ui(),
id="top_level_nav",
),
title="DP Creator II",
)


def server(input, output, session):
dataset_panel.dataset_server(input, output, session)
analysis_panel.analysis_server(input, output, session)
results_panel.results_server(input, output, session)


app = App(app_ui, server)
17 changes: 17 additions & 0 deletions dp_creator_ii/app/analysis_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from shiny import ui, reactive


def analysis_ui():
return ui.nav_panel(
"Define Analysis",
"TODO: Define analysis",
ui.input_action_button("go_to_results", "Download results"),
value="analysis_panel",
)


def analysis_server(input, output, session):
@reactive.effect
@reactive.event(input.go_to_results)
def go_to_results():
ui.update_navs("top_level_nav", selected="results_panel")
43 changes: 43 additions & 0 deletions dp_creator_ii/app/dataset_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import argv

from shiny import ui, reactive, render

from dp_creator_ii import get_arg_parser


def dataset_ui():
return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.output_text("csv_path_text"),
ui.output_text("unit_of_privacy_text"),
ui.input_action_button("go_to_analysis", "Perform analysis"),
value="dataset_panel",
)


def dataset_server(input, output, session):
if argv[1:3] == ["run", "--port"]:
# Started by playwright
arg_csv_path = None
arg_unit_of_privacy = None
else:
args = get_arg_parser().parse_args()
arg_csv_path = args.csv_path
arg_unit_of_privacy = args.unit_of_privacy

csv_path = reactive.value(arg_csv_path)
unit_of_privacy = reactive.value(arg_unit_of_privacy)

@render.text
def csv_path_text():
return str(csv_path.get())

@render.text
def unit_of_privacy_text():
return str(unit_of_privacy.get())

@reactive.effect
@reactive.event(input.go_to_analysis)
def go_to_analysis():
ui.update_navs("top_level_nav", selected="analysis_panel")
70 changes: 3 additions & 67 deletions dp_creator_ii/app.py → dp_creator_ii/app/results_panel.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
from sys import argv
from shiny import ui, render

from shiny import App, ui, reactive, render

from dp_creator_ii import get_arg_parser
from dp_creator_ii.template import make_notebook_py, make_script_py
from dp_creator_ii.converters import convert_py_to_nb


def dataset_panel():
return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.output_text("csv_path_text"),
ui.output_text("unit_of_privacy_text"),
ui.input_action_button("go_to_analysis", "Perform analysis"),
value="dataset_panel",
)


def analysis_panel():
return ui.nav_panel(
"Perform Analysis",
"TODO: Perform analysis",
ui.input_action_button("go_to_results", "Download results"),
value="analysis_panel",
)


def results_panel():
def results_ui():
return ui.nav_panel(
"Download results",
"TODO: Download results",
Expand All @@ -43,45 +20,7 @@ def results_panel():
)


app_ui = ui.page_bootstrap(
ui.navset_tab(
dataset_panel(),
analysis_panel(),
results_panel(),
id="top_level_nav",
),
title="DP Creator II",
)


def server(input, output, session):
if argv[1:3] == ["run", "--port"]:
# Started by playwright
csv_path = None
unit_of_privacy = None
else:
args = get_arg_parser().parse_args()
csv_path = reactive.value(args.csv_path)
unit_of_privacy = reactive.value(args.unit_of_privacy)

@render.text
def csv_path_text():
return str(csv_path.get())

@render.text
def unit_of_privacy_text():
return str(unit_of_privacy.get())

@reactive.effect
@reactive.event(input.go_to_analysis)
def go_to_analysis():
ui.update_navs("top_level_nav", selected="analysis_panel")

@reactive.effect
@reactive.event(input.go_to_results)
def go_to_results():
ui.update_navs("top_level_nav", selected="results_panel")

def results_server(input, output, session):
@render.download(
filename="dp-creator-script.py",
media_type="text/x-python",
Expand Down Expand Up @@ -121,6 +60,3 @@ async def download_notebook_executed():
)
notebook_nb = convert_py_to_nb(notebook_py, execute=True)
yield notebook_nb


app = App(app_ui, server)
6 changes: 3 additions & 3 deletions dp_creator_ii/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from shiny.pytest import create_app_fixture


app = create_app_fixture("../app.py")
app = create_app_fixture("../app/__init__.py")


# TODO: Why is incomplete coverage reported here?
# https://github.com/opendp/dp-creator-ii/issues/18
def test_app(page: Page, app: ShinyAppProc): # pragma: no cover
pick_dataset_text = "TODO: Pick dataset"
perform_analysis_text = "TODO: Perform analysis"
perform_analysis_text = "TODO: Define analysis"
download_results_text = "TODO: Download results"

def expect_visible(text):
Expand All @@ -25,7 +25,7 @@ def expect_not_visible(text):
expect_not_visible(perform_analysis_text)
expect_not_visible(download_results_text)

page.get_by_role("button", name="Perform analysis").click()
page.get_by_role("button", name="Define analysis").click()
expect_not_visible(pick_dataset_text)
expect_visible(perform_analysis_text)
expect_not_visible(download_results_text)
Expand Down

0 comments on commit 580c14d

Please sign in to comment.