From 2bd850f297f2863d57505f34815d7822bc302dd8 Mon Sep 17 00:00:00 2001 From: DanielBradburn Date: Sun, 14 Aug 2016 20:44:23 +0200 Subject: [PATCH] added examples for known failures --- pytest/test_fstring.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pytest/test_fstring.py b/pytest/test_fstring.py index 2947337b..9fb38e3f 100644 --- a/pytest/test_fstring.py +++ b/pytest/test_fstring.py @@ -1,4 +1,5 @@ # test +import pytest import hypothesis from hypothesis import strategies as st # uncompyle6 @@ -84,8 +85,8 @@ def fstrings(draw): :return: A valid f-string. """ - prefix = draw(st.sampled_from('fF')) - raw = draw(st.sampled_from(list('rR') + [''])) + prefix = draw(st.sampled_from('f')) + raw = draw(st.sampled_from(list('r') + [''])) integer_strategy = st.integers(min_value=0, max_value=3) expression_count = draw(integer_strategy) content = [] @@ -93,10 +94,10 @@ def fstrings(draw): expression = draw(expressions()) #conversion = draw(st.sampled_from(('', '!s', '!r', '!a',))) #specifier = draw(st.sampled_from(format_specifiers(), st.just(''))) - content.append(f'{{{expression}}}') + content.append('{{{}}}'.format(expression)) content = ''.join(content) - return f"{prefix}{raw}'{content}'" + return "{}{}'{}'".format(prefix, raw, content) @hypothesis.given(format_specifiers()) @@ -109,10 +110,20 @@ def test_format_specifiers(format_specifier): raise +@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason="requires python3.6") @hypothesis.given(fstrings()) +@hypothesis.example("f'{abc}'") # BUG: strings with a single expression do not uncompyle correctly. +@hypothesis.example("fr'{abc}{xyz}'") # BUG: no support for raw f strings. +@hypothesis.example("f'{len(items)}{abc}'") # BUG: more complicated expressions than LOAD_NAME don't work def test_uncompyle_fstring(fstring): """Verify uncompyling fstring bytecode""" - hypothesis.assume('{' in fstring) # ignore fstring with no expressions - expr = f'{fstring}\n' + + # ignore fstring with no expressions an fsring with + # no expressions just gets compiled to a normal string. + hypothesis.assume('{' in fstring) + + expr = fstring + '\n' code = compile(expr, '', 'single') - assert deparse_code(PYTHON_VERSION, code, compile_mode='single').text == expr + deparsed = deparse_code(PYTHON_VERSION, code, compile_mode='single') + + assert deparsed.text == expr