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

Auto-realize encode/decode arguments for unsupported codecs #271

Closed
pschanely opened this issue Jul 13, 2024 · 1 comment
Closed

Auto-realize encode/decode arguments for unsupported codecs #271

pschanely opened this issue Jul 13, 2024 · 1 comment

Comments

@pschanely
Copy link
Owner

Found via hypothesis:

Looks like string-encoding wants to receive exactly a str, meaning it crashes under crosshair:

from encodings.aliases import aliases
from hypothesis import Verbosity, given, settings, strategies as st

def _enc(cdc):
    try:
        "".encode(cdc)
        return True
    except Exception:
        return False

lots_of_encodings = sorted(x for x in set(aliases).union(aliases.values()) if _enc(x))
assert len(lots_of_encodings) > 100  # sanity-check

@settings(backend="crosshair", verbosity=Verbosity.verbose)
@given(st.text(), st.sampled_from(lots_of_encodings))
def test_b(string, codec_name):
    string.encode(codec_name)

representative traceback:

Trying example: test_b(
    string='',
)
Traceback (most recent call last):
  File ".../demo.py", line 14, in test_b
    string.encode("037")
  File ".venv/lib/python3.10/site-packages/crosshair/libimpl/builtinslib.py", line 2691, in encode
    return codecs.encode(self, encoding, errors)
  File ".venv/lib/python3.10/site-packages/crosshair/libimpl/codecslib.py", line 19, in _encode
    (out, _len_consumed) = _getencoder(encoding)(obj, errors)
  File ".../3.10.11/lib/python3.10/encodings/cp037.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
TypeError: charmap_encode() argument 1 must be str, not LazyIntSymbolicStr

...
hypothesis.errors.Flaky: Inconsistent results from replaying a failing test case!
  last: INTERESTING from TypeError at .../3.10.11/lib/python3.10/encodings/cp037.py:12
  this: VALID

Originally posted by @Zac-HD in HypothesisWorks/hypothesis#4034 (comment)

@pschanely
Copy link
Owner Author

This was fixed in 0.0.62, but I neglected to updated this issue (or add it to the changelog). Doing so now!

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

No branches or pull requests

1 participant