Skip to content

Conversation

phw
Copy link
Member

@phw phw commented Aug 28, 2025

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

Problem

The tests in test_coverart_details_option would randomly fail if run after localization tests due to differences in number formatting

Solution

  1. Set C locale explicitly in test_coverart_details_option tests. Tests should stand on their own and set this up. We always do this for tests being based on PicardTestCase, but this isn't the case here.
  2. In any case also reset the locale in test_i18n after the tests. Those tests change the locale. It is good practice to clean up after yourself ;)

phw added 2 commits August 28, 2025 22:13
This ensures consistent number formatting in the output strings
@phw
Copy link
Member Author

phw commented Aug 28, 2025

For reference, this was the failing test:

_______ test_coverartbox_child_filtering[True-False-True-True-expected2] _______
[gw6] linux -- Python 3.12.3 /home/phw/devel/musicbrainz/picard/.venv/bin/python3

box = <test.test_coverart_details_option.CoverArtBoxLite object at 0x7c701d2ca540>
_restore_cover_details_options = None, type_on = True, size_on = False
dims_on = True, mime_on = True, expected = ['Front', '500 x 500', 'image/jpeg']

    @pytest.mark.parametrize(
        "type_on,size_on,dims_on,mime_on,expected",
        [
            (True, True, True, True, ["Front", "55.3 kB (54 KiB)", "500 x 500", "image/jpeg"]),
            (False, True, True, True, ["55.3 kB (54 KiB)", "500 x 500", "image/jpeg"]),
            (True, False, True, True, ["Front", "500 x 500", "image/jpeg"]),
            (True, True, False, True, ["Front", "55.3 kB (54 KiB)", "image/jpeg"]),
            (True, True, True, False, ["Front", "55.3 kB (54 KiB)", "500 x 500"]),
            (False, False, False, False, []),
        ],
    )
    def test_coverartbox_child_filtering(
        box: CoverArtBoxLite,
        _restore_cover_details_options: None,
        type_on: bool,
        size_on: bool,
        dims_on: bool,
        mime_on: bool,
        expected: list[str],
    ) -> None:
        # Configure options
        _set_details_config(parent=True, type_on=type_on, size_on=size_on, dims_on=dims_on, mime_on=mime_on)
    
        # Provide one image on the new/current thumbnail
        img = DummyImage("Front", 55300, 500, 500, "image/jpeg")
        box.cover_art.related_images = [img]
        box.orig_cover_art.related_images = []
    
        # Update and assert
        box.update_display(force=True)
        assert box.cover_art_info_label.text() == lines_to_text(expected)
        # Tooltip remains full
        full = ["Front", "55.3 kB (54 KiB)", "500 x 500", "image/jpeg"]
>       assert box.cover_art.toolTip() == "<br/>".join(full)
E       AssertionError: assert 'Front<br/>55...r/>image/jpeg' == 'Front<br/>55...r/>image/jpeg'
E         
E         Skipping 33 identical trailing characters in diff, use -v to show
E         - Front<br/>55.3 kB (54 
E         ?             ^
E         + Front<br/>55,3 kB (54 
E         ?             ^

test/test_coverart_details_option.py:337: AssertionError
=========================== short test summary info ============================
FAILED test/test_coverart_details_option.py::test_coverartbox_child_filtering[True-False-True-True-expected2] - AssertionError: assert 'Front<br/>55...r/>image/jpeg' == 'Front<br/>55...r/...

@phw phw force-pushed the fix-tests-locale-errors branch from 0379389 to db28245 Compare August 28, 2025 20:54
Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@phw phw merged commit 62854ad into metabrainz:master Aug 28, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants