def test_generate_adjusted(self): block = """ x = 5 +6 if x > 7: for y in range(1,5): print "<td>%s</td>" % y """ stream = StringIO() printer = PythonPrinter(stream) printer.write_indented_block(block) printer.close() #print stream.getvalue() assert stream.getvalue() == \ """
def test_backslash_line(self): block = \ """ # comment if test: if (lala + hoho) + \\ (foobar + blat) == 5: print "hi" print "more indent" """ stream = StringIO() printer = PythonPrinter(stream) printer.write_indented_block(block) printer.close() assert stream.getvalue() == \ """
def test_multi_line(self): block = \ """ if test: print ''' this is a block of stuff. this is more stuff in the block. and more block. ''' do_more_stuff(g) """ stream = StringIO() printer = PythonPrinter(stream) printer.write_indented_block(block) printer.close() #print stream.getvalue() assert stream.getvalue() == \ """
def test_generate_combo(self): block = \ """ x = 5 +6 if x > 7: for y in range(1,5): print "<td>%s</td>" % y print "hi" print "there" foo(lala) """ stream = StringIO() printer = PythonPrinter(stream) printer.writeline("import lala") printer.writeline("for x in foo:") printer.writeline("print x") printer.write_indented_block(block) printer.writeline(None) printer.writeline("print y") printer.close() #print "->" + stream.getvalue().replace(' ', '#') + "<-" assert stream.getvalue() == \ """import lala