<commit_before>import unittest
import sys
sys.path.insert(0, '../src')
import io
from formatter import *
from testdata import Section
import executor


class TestTextFormatter(unittest.TestCase):
    def test_empty_session(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst)
        f.begin_session()
        f.end_session()
        self.assertEqual(dst.getvalue(), '')

    def test_single_case(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst)
        f.begin_session()
        f.begin_test("description", ["a b c"], "1\n2\n3\n", "x\ny\n")
        f.end_session()
        exp = """TEST: description
COMMAND LINE: a b c
INPUT:
1
2
3
TEMPORARY FILE:
x
y
"""
        self.assertEqual(dst.getvalue(), exp)

    def test_errors(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst,
                          verbosity=TextFormatter.ERROR)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        
        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_SEGFAULT, -1, "", "")
        f.execution_result(["prog"], res)

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_TIMEOUT, 0, "", "")
        f.execution_result(["prog"], res)

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_ERROR, 42, "", "")
        f.execution_result(["prog"], res)

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_NOTFILE, 1, "", "")
        f.execution_result(["prog"], res)
        
        f.end_session()
        exp = """PROCESS ENDED WITH A FAILURE (SEGMENTATION FAULT)
TIMEOUT EXPIRED: PROCESS TERMINATED
PROCESS ENDED WITH A FAILURE (ERROR CODE 42)
FAILED TO RUN THE FILE 'prog' (the file does not exist)
"""<commit_msg>Aggiornato test formatter<commit_after>import unittest
import sys
sys.path.insert(0, '../src')
import io
from formatter import *
from testdata import Section
import executor


class TestTextFormatter(unittest.TestCase):
    def test_empty_session(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst)
        f.begin_session()
        f.end_session()
        self.assertEqual(dst.getvalue(), '')

    def test_single_case(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst)
        f.begin_session()
        f.begin_test("description", ["a b c"], "1\n2\n3\n", "x\ny\n")
        f.end_session()
        exp = """TEST: description
COMMAND LINE: a b c
INPUT:
1
2
3
TEMPORARY FILE:
x
y
"""
        self.assertEqual(dst.getvalue(), exp)

    def test_errors(self):
        dst = io.StringIO()
        f = TextFormatter(destination=dst,
                          verbosity=TextFormatter.ERROR)
        f.begin_session()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_OK, 0, "", "")
        f.execution_result(["prog"], res)
        f.end_test()
        
        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_SEGFAULT, -1, "", "")
        f.execution_result(["prog"], res)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_TIMEOUT, 0, "", "")
        f.execution_result(["prog"], res)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_ERROR, 42, "", "")
        f.execution_result(["prog"], res)
        f.end_test()

        f.begin_test("description", ["abc"], "1\n", "")
        res = executor.ExecResult(executor.ER_NOTFILE, 1, "", "")
        f.execution_result(["prog"], res)
        f.end_test()
        
        f.end_session()
        exp = """PROCESS ENDED WITH A FAILURE (SEGMENTATION FAULT)
TIMEOUT EXPIRED: PROCESS TERMINATED
PROCESS ENDED WITH A FAILURE (ERROR CODE 42)
FAILED TO RUN THE FILE 'prog' (the file does not exist)
"""
{'fraction_non_alphanumeric': 0.15845155085357057, 'fraction_numerical': 0.009617696561673479, 'mean_word_length': 2.652326602282704, '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': '7424466', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1332, 'n_words': 287}