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

[WIP] Add more GUI tests #1042

Draft
wants to merge 33 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ec8b780
Add test for getting non visible items from the database
robintw Sep 28, 2021
99bd48f
Update test
robintw Sep 28, 2021
93ebc03
Add initial interactive GUI tests
robintw Sep 30, 2021
75fb2dd
Add new pytest plugin dependency
robintw Sep 30, 2021
5a181fc
Turn off showing output
robintw Sep 30, 2021
6dca738
Add test for delete action
robintw Sep 30, 2021
9062f98
Don't show output
robintw Sep 30, 2021
231a495
Add back old pyte-based tests
robintw Sep 30, 2021
6d518ef
Add debugging to try and fix CI-only failures
robintw Sep 30, 2021
2ec35f1
Simplify CI config
robintw Sep 30, 2021
7c0d36c
Switch to alt_pytest_asyncio
robintw Sep 30, 2021
03dd874
Replace with stupidly simple test
robintw Sep 30, 2021
72b7106
Add await
robintw Sep 30, 2021
3b995e3
Gradually add more content back in
robintw Sep 30, 2021
875c52c
Add keypress sending
robintw Sep 30, 2021
103e782
Try without autoexit
robintw Sep 30, 2021
18d9b26
Remove test that required autoexit=True
robintw Sep 30, 2021
ed0760c
Remove debug prints and add extra delay
robintw Sep 30, 2021
e0a85d3
Remove check
robintw Sep 30, 2021
e3197d1
Tests again
robintw Sep 30, 2021
7d5fd7f
More tests
robintw Sep 30, 2021
2139c5c
Try without initing datastore
robintw Sep 30, 2021
9409438
Change test
robintw Sep 30, 2021
a75772e
Add extra sleep
robintw Sep 30, 2021
3506971
Add sleep
robintw Sep 30, 2021
173eaa2
Add logging
robintw Sep 30, 2021
47069f1
More logs
robintw Sep 30, 2021
14a21a2
Try more delays
robintw Sep 30, 2021
1032afb
More testing
robintw Sep 30, 2021
f034ba1
Try tests with the new style that Jonathan suggested - see if they ar…
robintw Oct 8, 2021
392289f
Just one test, with prints
robintw Oct 8, 2021
7800dae
Add back in other test
robintw Oct 8, 2021
bd23c86
New approach to tests, plus nice interface, plus a load of debugging …
robintw Oct 9, 2021
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
16 changes: 8 additions & 8 deletions .github/workflows/test_pepys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ jobs:
shell: bash -l {0}
run: pip install pytest-github-actions-annotate-failures

- name: Run tests (non GUI)
shell: bash -l {0}
env:
PEPYS_SPATIALITE_PATH: /usr/lib/x86_64-linux-gnu/mod_spatialite.so
SQLALCHEMY_WARN_20: 1
run: |
coverage3 run -m pytest -v --color=yes --ignore=tests/gui_tests tests/ -Werror
# - name: Run tests (non GUI)
# shell: bash -l {0}
# env:
# PEPYS_SPATIALITE_PATH: /usr/lib/x86_64-linux-gnu/mod_spatialite.so
# SQLALCHEMY_WARN_20: 1
# run: |
# coverage3 run -m pytest -v --color=yes --ignore=tests/gui_tests tests/ -Werror

- name: Run tests (GUI)
shell: bash -l {0}
env:
PEPYS_SPATIALITE_PATH: /usr/lib/x86_64-linux-gnu/mod_spatialite.so
SQLALCHEMY_WARN_20: 1
run: |
coverage3 run -a -m pytest -v --color=yes -s tests/gui_tests -Werror
pytest tests/gui_tests/test_gui_interactively.py -s -vv

- name: Run black
shell: bash -l {0}
Expand Down
1 change: 1 addition & 0 deletions pepys_admin/maintenance/dialogs/progress_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def coroutine():
is_cancelled=self.is_cancelled,
),
)
get_app().progress_bar_finished.fire()
self.future.set_result(result)
except Exception as e:
try:
Expand Down
19 changes: 17 additions & 2 deletions pepys_admin/maintenance/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from prompt_toolkit.layout.menus import CompletionsMenu
from prompt_toolkit.lexers.pygments import PygmentsLexer
from prompt_toolkit.styles import Style
from prompt_toolkit.utils import Event
from prompt_toolkit.widgets.base import Border, Label
from pygments.lexers.sql import SqlLexer
from sqlalchemy.orm import joinedload, undefer
Expand Down Expand Up @@ -141,6 +142,8 @@ def __init__(self, data_store=None):
)

