<commit_before>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"""
<commit_msg>test exporting data, too.<commit_after>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"

{'fraction_non_alphanumeric': 0.13170472650026555, 'fraction_numerical': 0.012745618693574084, 'mean_word_length': 2.5083798882681565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '471849', 'n_tokens_mistral': 671, 'n_tokens_neox': 646, 'n_words': 128}