def app() -> dash.Dash: dash_app = dash.Dash(__name__) dash_app.css.config.serve_locally = True dash_app.scripts.config.serve_locally = True dash_app.config.suppress_callback_exceptions = True CACHE.init_app(dash_app.server) yield dash_app
def test_parameter_corr(dash_duo: dash.testing.composite.DashComposite) -> None: app = dash.Dash(__name__) app.css.config.serve_locally = True app.scripts.config.serve_locally = True app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) app.webviz_settings = { "shared_settings": {"scratch_ensembles": {"iter-0": ""}}, "theme": default_theme, } ensembles = ["iter-0"] with mock.patch(GET_PARAMETERS) as mock_parameters: mock_parameters.return_value = pd.read_csv("tests/data/parameters.csv") parameter_correlation = ParameterCorrelation(app, ensembles) app.layout = parameter_correlation.layout dash_duo.start_server(app) my_component = dash_duo.find_element( f"#{parameter_correlation.ids('ensemble-all')}" ) if not my_component.text.startswith("iter-0"): raise AssertionError()
def test_inplace_volumes(dash_duo): app = dash.Dash(__name__) app.css.config.serve_locally = True app.scripts.config.serve_locally = True app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) container_settings = {"scratch_ensembles": {"iter-0": "", "iter-1": ""}} ensembles = ["iter-0", "iter-1"] volfiles = {"geogrid": "geogrid--oil.csv", "simgrid": "simgrid--oil.csv"} with mock.patch(extract_volumes) as mock_volumes: mock_volumes.return_value = pd.read_csv("tests/data/volumes.csv") vol = InplaceVolumes(app, container_settings, ensembles, volfiles) app.layout = vol.layout dash_duo.start_server(app) if ("Stock Tank Oil Initially Inplace" not in dash_duo.wait_for_element(f"#{vol.response_id}").text): raise AssertionError() if dash_duo.get_logs() != []: raise AssertionError()
def test_initialized_table_plotter(dash_duo): app = dash.Dash(__name__) app.css.config.serve_locally = True app.scripts.config.serve_locally = True app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) app.webviz_settings = {"theme": default_theme} csv_file = "./tests/data/example_data.csv" plot_options = dict( x="Well", y="Initial reservoir pressure (bar)", size="Average permeability (D)", facet_col="Segment", ) page = _table_plotter.TablePlotter(app, csv_file, lock=True, plot_options=plot_options) app.layout = page.layout dash_duo.start_server(app) # Wait for the app to render(there is probably a better way...) # Checking that plot options are defined assert page.plot_options == plot_options assert page.lock # Checking that the selectors are hidden selector_row = dash_duo.find_element("#" + page.uuid("selector-row")) assert "display: none;" in selector_row.get_attribute("style")
def test_table_plotter(dash_duo): app = dash.Dash(__name__) app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) app.webviz_settings = {"theme": default_theme} csv_file = "./tests/data/example_data.csv" page = _table_plotter.TablePlotter(app, csv_file) app.layout = page.layout dash_duo.start_server(app) # Wait for the app to render(there is probably a better way...) time.sleep(5) # Checking that no plot options are defined assert page.plot_options == {} # Check that filter is not active assert not page.use_filter # Checking that the correct plot type is initialized plot_dd = dash_duo.find_element("#" + page.uuid("plottype")) assert plot_dd.text == "scatter" # Checking that only the relevant options are shown for plot_option in page.plot_args.keys(): plot_option_dd = dash_duo.find_element("#" + page.uuid(f"div-{plot_option}")) if plot_option not in page.plots["scatter"]: assert plot_option_dd.get_attribute("style") == "display: none;" # Checking that options are initialized correctly for option in ["x", "y"]: plot_option_dd = dash_duo.find_element("#" + page.uuid(f"dropdown-{option}")) assert plot_option_dd.text == "Well"
def test_data_table(dash_duo): app = dash.Dash(__name__) app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) code_file = "./tests/data/example_data.csv" with mock.patch(GET_DATA) as mock_path: mock_path.return_value = pd.read_csv(code_file) page = _data_table.DataTable(code_file) app.layout = page.layout dash_duo.start_server(app) assert dash_duo.get_logs( ) == [], "browser console should contain no error"
def test_syntax_highlighter(dash_duo): app = dash.Dash(__name__) app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) code_file = Path("./tests/data/basic_example.yaml") with mock.patch( "webviz_config.plugins._syntax_highlighter.get_path") as mock_path: mock_path.return_value = code_file page = _syntax_highlighter.SyntaxHighlighter(app, code_file) app.layout = page.layout dash_duo.start_server(app) assert dash_duo.get_logs( ) == [], "browser console should contain no error"
def app() -> dash.Dash: run_mode = WebvizRunMode.NON_PORTABLE storage_folder = pathlib.Path(__file__).resolve().parent app_instance_info = WebvizInstanceInfo(run_mode, storage_folder) try: WEBVIZ_FACTORY_REGISTRY.initialize(app_instance_info, None) except RuntimeError: pass dash_app = dash.Dash(__name__) dash_app.css.config.serve_locally = True dash_app.scripts.config.serve_locally = True dash_app.config.suppress_callback_exceptions = True CACHE.init_app(dash_app.server) yield dash_app
def test_example_plugin(dash_duo): app = dash.Dash(__name__) app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) title = "Example" page = _example_plugin.ExamplePlugin(app, title) app.layout = page.layout dash_duo.start_server(app) btn = dash_duo.find_element("#" + page.uuid("submit-button")) assert btn.text == "Submit" text = dash_duo.find_element("#" + page.uuid("output-state")) assert text.text == "Button has been pressed 0 times." btn.click() dash_duo.wait_for_contains_text("#" + page.uuid("output-state"), "Button has been pressed 1 times", timeout=2) assert text.text == "Button has been pressed 1 times."
def app() -> dash.Dash: dash_app = dash.Dash(__name__) WEBVIZ_INSTANCE_INFO.initialize( dash_app=dash_app, run_mode=WebvizRunMode.NON_PORTABLE, theme=default_theme, storage_folder=pathlib.Path(__file__).resolve().parent, ) try: WEBVIZ_FACTORY_REGISTRY.initialize(None) except RuntimeError: pass dash_app.css.config.serve_locally = True dash_app.scripts.config.serve_locally = True dash_app.config.suppress_callback_exceptions = True CACHE.init_app(dash_app.server) yield dash_app
def test_create_themed_layout_on_app(dash_duo): # Test themed with a running app app = dash.Dash(__name__) app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) code_file = Path("./tests/data/basic_example.yaml") with mock.patch( "webviz_config.generic_plugins._syntax_highlighter.get_path" ) as mock_path: mock_path.return_value = code_file page = _syntax_highlighter.SyntaxHighlighter(app, code_file) app.layout = page.layout dash_duo.start_server(app) # empty input dict should return the theme layout assert default_theme.plotly_theme[ "layout"] == default_theme.create_themed_layout({}) # empty input dict should return the theme layout specified_layout = { "colorway": ["#FFFFFF", "#0000FF"], "xaxis": { "title": { "text": "Title" }, "type": "log", "constrain": "domain" }, "legend": { "font": { "family": "Arial" } }, } # create a new layout from specified and theme layouts new_layout = default_theme.create_themed_layout(specified_layout) # test some values assert new_layout["colorway"] == specified_layout["colorway"] assert new_layout["xaxis"]["title"]["text"] == "Title" assert dash_duo.get_logs( ) == [], "browser console should contain no error"
def test_parameter_corr(dash_duo): app = dash.Dash(__name__) app.css.config.serve_locally = True app.scripts.config.serve_locally = True app.config.suppress_callback_exceptions = True CACHE.init_app(app.server) container_settings = {"scratch_ensembles": {"iter-0": ""}} ensembles = ["iter-0"] with mock.patch(get_parameters) as mock_parameters: mock_parameters.return_value = pd.read_csv("tests/data/parameters.csv") p = ParameterCorrelation(app, container_settings, ensembles) app.layout = p.layout dash_duo.start_server(app) my_component = dash_duo.find_element(f"#{p.ens_matrix_id}") if not my_component.text.startswith("iter-0"): raise AssertionError()
) app.logger.setLevel(logging.WARNING) server = app.server app.title = "Reek Webviz Example" app.config.suppress_callback_exceptions = True app.webviz_settings = { "shared_settings": webviz_config.SHARED_SETTINGS_SUBSCRIPTIONS.transformed_settings( {'scratch_ensembles': {'sens_run': '../reek_fullmatrix/realization-*/iter-0', 'iter-0': '../reek_history_match/realization-*/iter-0', 'iter-1': '../reek_history_match/realization-*/iter-1', 'iter-2': '../reek_history_match/realization-*/iter-2', 'iter-3': '../reek_history_match/realization-*/iter-3'}}, PosixPath('/usr/src/webviz-subsurface-testdata/webviz_examples'), True ), "portable": True, "theme": theme, } CACHE.init_app(server) theme.adjust_csp({"script-src": app.csp_hashes()}, append=True) Talisman(server, content_security_policy=theme.csp, feature_policy=theme.feature_policy) WEBVIZ_STORAGE.get_stored_data = WEBVIZ_BLOB_STORAGE.get_stored_data WEBVIZ_STORAGE.use_storage = True WEBVIZ_STORAGE.storage_folder = Path(__file__).resolve().parent / "webviz_storage" WEBVIZ_ASSETS.portable = True if False and not webviz_config.is_reload_process(): # When Dash/Flask is started on localhost with hot module reload activated, # we do not want the main process to call expensive component functions in # the layout tree, as the layout tree used on initialization will anyway be called # from the child/restart/reload process.