Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
result = output(root)
assert result == """\
bar = a({x0, y0}
* {x1,{x2, y2} / {x3,{x4, y4} / {x5, y5}}})"""
output = printer.IndentedStream()
output.test_child_z_is_expression = False
output.test_child_z_list_sep = '//'
result = output(root)
assert result == """\
bar = a({x0, y0}
* {x1, {x2, y2}
// {x3, {x4, y4}
// {x5, y5}}})"""
finally:
printer.NODE_PRINTERS.pop('TestRoot', None)
printer.NODE_PRINTERS.pop('TestChild', None)
printer.NODE_PRINTERS.pop('TestNiece', None)
assert result == """\
bar = a({x0, y0}
* {x1,{x2, y2} / {x3,{x4, y4} / {x5, y5}}})"""
output = printer.IndentedStream()
output.test_child_z_is_expression = False
output.test_child_z_list_sep = '//'
result = output(root)
assert result == """\
bar = a({x0, y0}
* {x1, {x2, y2}
// {x3, {x4, y4}
// {x5, y5}}})"""
finally:
printer.NODE_PRINTERS.pop('TestRoot', None)
printer.NODE_PRINTERS.pop('TestChild', None)
printer.NODE_PRINTERS.pop('TestNiece', None)
else:
output.print_list(node.z, '/', standalone_items=False)
output.write('}')
output = printer.RawStream()
output.test_child_z_is_expression = True
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} + {x3,{x4, y4} + {x5, y5}}})'
output = printer.RawStream()
output.test_child_z_is_expression = False
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} / {x3,{x4, y4} / {x5, y5}}})'
finally:
printer.NODE_PRINTERS.pop('TestRoot', None)
printer.NODE_PRINTERS.pop('TestChild', None)
printer.NODE_PRINTERS.pop('TestNiece', None)
@printer.node_printer('RawStmt')
def raw_stmt(node, output):
output.write('Yeah')
output = printer.IndentedStream()
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah;\n\nYeah'
output = printer.IndentedStream(separate_statements=False)
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah;\nYeah'
finally:
if raw_stmt_printer is not None:
printer.NODE_PRINTERS['RawStmt'] = raw_stmt_printer
else:
printer.NODE_PRINTERS.pop('RawStmt', None)
def test_raw_stream_with_sql():
raw_stmt_printer = printer.NODE_PRINTERS.pop('RawStmt', None)
try:
@printer.node_printer('RawStmt')
def raw_stmt(node, output):
output.write('Yeah')
output = printer.RawStream()
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah; Yeah'
finally:
if raw_stmt_printer is not None:
printer.NODE_PRINTERS['RawStmt'] = raw_stmt_printer
else:
printer.NODE_PRINTERS.pop('RawStmt', None)
def test_separate_statements():
"""Separate statements by ``separate_statements`` (int) newlines."""
raw_stmt_printer = printer.NODE_PRINTERS.pop('RawStmt', None)
try:
@printer.node_printer('RawStmt')
def raw_stmt(node, output):
output.write('Yeah')
output = printer.IndentedStream(separate_statements=2)
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah;\n\n\nYeah'
finally:
if raw_stmt_printer is not None:
printer.NODE_PRINTERS['RawStmt'] = raw_stmt_printer
else:
printer.NODE_PRINTERS.pop('RawStmt', None)
output.print_list(node.z, '/', standalone_items=False)
output.write('}')
output = printer.RawStream()
output.test_child_z_is_expression = True
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} + {x3,{x4, y4} + {x5, y5}}})'
output = printer.RawStream()
output.test_child_z_is_expression = False
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} / {x3,{x4, y4} / {x5, y5}}})'
finally:
printer.NODE_PRINTERS.pop('TestRoot', None)
printer.NODE_PRINTERS.pop('TestChild', None)
printer.NODE_PRINTERS.pop('TestNiece', None)
def test_indented_stream_with_sql():
raw_stmt_printer = printer.NODE_PRINTERS.pop('RawStmt', None)
try:
@printer.node_printer('RawStmt')
def raw_stmt(node, output):
output.write('Yeah')
output = printer.IndentedStream()
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah;\n\nYeah'
output = printer.IndentedStream(separate_statements=False)
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah;\nYeah'
finally:
if raw_stmt_printer is not None:
printer.NODE_PRINTERS['RawStmt'] = raw_stmt_printer
else:
output.print_list(node.z, '+')
else:
output.print_list(node.z, '/', standalone_items=False)
output.write('}')
output = printer.RawStream()
output.test_child_z_is_expression = True
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} + {x3,{x4, y4} + {x5, y5}}})'
output = printer.RawStream()
output.test_child_z_is_expression = False
result = output(root)
assert result == 'bar = a({x0, y0} * {x1,{x2, y2} / {x3,{x4, y4} / {x5, y5}}})'
finally:
printer.NODE_PRINTERS.pop('TestRoot', None)
printer.NODE_PRINTERS.pop('TestChild', None)
printer.NODE_PRINTERS.pop('TestNiece', None)
def test_raw_stream_with_sql():
raw_stmt_printer = printer.NODE_PRINTERS.pop('RawStmt', None)
try:
@printer.node_printer('RawStmt')
def raw_stmt(node, output):
output.write('Yeah')
output = printer.RawStream()
result = output('SELECT 1; SELECT 2')
assert result == 'Yeah; Yeah'
finally:
if raw_stmt_printer is not None:
printer.NODE_PRINTERS['RawStmt'] = raw_stmt_printer
else:
printer.NODE_PRINTERS.pop('RawStmt', None)