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

2023 11 13 unit tests #309

Merged
merged 12 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ When implementing new features, think about how to break them down into atomic a
In most cases, you will want to use the [Gio.SimpleAction](https://lazka.github.io/pgi-docs/Gio-2.0/interfaces/SimpleAction.html) interface.
You will find usage examples within the code, in the [GTK Python developer handbook: Working with GIO Actions](https://bharatkalluri.gitbook.io/gnome-developer-handbook/writing-apps-using-python/working-with-gio-gactions).
Write actions as methods prefixed with `do_*`, e.g. `do_search` and attach them to the app itself or to the window they relate to.
Write at least one unit test for each action, e.g. `test_do_search` for the action `do_search`.
Write at least one unit test for each action, e.g. `test_do_search` for the action `do_search`.

Tests
-----

For testing, we mock the `dtool_lookup_api` in `conftest.py` to return dummy data on all API calls used within `dtool-lookup-gui`.
With for functionality packed in atomic actions, it is then straight forward to write unit tests.
We aim at writing two test cases for each action. One test case directly calls the action, e.g. `app.do_reset_config(...)` and tests against its operation on the provided dummy data without mocking anything other than the `dtool_lookup_api` calls.
The second test mocks many internal functions evoked by an action, activates the action via the intended GTK framework mechanism, e.g. `app.activate_action('reset-config')` and subsequently asserts the expected evocation of mocked methods.
3 changes: 2 additions & 1 deletion dtool_lookup_gui/models/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright 2022 Johannes Laurin Hörmann
# Copyright 2023 Ashwin Vazhappilly
# 2022 Johannes Laurin Hörmann
# 2021 Lars Pastewka
#
# ### MIT license
Expand Down
2 changes: 1 addition & 1 deletion dtool_lookup_gui/utils/copy_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2022 Johannes Laurin Hörmann
# Copyright 2022-2023 Johannes Laurin Hörmann
# 2021 Lars Pastewka
#
# ### MIT license
Expand Down
23 changes: 23 additions & 0 deletions dtool_lookup_gui/views/config_details.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
#
# Copyright 2023 Ashwin Vazhappilly
#
# ### MIT license
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
import asyncio
import logging
import os
Expand Down
23 changes: 23 additions & 0 deletions dtool_lookup_gui/views/error_linting_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
#
# Copyright 2023 Ashwin Vazhappilly
#
# ### MIT license
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
import logging
import os
import gi
Expand Down
20 changes: 18 additions & 2 deletions dtool_lookup_gui/views/main_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Copyright 2021-2023 Johannes Laurin Hörmann
# 2023 Ashwin Vazhappilly
# Copyright 2023 Ashwin Vazhappilly
# 2021-2023 Johannes Laurin Hörmann
# 2021 Lars Pastewka
#
# ### MIT license
Expand Down Expand Up @@ -299,6 +299,7 @@ def refresh(self):
async def _refresh():
# first, refresh base uri list and its selection
await self._refresh_base_uri_list_box()
self.select_and_load_first_uri()

_logger.debug(f"Done refreshing base URIs.")
# on_base_uri_selected(self, list_box, row) called by selection
Expand Down Expand Up @@ -593,6 +594,7 @@ def do_refresh_view(self, action, value):
"""Refresh view by reloading base uri list, """
self.refresh()


# signal handlers
@Gtk.Template.Callback()
def on_settings_clicked(self, widget):
Expand Down Expand Up @@ -984,6 +986,20 @@ def enable_pagination_buttons(self):
self.page_advancer_button.set_sensitive(True)
self.next_page_advancer_button.set_sensitive(True)

def select_and_load_first_uri(self):
"""
This function is used exclusively for testing purposes. It automatically reloads the data
and selects the first URI. This function is designed to operate only when there is exactly
one URI in the list box, ensuring that tests can be automated effectively.
"""
if len(self.base_uri_list_box.get_children()) == 1:
first_row = self.base_uri_list_box.get_children()[0]
self.base_uri_list_box.select_row(first_row)
self.on_base_uri_selected(self.base_uri_list_box, first_row)

# TODO: this should be an action do_copy
# if it is possible to hand to strings, e.g. source and destination to an action, then this action should
# go to the main app.
# @Gtk.Template.Callback(), not in .ui
def on_copy_clicked(self, widget):
async def _copy():
Expand Down
2 changes: 1 addition & 1 deletion maintenance/update_license_headers.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/sh
# Updates all Python files with license taken from README.md and copyright information obtained from the git log.

for fn in setup.py `find dtool_lookup_gui -name "*.py"`; do
for fn in setup.py $(find test -name "*.py") $(find dtool_lookup_gui -name "*.py"); do
echo $fn
python3 maintenance/copyright.py $fn | cat - LICENSE-MIT.md | python3 maintenance/replace_header.py $fn
done
Loading
Loading