old_contents: from __future__ import absolute_import
  
  from zasim import cagen
  from zasim.features import *
  from zasim.display.console import *
  
  from .testutil import *
  
  import pytest
  
  class TestCAGen:
      @pytest.mark.skipif("not HAVE_MULTIDIM")
      def test_pretty_print_config_2d(self, capsys):
          gconf = GLIDER[0]
          simo = cagen.GameOfLife(config=gconf)
          display = TwoDimConsolePainter(simo)
  
          out, err = capsys.readouterr()
          assert out == """\
   #   
    #  
  ###  
       
       
  """
  
          display.export("temp.txt")
          with open("temp.txt", "r") as datafile:
              assert datafile.read() == """\
   #   
    #  
  ###  
       
       
  """
  
      def test_pretty_print_config_1d(self, capsys):
          conf = np.array([1,0,1,1,0])
          br = cagen.BinRule(config=conf, rule=204)
          display = LinearConsolePainter(br, 1)
  
          out, err = capsys.readouterr()
          assert out == """# ## \n"""
  
          display.export("temp.txt")
          with open("temp.txt", "r") as datafile:
              assert datafile.read() == "# ## \n"
  
  
new_contents: from __future__ import absolute_import
  
  from zasim import cagen
  from zasim.features import *
  from zasim.display.console import *
  
  from .testutil import *
  
  import pytest
  import tempfile
  
  class TestCAGen:
      @pytest.mark.skipif("not HAVE_MULTIDIM")
      def test_pretty_print_config_2d(self, capsys):
          gconf = GLIDER[0]
          simo = cagen.GameOfLife(config=gconf)
          display = TwoDimConsolePainter(simo)
  
          out, err = capsys.readouterr()
          assert out == """\
   #   
    #  
  ###  
       
       
  """
  
          with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
              name = tmpfile.name
              display.export(tmpfile.name)
  
          assert open(name).read() == """\
   #   
    #  
  ###  
       
       
  """
  
      def test_pretty_print_config_1d(self, capsys):
          conf = np.array([1,0,1,1,0])
          br = cagen.BinRule(config=conf, rule=204)
          display = LinearConsolePainter(br, 1)
  
          out, err = capsys.readouterr()
          assert out == """# ## \n"""
  
          with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
              name = tmpfile.name
              display.export(tmpfile.name)
  
          assert open(name).read() == "# ## \n"
  
  
subject: use a temporary file instead of "temp.txt" in tests.