-
Notifications
You must be signed in to change notification settings - Fork 720
Fix QRCode.clear() to properly reset the QRCode object. #411
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
Open
bartTC
wants to merge
6
commits into
main
Choose a base branch
from
qrcode-clear-reset-object
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0ec709
Fix QRCode.clear() to properly reset the QRCode object. Fixes #392
bartTC dc74a58
Remove Claude config
bartTC af63a74
Shorten up test
bartTC d5d8f0c
Move `clear()` call before QRCode attribute initialization
bartTC 90dfd34
Test is a PIL only test
bartTC 915af02
Test is a PIL only test
bartTC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
import qrcode | ||
from qrcode.constants import PIL_AVAILABLE | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
@pytest.mark.skipif(not PIL_AVAILABLE, reason="PIL is not installed") | ||
def test_qrcode_clear_resets_size(tmp_path: Path): | ||
""" | ||
Test that QRCode.clear() properly resets the QRCode object. | ||
|
||
Regression test for: | ||
|
||
QRCode class not resizing down between runs | ||
https://github.com/lincolnloop/python-qrcode/issues/392 | ||
""" | ||
test1_path = tmp_path / "test1.png" | ||
test2_path = tmp_path / "test2.png" | ||
test3_path = tmp_path / "test3.png" | ||
|
||
# Create a QR code instance | ||
qr = qrcode.QRCode(version=None) | ||
|
||
# Generate first QR code | ||
qr.add_data("https://example.com/") | ||
qr.make(fit=True) | ||
img1 = qr.make_image() | ||
img1.save(test1_path) | ||
|
||
# Clear and generate second QR code with different data | ||
qr.clear() | ||
qr.add_data("https://example.net/some/other/path") | ||
qr.make(fit=True) | ||
img2 = qr.make_image() | ||
img2.save(test2_path) | ||
|
||
# Clear and generate third QR code with same data as first | ||
qr.clear() | ||
qr.add_data("https://example.com/") | ||
qr.make(fit=True) | ||
img3 = qr.make_image() | ||
img3.save(test3_path) | ||
|
||
# Check that the first and third QR codes are identical. | ||
with test1_path.open("rb") as file1, test3_path.open("rb") as file3: | ||
assert file1.read() == file3.read(), ( | ||
"First and third QR codes should be identical after clearing" | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.