<commit_before>import subprocess
import sys
import unittest

import perf


class TestTimeit(unittest.TestCase):
    def test_cli(self):
        runs = [perf.RunResult([1.0], loops=100),
                perf.RunResult([1.5], loops=100),
                perf.RunResult([2.0], loops=100)]
        json = [run.json() for run in runs]
        json = '\n'.join(json)
        # check that empty lines are ignore
        json = '\n' + json + '\n\n'

        args = [sys.executable, '-m', 'perf']
        proc = subprocess.Popen(args,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                universal_newlines=True)
        stdout = proc.communicate(json)[0]
        self.assertEqual(proc.returncode, 0)

        self.assertEqual(stdout.rstrip(),
                         'Average: 1.50 sec +- 0.50 sec '
                         '(3 runs x 1 sample x 100 loops)')


if __name__ == "__main__":
    unittest.main()
<commit_msg>test_perf_cli: test also individual run<commit_after>import subprocess
import sys
import unittest

import perf


class TestPerfCLI(unittest.TestCase):
    def test_run_result(self):
        run = perf.RunResult([1.0, 1.5, 2.0], loops=100)
        json = run.json()

        args = [sys.executable, '-m', 'perf']
        proc = subprocess.Popen(args,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                universal_newlines=True)
        stdout = proc.communicate(json)[0]
        self.assertEqual(proc.returncode, 0)

        self.assertEqual(stdout.rstrip(),
                         'Average: 1.50 sec +- 0.50 sec '
                         '(3 samples x 100 loops)')

    def test_results(self):
        runs = [perf.RunResult([1.0], loops=100),
                perf.RunResult([1.5], loops=100),
                perf.RunResult([2.0], loops=100)]
        json = [run.json() for run in runs]
        json = '\n'.join(json)
        # check that empty lines are ignore
        json = '\n' + json + '\n\n'

        args = [sys.executable, '-m', 'perf']
        proc = subprocess.Popen(args,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                universal_newlines=True)
        stdout = proc.communicate(json)[0]
        self.assertEqual(proc.returncode, 0)

        self.assertEqual(stdout.rstrip(),
                         'Average: 1.50 sec +- 0.50 sec '
                         '(3 runs x 1 sample x 100 loops)')


if __name__ == "__main__":
    unittest.main()

{'fraction_non_alphanumeric': 0.12046827794561933, 'fraction_numerical': 0.0290785498489426, 'mean_word_length': 1.5618955512572534, 'pattern_counts': {'":': 2, '<': 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': '6172052', 'n_tokens_mistral': 836, 'n_tokens_neox': 758, 'n_words': 173}