From fe769e06a2f16434ce323aef949b83c336df5654 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:11:03 +0100 Subject: [PATCH 01/17] add ids for sidebar and sidebar links --- wazp/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wazp/app.py b/wazp/app.py index e1b6156..29396f7 100644 --- a/wazp/app.py +++ b/wazp/app.py @@ -54,6 +54,7 @@ dbc.Nav( children=[ dcc.Link( + id="link-" + page["name"].replace(" ", "-"), children=f"{page['name']}", href=page["relative_path"], # url of each page ) @@ -64,6 +65,7 @@ ), ], style=SIDEBAR_STYLE, + id="sidebar", ) # Main content style From 94cdddf7d904f7318e996c1701341450464a27cb Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:13:46 +0100 Subject: [PATCH 02/17] add tests to check components common to all pages are created correctly --- tests/test_integration/test_common_layout.py | 137 +++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/test_integration/test_common_layout.py diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py new file mode 100644 index 0000000..bef4dcb --- /dev/null +++ b/tests/test_integration/test_common_layout.py @@ -0,0 +1,137 @@ +import dash +import pytest +import selenium +from dash.testing.composite import DashComposite + +from wazp.app import app + + +@pytest.fixture +def map_page_name_to_title(): + return { + "Home": "Home", + "01 metadata": "Metadata", + "02 roi": "ROI definition", + "03 pose estimation": "Pose estimation inference", + "04 dashboard": "Dashboard & data export", + } + + +# Q for review: is this overkill? +@pytest.fixture() +def timeout(): + """Maximum time to wait for a component + to be located in layout + + Returns + ------- + timeout : float + maximum time to wait in seconds + """ + return 4 + + +# NOTE: pass the 'no_cover' fixture to allow debugging in VSCode? +# @pytest.mark.no_cover +def test_components_created( + dash_duo: DashComposite, + timeout: float, +) -> None: + """Check that the components common to all pages are created. + + The components common to all pages are the page content container and + the sidebar. + + Parameters: + dash_duo : DashComposite + Default fixture for Dash Python integration tests. + timeout : float + maximum time to wait in seconds for a component + """ + + # start server + dash_duo.start_server(app) + + # wait for main content to be rendered + try: + dash_duo.wait_for_element("#page-content", timeout=timeout) + except selenium.common.exceptions.TimeoutException: + pytest.fail("Main content component not generated") + + # wait for sidebar to be rendered + try: + dash_duo.wait_for_text_to_equal( + "#sidebar h2", "WAZP 🐝", timeout=timeout + ) + except selenium.common.exceptions.TimeoutException: + pytest.fail("Sidebar component not generated") + + # check there are no errors in browser console + assert ( + dash_duo.get_logs() == [] + ), "There are errors in the browser console!" + + +@pytest.mark.xfail( + raises=AssertionError, + reason=( + "Feature not yet implemented:" + "When config has not been loaded, " + "warnings should show in pages that are not Home" + ), + strict=True, + # if the test passes unexpectedly, + # it will fail the test suite +) +def test_sidebar_links( + dash_duo: DashComposite, + map_page_name_to_title: dict, + timeout: float, +) -> None: + """Check the sidebar links take to pages with the expected title + and that no errors occur in the browser console + + Parameters: + dash_duo : DashComposite + Default fixture for Dash Python integration tests. + map_page_name_to_title: dictionary : dict + dictionary with page names as keys, and page titles as values + timeout : float + maximum time to wait in seconds for a component + """ + + # start server + dash_duo.start_server(app) + + # click through links in sidebar + for page in dash.page_registry.values(): + + # click thru each page + dash_duo.find_element( + "#sidebar #link-" + page["name"].replace(" ", "-"), + ).click() + + # check page title + try: + dash_duo.wait_for_text_to_equal( + "h1", map_page_name_to_title[page["name"]], timeout=timeout + ) + + except selenium.common.exceptions.TimeoutException: + pytest.fail( + f'Timeout waiting for page {page["name"]} ' + "to show a title with the text: " + f'{map_page_name_to_title[page["name"]]}' + ) + + # click back to home + # TODO: to make starting point consistent...but is it required? + dash_duo.find_element("#sidebar #link-Home").click() + + # TODO: if no config file has been loaded, check warning is shown? + # ... + + # NOTE: this will now fail + assert ( + dash_duo.get_logs() == [] + ), "There are errors in the browser console!" From 6aa95f7bb7eb9a792314f9aac0727a50c1f232ca Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:24:35 +0100 Subject: [PATCH 03/17] add docstring for map fixture and clean comments for review --- tests/test_integration/test_common_layout.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index bef4dcb..a02f779 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -8,6 +8,13 @@ @pytest.fixture def map_page_name_to_title(): + """Map page names to page head titles + + Returns + ------- + dict + dictionary with page names as keys, and page titles as values + """ return { "Home": "Home", "01 metadata": "Metadata", @@ -17,7 +24,6 @@ def map_page_name_to_title(): } -# Q for review: is this overkill? @pytest.fixture() def timeout(): """Maximum time to wait for a component @@ -28,11 +34,9 @@ def timeout(): timeout : float maximum time to wait in seconds """ - return 4 + return 4 # Q for review: is this overkill? -# NOTE: pass the 'no_cover' fixture to allow debugging in VSCode? -# @pytest.mark.no_cover def test_components_created( dash_duo: DashComposite, timeout: float, @@ -80,6 +84,7 @@ def test_components_created( "warnings should show in pages that are not Home" ), strict=True, + # with strict=True # if the test passes unexpectedly, # it will fail the test suite ) @@ -125,13 +130,14 @@ def test_sidebar_links( ) # click back to home - # TODO: to make starting point consistent...but is it required? + # Q for review: I do this to make the starting point consistent... + # but is it required? should I use fixtures instead? dash_duo.find_element("#sidebar #link-Home").click() - # TODO: if no config file has been loaded, check warning is shown? + # TODO: if no config file has been loaded, check a warning is shown? # ... - # NOTE: this will now fail + # NOTE: this is expected to fail assert ( dash_duo.get_logs() == [] ), "There are errors in the browser console!" From f8d4d026b94ebe5504487547fc50e599b3496ff7 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 11:17:47 +0100 Subject: [PATCH 04/17] move fixtures to conftest --- tests/test_integration/conftest.py | 32 ++++++++++++++ tests/test_integration/test_common_layout.py | 46 ++++---------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/tests/test_integration/conftest.py b/tests/test_integration/conftest.py index 83b5dc1..0d1e2ad 100644 --- a/tests/test_integration/conftest.py +++ b/tests/test_integration/conftest.py @@ -1,3 +1,4 @@ +import pytest from selenium.webdriver.chrome.options import Options @@ -6,3 +7,34 @@ def pytest_setup_options(): options.add_argument("--headless") options.add_argument("--disable-gpu") return options + + +@pytest.fixture +def map_page_name_to_title() -> dict: + """Map page names to page head titles + + Returns + ------- + dict + dictionary with page names as keys, and page titles as values + """ + return { + "Home": "Home", + "01 metadata": "Metadata", + "02 roi": "ROI definition", + "03 pose estimation": "Pose estimation inference", + "04 dashboard": "Dashboard & data export", + } + + +@pytest.fixture +def timeout() -> float: + """Maximum time to wait for a component + to be located in layout + + Returns + ------- + timeout : float + maximum time to wait in seconds + """ + return 4 diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index a02f779..366ed4e 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -6,45 +6,15 @@ from wazp.app import app -@pytest.fixture -def map_page_name_to_title(): - """Map page names to page head titles - - Returns - ------- - dict - dictionary with page names as keys, and page titles as values - """ - return { - "Home": "Home", - "01 metadata": "Metadata", - "02 roi": "ROI definition", - "03 pose estimation": "Pose estimation inference", - "04 dashboard": "Dashboard & data export", - } - - -@pytest.fixture() -def timeout(): - """Maximum time to wait for a component - to be located in layout - - Returns - ------- - timeout : float - maximum time to wait in seconds - """ - return 4 # Q for review: is this overkill? - - def test_components_created( dash_duo: DashComposite, timeout: float, ) -> None: - """Check that the components common to all pages are created. + """Check that the components that are common to all pages are created. - The components common to all pages are the page content container and - the sidebar. + The components common to all pages are: + - the page content container, and + - the sidebar. Parameters: dash_duo : DashComposite @@ -56,7 +26,7 @@ def test_components_created( # start server dash_duo.start_server(app) - # wait for main content to be rendered + # wait for main content container to be rendered try: dash_duo.wait_for_element("#page-content", timeout=timeout) except selenium.common.exceptions.TimeoutException: @@ -73,7 +43,8 @@ def test_components_created( # check there are no errors in browser console assert ( dash_duo.get_logs() == [] - ), "There are errors in the browser console!" + ), f"There are {len(dash_duo.get_logs())} errors" + " in the browser console!" @pytest.mark.xfail( @@ -130,8 +101,7 @@ def test_sidebar_links( ) # click back to home - # Q for review: I do this to make the starting point consistent... - # but is it required? should I use fixtures instead? + # NOTE: consider doing this via test parametrisation dash_duo.find_element("#sidebar #link-Home").click() # TODO: if no config file has been loaded, check a warning is shown? From 8cb7ebb608714fd102110ea470ad1c76b167be62 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 11:31:56 +0100 Subject: [PATCH 05/17] parametrise test sidebar links --- tests/test_integration/test_common_layout.py | 96 ++++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 366ed4e..9de7543 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -1,4 +1,3 @@ -import dash import pytest import selenium from dash.testing.composite import DashComposite @@ -47,20 +46,43 @@ def test_components_created( " in the browser console!" -@pytest.mark.xfail( - raises=AssertionError, - reason=( - "Feature not yet implemented:" - "When config has not been loaded, " - "warnings should show in pages that are not Home" - ), - strict=True, - # with strict=True - # if the test passes unexpectedly, - # it will fail the test suite +# @pytest.mark.xfail( +# raises=AssertionError, +# reason=( +# "Feature not yet implemented:" +# "When config has not been loaded, " +# "warnings should show in pages that are not Home" +# ), +# strict=True, +# # with strict=True +# # if the test passes unexpectedly, +# # it will fail the test suite +# ) +@pytest.mark.parametrize( + "page_name", + [ + pytest.param( + name, + marks=pytest.mark.xfail( + reason=( + "Feature not yet implemented:" + "When config has not been loaded, " + "warnings should show in pages that are not Home" + ) + ), + ) + for name in [ + "Home", + "01 metadata", + "02 roi", + "03 pose estimation", + "04 dashboard", + ] + ], ) def test_sidebar_links( dash_duo: DashComposite, + page_name: str, map_page_name_to_title: dict, timeout: float, ) -> None: @@ -70,6 +92,8 @@ def test_sidebar_links( Parameters: dash_duo : DashComposite Default fixture for Dash Python integration tests. + page : str + .... map_page_name_to_title: dictionary : dict dictionary with page names as keys, and page titles as values timeout : float @@ -80,32 +104,28 @@ def test_sidebar_links( dash_duo.start_server(app) # click through links in sidebar - for page in dash.page_registry.values(): - - # click thru each page - dash_duo.find_element( - "#sidebar #link-" + page["name"].replace(" ", "-"), - ).click() - - # check page title - try: - dash_duo.wait_for_text_to_equal( - "h1", map_page_name_to_title[page["name"]], timeout=timeout - ) - - except selenium.common.exceptions.TimeoutException: - pytest.fail( - f'Timeout waiting for page {page["name"]} ' - "to show a title with the text: " - f'{map_page_name_to_title[page["name"]]}' - ) - - # click back to home - # NOTE: consider doing this via test parametrisation - dash_duo.find_element("#sidebar #link-Home").click() - - # TODO: if no config file has been loaded, check a warning is shown? - # ... + # for page in dash.page_registry.values(): + + # click thru each page + dash_duo.find_element( + "#sidebar #link-" + page_name.replace(" ", "-"), + ).click() + + # check page title + try: + dash_duo.wait_for_text_to_equal( + "h1", map_page_name_to_title[page_name], timeout=timeout + ) + + except selenium.common.exceptions.TimeoutException: + pytest.fail( + f"Timeout waiting for page {page_name} " + "to show a title with the text: " + f"{map_page_name_to_title[page_name]}" + ) + + # TODO: if no config file has been loaded, check a warning is shown? + # ... # NOTE: this is expected to fail assert ( From eda18ce7d1e2f8c52f8043142ca6a911a22bd84d Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 11:47:35 +0100 Subject: [PATCH 06/17] add xfail for each parametrized case --- tests/test_integration/test_common_layout.py | 62 ++++++++------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 9de7543..6eff352 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -46,38 +46,28 @@ def test_components_created( " in the browser console!" -# @pytest.mark.xfail( -# raises=AssertionError, -# reason=( -# "Feature not yet implemented:" -# "When config has not been loaded, " -# "warnings should show in pages that are not Home" -# ), -# strict=True, -# # with strict=True -# # if the test passes unexpectedly, -# # it will fail the test suite -# ) +config_xfail = pytest.mark.xfail( + raises=AssertionError, + reason=( + "Feature not yet implemented:" + "When config has not been loaded, " + "warnings should show in pages that are not Home" + ), + strict=True, + # with strict=True + # if the test passes unexpectedly, + # it will fail the test suite +) + + @pytest.mark.parametrize( "page_name", [ - pytest.param( - name, - marks=pytest.mark.xfail( - reason=( - "Feature not yet implemented:" - "When config has not been loaded, " - "warnings should show in pages that are not Home" - ) - ), - ) - for name in [ - "Home", - "01 metadata", - "02 roi", - "03 pose estimation", - "04 dashboard", - ] + "Home", + pytest.param("01 metadata", marks=config_xfail), + pytest.param("02 roi", marks=config_xfail), + "03 pose estimation", # passes for now because not implemented yet :P + pytest.param("04 dashboard", marks=config_xfail), ], ) def test_sidebar_links( @@ -86,14 +76,16 @@ def test_sidebar_links( map_page_name_to_title: dict, timeout: float, ) -> None: - """Check the sidebar links take to pages with the expected title + """Check the sidebar links take to the corresponding pages and that no errors occur in the browser console + The pages are checked via their title. + Parameters: dash_duo : DashComposite Default fixture for Dash Python integration tests. page : str - .... + . map_page_name_to_title: dictionary : dict dictionary with page names as keys, and page titles as values timeout : float @@ -103,15 +95,12 @@ def test_sidebar_links( # start server dash_duo.start_server(app) - # click through links in sidebar - # for page in dash.page_registry.values(): - - # click thru each page + # click sidebar link dash_duo.find_element( "#sidebar #link-" + page_name.replace(" ", "-"), ).click() - # check page title + # check page title is expected try: dash_duo.wait_for_text_to_equal( "h1", map_page_name_to_title[page_name], timeout=timeout @@ -124,6 +113,7 @@ def test_sidebar_links( f"{map_page_name_to_title[page_name]}" ) + dash_duo.find_element("#sidebar #link-Home").click() # TODO: if no config file has been loaded, check a warning is shown? # ... From 97e64c2ca945fc014bae2b334fcf983fd5957230 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 12:08:03 +0100 Subject: [PATCH 07/17] use fixture in pytest parametrize --- tests/test_integration/test_common_layout.py | 45 ++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 6eff352..a00c99c 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -46,7 +46,7 @@ def test_components_created( " in the browser console!" -config_xfail = pytest.mark.xfail( +unloaded_config_xfail = pytest.mark.xfail( raises=AssertionError, reason=( "Feature not yet implemented:" @@ -61,20 +61,30 @@ def test_components_created( @pytest.mark.parametrize( - "page_name", + ("page_name_and_title"), [ - "Home", - pytest.param("01 metadata", marks=config_xfail), - pytest.param("02 roi", marks=config_xfail), - "03 pose estimation", # passes for now because not implemented yet :P - pytest.param("04 dashboard", marks=config_xfail), + "home_page_name_and_title", + pytest.param( + "metadata_page_name_and_title", marks=unloaded_config_xfail + ), + pytest.param("roi_page_name_and_title", marks=unloaded_config_xfail), + ( + "pose_estimation_page_name_and_title" + ), # passes for now because not implemented yet :P + pytest.param( + "dashboard_page_name_and_title", marks=unloaded_config_xfail + ), + # + # pytest.param(k, v, marks=unloaded_config_xfail) + # for k,v in map_page_name_to_title.items() ], ) def test_sidebar_links( dash_duo: DashComposite, - page_name: str, - map_page_name_to_title: dict, + page_name_and_title: str, + # page_title: str, timeout: float, + request, ) -> None: """Check the sidebar links take to the corresponding pages and that no errors occur in the browser console @@ -84,14 +94,17 @@ def test_sidebar_links( Parameters: dash_duo : DashComposite Default fixture for Dash Python integration tests. - page : str - . - map_page_name_to_title: dictionary : dict - dictionary with page names as keys, and page titles as values + page_name : str + name of the page in the dash registry + page_title: str + main title shown for a page timeout : float maximum time to wait in seconds for a component """ + # get fixture value + (page_name, page_title) = request.getfixturevalue(page_name_and_title) + # start server dash_duo.start_server(app) @@ -102,15 +115,13 @@ def test_sidebar_links( # check page title is expected try: - dash_duo.wait_for_text_to_equal( - "h1", map_page_name_to_title[page_name], timeout=timeout - ) + dash_duo.wait_for_text_to_equal("h1", page_title, timeout=timeout) except selenium.common.exceptions.TimeoutException: pytest.fail( f"Timeout waiting for page {page_name} " "to show a title with the text: " - f"{map_page_name_to_title[page_name]}" + f"{page_title}" ) dash_duo.find_element("#sidebar #link-Home").click() From 0428d4491a2ffd7a19cba15140afdc2b24d66d49 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 13:33:17 +0100 Subject: [PATCH 08/17] add fixture to parametrize --- tests/test_integration/test_common_layout.py | 22 +++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index a00c99c..0a021d1 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -63,20 +63,14 @@ def test_components_created( @pytest.mark.parametrize( ("page_name_and_title"), [ - "home_page_name_and_title", - pytest.param( - "metadata_page_name_and_title", marks=unloaded_config_xfail - ), - pytest.param("roi_page_name_and_title", marks=unloaded_config_xfail), - ( - "pose_estimation_page_name_and_title" - ), # passes for now because not implemented yet :P - pytest.param( - "dashboard_page_name_and_title", marks=unloaded_config_xfail - ), - # - # pytest.param(k, v, marks=unloaded_config_xfail) - # for k,v in map_page_name_to_title.items() + pytest.param(fx, marks=mark) + for fx, mark in [ + ("home_page_name_and_title", []), + ("metadata_page_name_and_title", unloaded_config_xfail), + ("roi_page_name_and_title", unloaded_config_xfail), + ("pose_estimation_page_name_and_title", []), + ("dashboard_page_name_and_title", unloaded_config_xfail), + ] ], ) def test_sidebar_links( From fcf406d26eb1a48983ed7ccced53c0d235c3e405 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 13:42:55 +0100 Subject: [PATCH 09/17] adding fixtures in conftest --- tests/test_integration/conftest.py | 53 ++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/test_integration/conftest.py b/tests/test_integration/conftest.py index 0d1e2ad..2f339f7 100644 --- a/tests/test_integration/conftest.py +++ b/tests/test_integration/conftest.py @@ -9,22 +9,47 @@ def pytest_setup_options(): return options +# @pytest.fixture +# def map_page_name_to_title() -> dict: +# """Map page names to page head titles + +# Returns +# ------- +# dict +# dictionary with page names as keys, and page titles as values +# """ +# return { +# "Home": "Home", +# "01 metadata": "Metadata", +# "02 roi": "ROI definition", +# "03 pose estimation": "Pose estimation inference", +# "04 dashboard": "Dashboard & data export", +# } + + @pytest.fixture -def map_page_name_to_title() -> dict: - """Map page names to page head titles +def home_page_name_and_title(): + return ("Home", "Home") - Returns - ------- - dict - dictionary with page names as keys, and page titles as values - """ - return { - "Home": "Home", - "01 metadata": "Metadata", - "02 roi": "ROI definition", - "03 pose estimation": "Pose estimation inference", - "04 dashboard": "Dashboard & data export", - } + +@pytest.fixture +def metadata_page_name_and_title(): + return ("01 metadata", "Metadata") + + +@pytest.fixture +def roi_page_name_and_title(): + return ("02 roi", "ROI definition") + + +@pytest.fixture +def pose_estimation_page_name_and_title(): + return ("03 pose estimation", "Pose estimation inference") + + +@pytest.fixture +def dashboard_page_name_and_title(): + return ("04 dashboard", "Dashboard & data export") @pytest.fixture From d748a5bb51f28826027c37c3b8324da3b7759b41 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 14:01:53 +0100 Subject: [PATCH 10/17] remove map from comftest. add question for review. --- tests/test_integration/conftest.py | 18 ------------------ tests/test_integration/test_common_layout.py | 3 +++ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/tests/test_integration/conftest.py b/tests/test_integration/conftest.py index 2f339f7..e2f9100 100644 --- a/tests/test_integration/conftest.py +++ b/tests/test_integration/conftest.py @@ -9,24 +9,6 @@ def pytest_setup_options(): return options -# @pytest.fixture -# def map_page_name_to_title() -> dict: -# """Map page names to page head titles - -# Returns -# ------- -# dict -# dictionary with page names as keys, and page titles as values -# """ -# return { -# "Home": "Home", -# "01 metadata": "Metadata", -# "02 roi": "ROI definition", -# "03 pose estimation": "Pose estimation inference", -# "04 dashboard": "Dashboard & data export", -# } - - @pytest.fixture def home_page_name_and_title(): return ("Home", "Home") diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 0a021d1..bc7cd11 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -60,6 +60,9 @@ def test_components_created( ) +# Q for review: is there a way to have this with +# one fixture only? +# https://docs.pytest.org/en/latest/how-to/skipping.html#skip-xfail-with-parametrize @pytest.mark.parametrize( ("page_name_and_title"), [ From 7c9d8e5fc240ebe25643eb732870ee5ca7300826 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 14:23:07 +0100 Subject: [PATCH 11/17] remove commented input arg --- tests/test_integration/test_common_layout.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index bc7cd11..17335f8 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -79,7 +79,6 @@ def test_components_created( def test_sidebar_links( dash_duo: DashComposite, page_name_and_title: str, - # page_title: str, timeout: float, request, ) -> None: From f08c594b9de65f1f8be5f4c53756c1bf099fa8a3 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 17:50:27 +0100 Subject: [PATCH 12/17] correct type in test input args Co-authored-by: Sam Cunliffe --- tests/test_integration/test_common_layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 17335f8..4451cab 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -78,7 +78,7 @@ def test_components_created( ) def test_sidebar_links( dash_duo: DashComposite, - page_name_and_title: str, + page_name_and_title: tuple(str), timeout: float, request, ) -> None: From 01fa4b04b1328f70f2b9e239a6a4c948a360a6c7 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 17:51:26 +0100 Subject: [PATCH 13/17] Update docstrings Co-authored-by: Sam Cunliffe --- tests/test_integration/test_common_layout.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 4451cab..010ed93 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -90,10 +90,8 @@ def test_sidebar_links( Parameters: dash_duo : DashComposite Default fixture for Dash Python integration tests. - page_name : str - name of the page in the dash registry - page_title: str - main title shown for a page + page_name_and_title : tuple(str) + name of the page in the dash registry and the main title shown on the page timeout : float maximum time to wait in seconds for a component """ From 2ce91fb24f45a93df411bfabad8614b3505aab4d Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 18:12:35 +0100 Subject: [PATCH 14/17] add type and docstrings for request input --- tests/test_integration/test_common_layout.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 010ed93..07f2bab 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -78,9 +78,9 @@ def test_components_created( ) def test_sidebar_links( dash_duo: DashComposite, - page_name_and_title: tuple(str), + page_name_and_title: tuple[str], timeout: float, - request, + request: pytest.FixtureRequest, ) -> None: """Check the sidebar links take to the corresponding pages and that no errors occur in the browser console @@ -90,10 +90,17 @@ def test_sidebar_links( Parameters: dash_duo : DashComposite Default fixture for Dash Python integration tests. - page_name_and_title : tuple(str) - name of the page in the dash registry and the main title shown on the page + page_name_and_title : tuple[str] + name of the page in the dash registry and the main title shown on + the page timeout : float maximum time to wait in seconds for a component + request : pytest.FixtureRequest + a special fixture providing information of the requesting test + function. See `pytest docs`_ + + .. _pytest docs: + https://docs.pytest.org/en/6.2.x/reference.html#std-fixture-request """ # get fixture value From 400e5645871ea464669f7d85830f0df880b7cdf8 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 18:12:55 +0100 Subject: [PATCH 15/17] change docstrings to numpy format --- tests/test_integration/test_common_layout.py | 41 +++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 07f2bab..0df98be 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -15,11 +15,12 @@ def test_components_created( - the page content container, and - the sidebar. - Parameters: - dash_duo : DashComposite - Default fixture for Dash Python integration tests. - timeout : float - maximum time to wait in seconds for a component + Parameters + ---------- + dash_duo : DashComposite + Default fixture for Dash Python integration tests. + timeout : float + maximum time to wait in seconds for a component """ # start server @@ -87,20 +88,22 @@ def test_sidebar_links( The pages are checked via their title. - Parameters: - dash_duo : DashComposite - Default fixture for Dash Python integration tests. - page_name_and_title : tuple[str] - name of the page in the dash registry and the main title shown on - the page - timeout : float - maximum time to wait in seconds for a component - request : pytest.FixtureRequest - a special fixture providing information of the requesting test - function. See `pytest docs`_ - - .. _pytest docs: - https://docs.pytest.org/en/6.2.x/reference.html#std-fixture-request + Parameters + ---------- + dash_duo : DashComposite + Default fixture for Dash Python integration tests. + page_name_and_title : tuple[str] + name of the page in the dash registry and the main title shown on + the page + timeout : float + maximum time to wait in seconds for a component + request : pytest.FixtureRequest + a special fixture providing information of the requesting test + function. See [1]_ + + References + ---------- + .. [1] https://docs.pytest.org/en/6.2.x/reference.html#std-fixture-request """ # get fixture value From f51e26638538a81e495653dadbcdb971d827951f Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 18 May 2023 18:44:57 +0100 Subject: [PATCH 16/17] extra time for windows? --- tests/test_integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_integration/conftest.py b/tests/test_integration/conftest.py index e2f9100..f3a5219 100644 --- a/tests/test_integration/conftest.py +++ b/tests/test_integration/conftest.py @@ -44,4 +44,4 @@ def timeout() -> float: timeout : float maximum time to wait in seconds """ - return 4 + return 8 # for Windows? From d91f1e81e8b0a80143b554bd2cb34bbba0d6ff68 Mon Sep 17 00:00:00 2001 From: Sam Cunliffe Date: Fri, 9 Jun 2023 17:08:29 +0100 Subject: [PATCH 17/17] The ROI page was not sending errors on Windows. So it was an XPASS and we had XFAIL strict (expected fail, but found the test to pass therefore FAIL). Without strict we get an XPASS on Windows. Something to investigate further as we add more tests. --- tests/test_integration/conftest.py | 2 +- tests/test_integration/test_common_layout.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_integration/conftest.py b/tests/test_integration/conftest.py index e2e3ff1..2328194 100644 --- a/tests/test_integration/conftest.py +++ b/tests/test_integration/conftest.py @@ -88,4 +88,4 @@ def timeout() -> float: timeout : float maximum time to wait in seconds """ - return 8 # for Windows? + return 4 diff --git a/tests/test_integration/test_common_layout.py b/tests/test_integration/test_common_layout.py index 0df98be..7b1e9d6 100644 --- a/tests/test_integration/test_common_layout.py +++ b/tests/test_integration/test_common_layout.py @@ -54,7 +54,7 @@ def test_components_created( "When config has not been loaded, " "warnings should show in pages that are not Home" ), - strict=True, + strict=False, # with strict=True # if the test passes unexpectedly, # it will fail the test suite @@ -132,7 +132,7 @@ def test_sidebar_links( # TODO: if no config file has been loaded, check a warning is shown? # ... - # NOTE: this is expected to fail + # NOTE: this is expected to fail for a few pages (hence the marked xfails) assert ( dash_duo.get_logs() == [] ), "There are errors in the browser console!"