Comments (7)
Test itself: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_checker/test_hypothesis.py#L39
from hypothesmith.
Huh. Can you reproduce this with the compile('globalA\\ \n#\n', '<string>', 'single')
call? In my Python 3.9 env this just raises a SyntaxError: unexpected character after line continuation character
, which is much less interesting.
If you can reproduce, we should report this upstream to CPython core.
from hypothesmith.
I am trying to reproduce this on 3.9.1
(originally happened on 3.9.8
):
> ???
E hypothesis.errors.DidNotReproduce: The shape of the test data has changed in some way from where this blob was defined. Are you sure you're running the same test?
tests/test_checker/test_hypothesis.py:40: DidNotReproduce
Right now 3.9.8
is not available in pyenv
: pyenv/pyenv#2152
from hypothesmith.
@Zac-HD I just got another one!
This one is different, it also has warnings:
=================================== FAILURES ===================================
______________________________ test_no_exceptions ______________________________
self = <hypothesmith.syntactic.GrammarStrategy object at 0x7ffa6e39ab80>
data = ConjectureData(VALID, 26 bytes, frozen)
symbol = NonTerminal('simple_stmt')
draw_state = DrawState(result=['global', 'A', '\\ \n', ';', '\n'])
def draw_symbol(self, data, symbol, draw_state): # type: ignore
count = len(draw_state.result)
super().draw_symbol(data, symbol, draw_state)
if symbol.name in COMPILE_MODES:
try:
> compile(
source="".join(draw_state.result[count:]),
filename="<string>",
mode=COMPILE_MODES[symbol.name],
)
E SystemError: Negative size passed to PyUnicode_New
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:110: SystemError
The above exception was the direct cause of the following exception:
default_options = options(min_name_length=2, max_name_length=45, i_control_code=True, i_dont_control_code=True, max_noqa_comments=10, ne...gnitive_average=8, max_call_level=3, max_annotation_complexity=3, max_import_from_members=8, max_tuple_unpack_length=4)
parse_ast_tree = <function parse_ast_tree.<locals>.factory at 0x7ff8dfa10c10>
parse_tokens = <function parse_tokens.<locals>.factory at 0x7ff8df980160>
> ???
tests/test_checker/test_hypothesis.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:89: in do_draw
result = super().do_draw(data)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:153: in do_draw
self.draw_symbol(data, start, state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
self.draw_symbol(data, e, draw_state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
self.draw_symbol(data, e, draw_state)
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:107: in draw_symbol
super().draw_symbol(data, symbol, draw_state)
.venv/lib/python3.9/site-packages/hypothesis/extra/lark.py:181: in draw_symbol
self.draw_symbol(data, e, draw_state)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <hypothesmith.syntactic.GrammarStrategy object at 0x7ffa6e39ab80>
data = ConjectureData(VALID, 26 bytes, frozen)
symbol = NonTerminal('simple_stmt')
draw_state = DrawState(result=['global', 'A', '\\ \n', ';', '\n'])
def draw_symbol(self, data, symbol, draw_state): # type: ignore
count = len(draw_state.result)
super().draw_symbol(data, symbol, draw_state)
if symbol.name in COMPILE_MODES:
try:
compile(
source="".join(draw_state.result[count:]),
filename="<string>",
mode=COMPILE_MODES[symbol.name],
)
except SyntaxError:
# Python's grammar doesn't actually fully describe the behaviour of the
# CPython parser and AST-post-processor, so we just filter out errors.
assume(False)
except Exception as err: # pragma: no cover
# Attempting to compile almost-valid strings has triggered a wide range
# of bizzare errors in CPython, especially with the new PEG parser,
# and so we maintain this extra clause to ensure that we get a decent
# error message out of it.
if isinstance(err, SystemError) and sys.version_info[:3] == (3, 9, 0):
# We've triggered https://bugs.python.org/issue42218 - it's been
# fixed upstream, so we'll treat it as if it were a SyntaxError.
assume(False)
source_code = ascii("".join(draw_state.result[count:]))
> raise type(err)(
f"compile({source_code}, '<string>', "
f"{COMPILE_MODES[symbol.name]!r}) "
f"raised {type(err).__name__}: {str(err)}"
) from err
E SystemError: compile('globalA\\ \n;\n', '<string>', 'single') raised SystemError: Negative size passed to PyUnicode_New
.venv/lib/python3.9/site-packages/hypothesmith/syntactic.py:129: SystemError
---------------------------------- Hypothesis ----------------------------------
Highest target scores:
19 (label='(hypothesmith) number of unique ast node types')
46 (label='(hypothesmith) instructions in bytecode')
74 (label='(hypothesmith) total number of ast nodes')
You can reproduce this example by temporarily adding @reproduce_failure('6.24.2', b'AXicY2RkYGJlYGQAAWZGCA0hAQFGABE=') as a decorator on your test case
=============================== warnings summary ===============================
tests/test_checker/test_hypothesis.py: 933 warnings
<string>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
tests/test_checker/test_hypothesis.py: 916 warnings
<string>:3: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
-- Docs: https://docs.pytest.org/en/stable/warnings.html
----------- coverage: platform linux, python 3.9.8-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
---------------------------------------------------
---------------------------------------------------
TOTAL 6290 0 2813 0 100%
141 files skipped due to complete coverage.
Coverage HTML written to dir htmlcov
Coverage XML written to file coverage.xml
Required test coverage of 100% reached. Total coverage: 100.00%
============================= SnapshotTest summary =============================
11 snapshots passed.
=========================== short test summary info ============================
FAILED tests/test_checker/test_hypothesis.py::test_no_exceptions - SystemErro...
==== 1 failed, 32026 passed, 12 skipped, 1849 warnings in 330.95s (0:05:30) ====
make: *** [Makefile:14: unit] Error 1
from hypothesmith.
The pyenv PR you linked to has been merged four days ago, so I think it should work?
This does seem like a real bug if we can trigger it with multiple inputs like this; I'd suggest one more attempt to reproduce and then reporting upstream with links to https://bugs.python.org/issue42218 https://bugs.python.org/issue40661 and https://bugs.python.org/issue42109
from hypothesmith.
Ah, https://bugs.python.org/issue45738 has already been opened.
from hypothesmith.
Fixed in 67fe545, version 0.2.0 released 🎉
from hypothesmith.
Related Issues (20)
- FailedHealthCheck when generating eval_input
- Python3.9 related bug. HOT 2
- New failure on Python3.9 HOT 11
- No git version tags HOT 4
- Generated programs are missing spaces HOT 17
- Generate names which collide when NFKC-normalized
- Register a strategy for `libcst.MatchSingleton` HOT 2
- libcst version requirement should be updated HOT 1
- Grammar definition file handling is broken HOT 1
- hypothesmith on PyPI breaks with FileNotFoundError when importing from_grammar or from_node HOT 3
- Generate programs matching a syntatic pattern... using `libcst` matchers
- can pysource-codegen be used to generate code with hypothesmith HOT 3
- hypothesmith-inspired compiler fuzzer used to validate PEP 709 implementation HOT 1
- How to get hypothesmith to generate a FunctionDef with arguments? HOT 2
- Broken with `hypothesis==6.84.0` HOT 2
- Use `from_regex(..., alphabet=st.characters(min_codepoint=1, codec="utf-8"))` to reduce rejection sampling HOT 1
- 0.3.1: no git tag and no commits HOT 3
- Cannot import on 3.13, importlib.resources.read_text is removed HOT 1
- 0.3.3: pytest fails in `tests/test_syntactic.py::test_black_autoformatter_from_grammar` unit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hypothesmith.