def testIndentBlock(self): writer = util.Writer() writer.write('foo') with writer.indent_block(n=2): writer.write('bar') writer.write('baz') self.assertEqual(writer.getvalue(), 'foo\n\t\tbar\nbaz\n')
def testWriteBlock(self): writer = util.Writer() mod_block = block.ModuleBlock(None, '__main__', '<test>', '', imputil.FutureFeatures()) writer.write_block(mod_block, 'BODY') output = writer.getvalue() dispatch = 'switch πF.State() {\n\tcase 0:\n\tdefault: panic' self.assertIn(dispatch, output)
def __init__(self, block_, future_node=None): self.block = block_ self.future_node = future_node self.writer = util.Writer() self.expr_visitor = expr_visitor.ExprVisitor(self)
def testDedent(self): writer = util.Writer() writer.indent(4) writer.dedent(3) writer.write('foo') self.assertEqual(writer.getvalue(), '\tfoo\n')
def testWriteTmpl(self): writer = util.Writer() writer.write_tmpl('$foo, $bar\n$baz', foo=1, bar=2, baz=3) self.assertEqual(writer.getvalue(), '1, 2\n3\n')
def testWriteSkipBlankLine(self): writer = util.Writer() writer.write('foo\n\nbar') self.assertEqual(writer.getvalue(), 'foo\nbar\n')
def testWritePyContext(self): writer = util.Writer() writer.write_py_context(12, 'print "foo"') self.assertEqual(writer.getvalue(), '// line 12: print "foo"\n')
def testWriteMultiline(self): writer = util.Writer() writer.indent(2) writer.write('foo\nbar\nbaz\n') self.assertEqual(writer.getvalue(), '\t\tfoo\n\t\tbar\n\t\tbaz\n')
def _ResolveName(self, b, name): writer = util.Writer() b.resolve_name(writer, name) return writer.getvalue()