this post was submitted on 09 Feb 2025
30 points (100.0% liked)

Python

6638 readers
70 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

I'm working on a project that needs lots of toolbars on screen at once, even though not all of them will be used at the same time. So, I'm modelling this 'foldable' dock widget after what I remember Photoshop panels used to be like.

It's a work in progress, but would like to hear constructive suggestions.

https://blocks.programming.dev/0101100101/42c5d67f86c049baa3500aa38e439f8a

you are viewing a single comment's thread
view the rest of the comments
[–] logging_strict@programming.dev 1 points 2 days ago (1 children)

ternary expressions

Recommend against the ternary expression. coverage might not detect the two code blocks. Would also not be able to apply # pragma: no cover comment to a code block that isn't important enough to justify testing it. Often use do nothing code blocks.

self.float_button.setIcon(self.icon_dock if is_floating else self.icon_float) lets say while testing something goes wrong and trying to debug what happened.

Will not see the value that gets past into self.float_button.setIcon

I like your idea of having the param be keyword only. Makes it more readable.

[–] FizzyOrange@programming.dev 1 points 2 days ago (1 children)

If you branch coverage tool can't handle branches on the same line I would suggest you use a different one! Does it handle if foo or bar?

Will not see the value that gets past into self.float_button.setIcon

Uhm, yes you will? Just step into the function.

[–] logging_strict@programming.dev 1 points 2 days ago (1 children)

self.float_button.setIcon is a Python wrapper around a C++ library. Might not be possible to, or want to, step into the function.

if foo or bar is part of a if-else condition. The else portion needs # pragma: no cover or coverage may complain.

[–] FizzyOrange@programming.dev 2 points 9 hours ago (2 children)

Well... the else condition (bar) needs to be covered. I haven't used branch coverage tools in Python but in any sane language you cover the actual semantics, not the lines. It shouldn't make any difference if you write your code on one line, or with ternary expressions, or whatever.

What matters is what the package coverage can do and what limitations or nuances it has. Have to work with what we have. We are lucky to have coverage. Especially within a subprocess and multiprocessing workers

We are dealing with Python and coverage, not some theoretical situation or circumstances.

Was assuming measuring branch coverage. In which case, my advice is coming from experience