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

cog.py: Fix test_cog_creation_of_overviews_with_compression. #11705

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

schwehr
Copy link
Member

@schwehr schwehr commented Jan 23, 2025

a -> b

Just a minor typo such that the second JPEG_QUALITY check was a repeat of the first.

@schwehr schwehr requested a review from rouault January 23, 2025 00:09
@rouault
Copy link
Member

rouault commented Jan 23, 2025

would you mind replacing the whole block

    ds_overview_a = gdal.Open("GTIFF_DIR:2:" + filename)
    assert ds_overview_a.GetMetadata("IMAGE_STRUCTURE")["COMPRESSION"] == "JPEG"
    assert ds_overview_a.GetMetadata("IMAGE_STRUCTURE")["JPEG_QUALITY"] == "50"

    ds_overview_b = gdal.Open("GTIFF_DIR:3:" + filename)
    assert ds_overview_b.GetMetadata("IMAGE_STRUCTURE")["COMPRESSION"] == "JPEG"
    assert ds_overview_b.GetMetadata("IMAGE_STRUCTURE")["JPEG_QUALITY"] == "50"

    ds_overview_a = None
    ds_overview_b = None

with something like (pending correct indentation)

    with gdal.Open("GTIFF_DIR:2:" + filename) as ds:
        assert ds.GetMetadata("IMAGE_STRUCTURE")["COMPRESSION"] == "JPEG"
        assert ds.GetMetadata("IMAGE_STRUCTURE")["JPEG_QUALITY"] == "50"

    with gdal.Open("GTIFF_DIR:3:" + filename) as ds:
        assert ds.GetMetadata("IMAGE_STRUCTURE")["COMPRESSION"] == "JPEG"
        assert ds.GetMetadata("IMAGE_STRUCTURE")["JPEG_QUALITY"] == "50"

@schwehr
Copy link
Member Author

schwehr commented Jan 23, 2025

Sure thing. That is definitely safer/better style. I will get it in a few hours or early tomorrow.

- The second overview check of JPEG_QUALITY: a -> b.
- Use with to make the code more obvious / simplify cleanup.
@schwehr
Copy link
Member Author

schwehr commented Jan 23, 2025

@rouault , Ran pre-commit and force pushed your suggestion.

I need to use the with pattern like this more often in my code. Much clearer and less bug prone in many cases.

@rouault rouault merged commit 4770117 into OSGeo:master Jan 23, 2025
37 of 38 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