Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_initial_doesnt_matter(quote_type):
code = random.choice(["'abra'", '"bobro"', "'''abra'''", '"""bobro"""'])
assert get_quote_type(set_quote_type(code, quote_type)) == quote_type
def test_cycle(code):
assert set_quote_type(code, get_quote_type(code)) == code
def test_single():
code = '"alpha123"'
expected = "'alpha123'"
assert set_quote_type(code, QuoteTypes.single) == expected
def test_single_from_triple():
code = '"""alpha123"""'
expected = "'alpha123'"
assert set_quote_type(code, QuoteTypes.single) == expected
converted, changed, str_in_str = fstringify_node(copy.deepcopy(tree))
except (SyntaxError, FlyntException, Exception) as e:
if state.verbose:
if isinstance(e, ConversionRefused):
print(f"Not converting code '{code}': {e}")
print(e)
else:
print(f"Exception {e} during conversion of code '{code}'")
traceback.print_exc()
state.invalid_conversions += 1
return code, False
else:
if changed:
new_code = astor.to_source(converted)
new_code = new_code.strip()
new_code = set_quote_type(
new_code, quote_type if not str_in_str else QuoteTypes.double
)
new_code = new_code.replace("\n", "\\n")
new_code = new_code.replace("\t", "\\t")
try:
ast.parse(new_code)
except Exception as e:
if state.verbose:
print(
f"Failed to parse transformed code '{new_code}' given original '{code}'"
)
print(e)
traceback.print_exc()
state.invalid_conversions += 1
return code, False
else: