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

Another zoneinfo bug for the trophy case #11

Merged
merged 2 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ Bugs found via this specific project:
`lib2to3.pgen.tokenize`.
- [PEP-615 (zoneinfo)](https://github.com/pganssle/zoneinfo/pull/32/commits/dc389beaaeaa702361fd186d8581da20dda807bb)
`fold` detection failed for early transitions when the number of elapsed
seconds is too large to fit in a C integer.
seconds is too large to fit in a C integer; and
[a `fold` inconsistency](https://github.com/pganssle/zoneinfo/pull/41)
where first offset handling was broken in the C extension.


## Further reading
Expand Down
25 changes: 18 additions & 7 deletions tests/test_re_by_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from contextlib import contextmanager
from functools import partial

from hypothesis import given, strategies as st
from hypothesis import given, reject, strategies as st
from hypothesis.errors import InvalidArgument

IS_PYPY = hasattr(sys, "pypy_version_info")

Expand Down Expand Up @@ -154,13 +155,23 @@ def non_matching_string(self, draw, state):
if not any(isinstance(x, tuple) for x in self.elements):
# easy case, only chars
return draw(st.characters(blacklist_characters=self.elements))

# Now, we *could* iterate through to get the set of all allowed characters,
# but that would be pretty slow. Instead, we just get the highest and lowest
# allowed codepoints and stay outside that interval, blacklisting individual
# characters. If we allow both chr(0) and chr(maxunicode), just give up.
chars = "".join(x for x in self.elements if not isinstance(x, tuple))
range_stops = [ord(x[1]) for x in self.elements if isinstance(x, tuple)]
max_stop = max(range_stops)
res = draw(
st.characters(min_codepoint=max_stop + 1, blacklist_characters=chars)
)
return res
low = min(ord(x[0]) for x in self.elements if isinstance(x, tuple))
high = max(ord(x[1]) for x in self.elements if isinstance(x, tuple))
strat = st.nothing()
if low > 0:
strat |= st.characters(max_codepoint=low - 1, blacklist_characters=chars)
if high < sys.maxunicode:
strat |= st.characters(min_codepoint=high + 1, blacklist_characters=chars)
try:
return draw(strat)
except InvalidArgument:
reject()

def build_re(self):
res = []
Expand Down