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

Make stub QgisInterface and MockMessageBar inherit real interfaces #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Joonalai
Copy link
Contributor

This PR:

  • Makes stub implementations of QgisInterface and QgsMessageBar to inherit their real parents
  • Improves tests

Fixes #24, fixes #26.

@Joonalai Joonalai force-pushed the 24-qgis-interface-py-implementation branch from 82b4875 to f0a76ac Compare December 18, 2023 18:35
@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2023

Codecov Report

Attention: 577 lines in your changes are missing coverage. Please review.

Comparison is base (af7f77a) 57.77% compared to head (64ad100) 29.85%.

Files Patch % Lines
src/pytest_qgis/qgis_interface.py 3.79% 558 Missing ⚠️
src/pytest_qgis/mock_qgis_classes.py 58.13% 18 Missing ⚠️
src/pytest_qgis/pytest_qgis.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #54       +/-   ##
===========================================
- Coverage   57.77%   29.85%   -27.92%     
===========================================
  Files           7        7               
  Lines         495     1065      +570     
===========================================
+ Hits          286      318       +32     
- Misses        209      747      +538     
Flag Coverage Δ
pytest 29.85% <7.53%> (-27.92%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Joonalai Joonalai force-pushed the 24-qgis-interface-py-implementation branch from f0a76ac to 64ad100 Compare December 18, 2023 18:42
@Joonalai
Copy link
Contributor Author

Joonalai commented Feb 9, 2024

@LKajan, could you review this?

@alukach
Copy link

alukach commented Feb 14, 2025

@Joonalai this looks great from an outsider's perspective. Any tips on what is needed to get this merged in?

@Joonalai
Copy link
Contributor Author

@alukach I'm afraid that this PR is not going to be merged. Maybe theses issues should be fixed in some other way. I am no longer in an active role of developing this project but maybe @LKajan could give some more details on how to get these issues fixed.

@LKajan
Copy link
Contributor

LKajan commented Feb 17, 2025

@alukach, @Joonalai,
Sorry for not responding to this PR earlier.

I think we should avoid bringing typing "stubs" of QGIS classes into this project. This would create an endless need to update the typing annotations for every new QGIS version. The QGIS package is already typed; users just need to add a py.typed file to the qgis package directory to use them.

However, there are parts of this PR that could be considered for merging. I'll take another look now that I have some more time.

@alukach
Copy link

alukach commented Feb 17, 2025

The QGIS package is already typed; users just need to add a py.typed file to the qgis package directory to use them.

@LKajan The typing itself is a bit of a secondary feature, correct? The key value add of this PR is supporting realistic interactions with the qgis tooling generated by this plugin, correct? For example, I'm currently seeing errors when attempting to build out the menus in my plugin with the iface generated by the plugin:

        # Build plugin menu
>       plugin_menu = cast(QtWidgets.QMenu, self.iface.pluginMenu())
E       AttributeError: 'QgisInterface' object has no attribute 'pluginMenu'

How can I help you in terms of resolving issues like these with the plugin?

@LKajan
Copy link
Contributor

LKajan commented Feb 18, 2025

@alukach, you are right that this would kind of solve the issue you're having. Still I wonder if this should be addressed probably by using mocking (using Mock from unittest.mock) instead of faking.

For your case, you could extend the faked QgisInterface as following:

@pytest.fixture(scope="session")
def qgis_iface(qgis_iface: QgisInterface):
    qgis_iface.pluginMenu=Mock()
    return qgis_iface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants