old_contents: from indent_io import IndentIO
  from cStringIO import StringIO
  from pyast import *
  import pytest
  
  ast_output_tests = [
  
  (While(BinOp(Const(4), '==', Const(1)),
      [While(Const(False),
          [Const(True),
           Const(4)])]),
  """while (4 == 1):
      while False:
          True
          4"""),
  
  (For('x', Const(4), [Pass()]),
  """for x in 4:
      pass"""),
  
  ]
  
  ast_no_validate_tests = [
          While(Pass(), Pass()),
  ]
  
  @pytest.mark.parametrize('ast,output', ast_output_tests)
  def test_output(ast, output):
      ast.check()
      outbuf = StringIO()
      outio = IndentIO(outbuf)
      ast.write_to(outio)
      outbuf.seek(0)
      # We strip whitespace off of the actual output here; Otherwise we will often
      # get trailing whitespace on an empty line, which is weird to look at here
      # given that it matters semantically for the tests, and it doesn't affect
      # the python semantics, so we don't care.
      assert outbuf.read().strip() == output
  
  
  @pytest.mark.parametrize('ast', ast_no_validate_tests)
  def test_no_validate(ast):
      with pytest.raises(ValidationError):
          ast.check()
  
  
  def test_indent_io():
      outbuf = StringIO()
      io = IndentIO(outbuf)
  
      io.write('%d\n' % io.level)
      with io.indent():
          io.write('%d\n' % io.level)
          with io.indent():
              io.write('%d-' % io.level)
              io.write('%d\n' % io.level)
              with io.indent():
                  io.write('%d\n' % io.level)
              io.write('%d\n' % io.level)
          io.write('%d\n' % io.level)
      io.write('%d\n' % io.level)
  
      outbuf.seek(0)
      assert outbuf.read() ==\
  """0
      1
          2-2
              3
          2
      1
  0
  """
  
new_contents: from indent_io import IndentIO
  from cStringIO import StringIO
  from pyast import *
  import pytest
  
  ast_output_tests = [
  
  (Const(0), "0"),
  (Const('Hello'), "'Hello'"),
  (Const(True), 'True'),
  (Const(4.2), '4.2'),
  
  (BinOp(Const(4), '+', Const(2)),
      "(4 + 2)"),
  (BinOp(BinOp(Const(4), '+', Const(2)), '<', Const(7)),
      "((4 + 2) < 7)"),
  
  (Pass(), "pass"),
  
  (While(Const(True), [Pass()]),
  """while True:
      pass"""),
  
  (While(BinOp(Const(4), '==', Const(1)),
      [While(Const(False),
          [Const(True),
           Const(4)])]),
  """while (4 == 1):
      while False:
          True
          4"""),
  
  (For('x', Const(4), [Pass()]),
  """for x in 4:
      pass"""),
  
  (For('x', Const(4), [Pass(), Const(False)]),
  """for x in 4:
      pass
      False"""),
  
  ]
  
  ast_no_validate_tests = [
  
          Const(BinOp(Const(4), '+', Const(2))),
  
          Const(Pass()),
  
          While(Pass(), Pass()),
  
          BinOp(Const(4), Const(5), Const(6)),
  
  ]
  
  @pytest.mark.parametrize('ast,output', ast_output_tests)
  def test_output(ast, output):
      ast.check()
      outbuf = StringIO()
      outio = IndentIO(outbuf)
      ast.write_to(outio)
      outbuf.seek(0)
      # We strip whitespace off of the actual output here; Otherwise we will often
      # get trailing whitespace on an empty line, which is weird to look at here
      # given that it matters semantically for the tests, and it doesn't affect
      # the python semantics, so we don't care.
      assert outbuf.read().strip() == output
  
  
  @pytest.mark.parametrize('ast', ast_no_validate_tests)
  def test_no_validate(ast):
      with pytest.raises(ValidationError):
          ast.check()
  
  
  def test_indent_io():
      outbuf = StringIO()
      io = IndentIO(outbuf)
  
      io.write('%d\n' % io.level)
      with io.indent():
          io.write('%d\n' % io.level)
          with io.indent():
              io.write('%d-' % io.level)
              io.write('%d\n' % io.level)
              with io.indent():
                  io.write('%d\n' % io.level)
              io.write('%d\n' % io.level)
          io.write('%d\n' % io.level)
      io.write('%d\n' % io.level)
  
      outbuf.seek(0)
      assert outbuf.read() ==\
  """0
      1
          2-2
              3
          2
      1
  0
  """
  
subject: Add more tests