Repository navigation
Write FLOAT values without an exponent #2137
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
fermsp
wants to merge
1
commit into
PyCalendar:main
Choose a base branch
from
fermsp:fix-2136-float-exponent
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.
+74
−2
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed :class:~icalendar.prop.float.vFloat and :class:~icalendar.prop.geo.vGeo writing very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of :rfc:5545#section-3.3.7 does not allow an exponent. @fermsp | ||
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
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
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,50 @@ | ||
| """Regression tests for issue #2136: FLOAT values must not use an exponent.""" | ||
|
|
||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
| from icalendar import Event | ||
| from icalendar.prop import vFloat, vGeo | ||
|
|
||
| RFC_5545_FLOAT = re.compile(r"[+-]?\d+(\.\d+)?") | ||
| """The FLOAT grammar of RFC 5545, section 3.3.7.""" | ||
|
|
||
| VALUES = [0.00001, -0.00002, 1.5e-07, 1e16, -1e22, 5e-324, 1.7976931348623157e308] | ||
| """Floats that Python writes with an exponent.""" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", VALUES) | ||
| def test_vfloat_follows_the_float_grammar(value): | ||
| """vFloat writes no exponent.""" | ||
| assert RFC_5545_FLOAT.fullmatch(vFloat(value).to_ical().decode()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", VALUES) | ||
| def test_vfloat_round_trip(value): | ||
| """The value is the same after writing and parsing it.""" | ||
| assert vFloat.from_ical(vFloat(value).to_ical().decode()) == value | ||
|
|
||
|
|
||
| def test_vfloat_examples(): | ||
| """Small and large values are written with all their digits.""" | ||
| assert vFloat(0.00001).to_ical() == b"0.00001" | ||
| assert vFloat(1e16).to_ical() == b"10000000000000000" | ||
|
|
||
|
|
||
| def test_vgeo_writes_no_exponent(): | ||
| """Coordinates close to zero are written with all their digits.""" | ||
| assert vGeo((0.00001, -0.00002)).to_ical() == "0.00001;-0.00002" | ||
|
|
||
|
|
||
| def test_geo_of_an_event(): | ||
| """The GEO property of an event has no exponent.""" | ||
| event = Event() | ||
| event.add("GEO", (0.00001, -0.00002)) | ||
| assert b"GEO:0.00001;-0.00002" in event.to_ical() | ||
|
|
||
|
|
||
| def test_other_values_stay_the_same(): | ||
| """Values that had no exponent are written as before.""" | ||
| assert vFloat(3.1415).to_ical() == b"3.1415" | ||
| assert vGeo((37.386013, -122.082932)).to_ical() == "37.386013;-122.082932" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your quick response and contribution.
Let's polish up the reStructuredText in this news fragment so that it links. You can check how it renders in the pull request preview under the CI check for docs/readthedocs.org:icalendar under Reference > Change log.
Otherwise this looks good to me, and I'll pass it over to a maintainer for final review.