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 == """\
 #   
  #  
###  
     
     
"""

    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"""


@@ -495,16 +495,177 @@
   %0A%22%22%22%0A%0A
+        display.export(%22temp.txt%22)%0A        with open(%22temp.txt%22, %22r%22) as datafile:%0A            assert datafile.read() == %22%22%22%5C%0A #   %0A  #  %0A###  %0A     %0A     %0A%22%22%22%0A%0A
     def 
@@ -913,12 +913,144 @@
 # ## %5Cn%22%22%22%0A%0A
+        display.export(%22temp.txt%22)%0A        with open(%22temp.txt%22, %22r%22) as datafile:%0A            assert datafile.read() == %22# ## %5Cn%22%0A%0A

test exporting data, too.