<commit_before># -*- coding: utf-8 -*-

from __future__ import absolute_import
import unittest
from pylsy import PylsyTable


class PylsyTableTests(unittest.TestCase):

    def setUp(self):
        attributes = ["name", "age"]
        self.table = PylsyTable(attributes)

    def tearDown(self):
        self.table = None

    def testCreateTable(self):
        name = ["a", "b"]
        self.table.add_data("name", name)
        age = [1, 2]
        self.table.add_data("age", age)
        correct_file = open('correct.out', 'r')
        correctPrint = correct_file.read()
        try:
            import io
            from contextlib import redirect_stdout
            with io.StringIO() as buf, redirect_stdout(buf):
                print(self.table)
                output = buf.getvalue()
                self.assertEqual(output, correctPrint)
        except ImportError:
            import sys
            f_handler = open('test.out', 'w')
            sys.stdout = f_handler
            self.table.create_table()
            f_handler.close()
            f_handler = open('test.out', 'r')
            self.assertEqual(f_handler.read(), correctPrint)

if __name__ == '__main__':
    unittest.main()<commit_msg>Update pylsy_test.py<commit_after># -*- coding: utf-8 -*-

from __future__ import absolute_import
import unittest
from pylsy import PylsyTable


class PylsyTableTests(unittest.TestCase):

    def setUp(self):
        attributes = ["name", "age"]
        self.table = PylsyTable(attributes)

    def tearDown(self):
        self.table = None

    def testCreateTable(self):
        name = ["a", "b"]
        self.table.add_data("name", name)
        age = [1, 2]
        self.table.add_data("age", age)
        correct_file = open('correct.out', 'r')
        correctPrint = correct_file.read()
        try:
            #import io
            #from contextlib import redirect_stdout
            #with io.StringIO() as buf, redirect_stdout(buf):
                #print(self.table,end='')
            output = self.table.__str__()
            self.assertEqual(output, correctPrint)
        except ImportError:
            import sys
            f_handler = open('test.out', 'w')
            sys.stdout = f_handler
            self.table.create_table()
            f_handler.close()
            f_handler = open('test.out', 'r')
            self.assertEqual(f_handler.read(), correctPrint)

if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.1184640522875817, 'fraction_numerical': 0.0024509803921568627, 'mean_word_length': 2.084382871536524, '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': '2979668', 'n_tokens_mistral': 721, 'n_tokens_neox': 703, 'n_words': 160}