self.app.dropdown_opened = False
self.app.progress_bar_finished = Event(self.app)
self.app.preview_table_updated = Event(self.app)

def init_ui_components(self):
"""Initialise all of the UI components, controls, containers and widgets"""
Expand Down Expand Up @@ -381,6 +384,7 @@ def filter_column_data(self, column_data):
def run_query(self):
"""Runs the query as defined by the FilterWidget,
and displays the result in the preview table."""
logger.debug("Running query")
if self.current_table_object is None:
return

Expand Down Expand Up @@ -460,6 +464,11 @@ def run_query(self):
# the selected items label
self.preview_table.current_values = []
self.update_selected_items_label()
app.invalidate()

logger.debug("Firing preview updated")
logger.debug(f"{len(self.table_objects)=}")
self.app.preview_table_updated.fire()

def get_table_data(self):
return self.table_data
Expand Down Expand Up @@ -582,6 +591,7 @@ def on_filter_widget_change(self, value):
widget is sensible about this and only raises this event if there has actually been
a change in the output of the filters property. That means we can run a query
each time this is called, and the query shouldn't get run more often than is needed."""
logger.debug("on filter widget change")
# Convert the filter object to a SQL string to display in the Complete Query tab
if value != []:
filter_query = filter_widget_output_to_query(
Expand Down Expand Up @@ -742,7 +752,10 @@ async def coroutine():
ensure_future(coroutine())

def run_delete(self):
logger.debug("In run_delete")

def do_delete(table_object, ids, set_percentage=None, is_cancelled=None):
logger.debug("In do delete")
with self.data_store.session_scope():
change_id = self.data_store.add_to_changes(
USER, datetime.utcnow(), "Manual delete from Maintenance GUI"
Expand All @@ -753,6 +766,7 @@ def do_delete(table_object, ids, set_percentage=None, is_cancelled=None):
def do_find_dependent_objects(
table_object, selected_ids, set_percentage=None, is_cancelled=None
):
logger.debug("In do_find_dep_objs")
with self.data_store.session_scope():
dependent_objects = self.data_store.find_dependent_objects(
table_object,
Expand All @@ -764,6 +778,7 @@ def do_find_dependent_objects(
return dependent_objects

async def coroutine():
logger.debug("In coroutine")
entries = await self.get_all_selected_entries()

if len(entries) == 0:
Expand All @@ -789,14 +804,14 @@ async def coroutine():
selected_items_text = f"{len(entries)} items selected"

selected_ids = convert_objects_to_ids(entries, self.current_table_object)

logger.debug("Converted objects to IDs")
dialog = ProgressDialog(
"Finding dependent items (may take a while)",
partial(do_find_dependent_objects, self.current_table_object, selected_ids),
show_cancel=True,
)
dependent_objects = await self.show_dialog_as_float(dialog)

logger.debug("Just awaited find dep objs progress dialog")
if isinstance(dependent_objects, Exception):
await self.show_messagebox_async(
"Error",
Expand Down
4 changes: 4 additions & 0 deletions pepys_admin/maintenance/widgets/filter_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)

CONTEXTUAL_HELP_STRING = "# Second panel: Build filters (F3)"
from loguru import logger


class FilterWidget:
Expand Down Expand Up @@ -104,6 +105,8 @@ def set_contextual_help(self, widget, text):

def trigger_on_change(self, event=None):
"""Triggers the on_change_handler, if it is defined"""
logger.debug("trigger on change")
logger.debug(f"{self.filters=}")
if self.on_change_handler is not None:
if not list_deep_equals(self.filters, self.last_filters_output):
# Only call event there is a difference from last time we called
Expand Down Expand Up @@ -202,6 +205,7 @@ def filters(self):

for entry_or_boolean in entries_and_booleans:
strings = entry_or_boolean.get_string_values()
logger.debug(f"{strings=}")
if strings[0] == self.column_prompt:
# The column dropdown is still at the default value
continue
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ markers =
postgres: marks tests as requiring a local postgres executable (deselect with '-m "not postgres"')
automaton: marks tests as using the CLI automaton, which may take a while to run (deselect with '-m "not automaton"')
filterwarnings =
error
error
default_async_timeout = 120
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ isort
pytest-benchmark
pyte
freezegun==1.*
pexpect
pexpect
alt_pytest_asyncio
Loading