diff --git a/tests/test_tokenize.py b/tests/test_tokenize.py index e6db9cd..9ce7cac 100644 --- a/tests/test_tokenize.py +++ b/tests/test_tokenize.py @@ -76,7 +76,7 @@ def draw_symbol_nonwhitespace(draw): chars = characters(blacklist_characters=whitespace) value = draw(text(alphabet=chars, min_size=1)) - location = tokenize.SymbolLocation(1, 1, "") + location = draw(draw_symbol_location()) return tokenize.Symbol(value, location) @@ -84,23 +84,33 @@ @composite def draw_symbol_whitespace(draw): value = draw(sampled_from(whitespace)) - location = tokenize.SymbolLocation(1, 1, "") + location = draw(draw_symbol_location()) return tokenize.Symbol(value, location) +# Draws a symbol with a set location +@composite +def draw_symbol_with_location(draw, strategy, location): + symbol = draw(strategy()) + return tokenize.Symbol(symbol.value, location) + + # Generates an alternating sequence of symbols @composite def draw_symbols_list(draw): output = [] elements = draw(lists(just(True))) drawing_whitespace = draw(booleans()) + location = tokenize.SymbolLocation(1, 1, "") for _ in elements: if drawing_whitespace: - strategy = draw_symbol_whitespace() - output += draw(lists(strategy, min_size=1)) + strategy = draw_symbol_whitespace + locationed = draw_symbol_with_location(strategy, location) + output += draw(lists(locationed, min_size=1)) else: - strategy = draw_symbol_nonwhitespace() - output.append(draw(strategy)) + strategy = draw_symbol_nonwhitespace + locationed = draw_symbol_with_location(strategy, location) + output.append(draw(locationed)) drawing_whitespace = not drawing_whitespace return output