<commit_before>import unittest
import os
from performance_testing.command_line import Tool


class CommandLineToolTest(unittest.TestCase):
    def setUp(self):
        self.current_directory = os.path.dirname(os.path.abspath(__file__))
        self.config = os.path.join(self.current_directory, 'assets/test_config.yml')
        self.result_directory = os.path.join(self.current_directory, 'assets/test_result')
        if os.path.exists(self.result_directory):
            os.removedirs(self.result_directory)

    def test_init(self):
        tool = Tool(config=self.config, result_directory=self.result_directory)
        self.assertTrue(os.path.exists(self.result_directory))
        self.assertEquals(tool.result_directory,
                          os.path.join(self.current_directory,
                                       'assets/test_result'))
        self.assertEquals(tool.host, 'http://www.example.com')
        self.assertEquals(tool.requests, 100)
        self.assertEquals(tool.clients, 2)
        self.assertEquals(tool.time, 60)
        self.assertEquals(tool.urls, ['/', '/about'])
<commit_msg>Write test for read_config<commit_after>import unittest
import os
from performance_testing.command_line import Tool


class CommandLineToolTest(unittest.TestCase):
    def setUp(self):
        self.current_directory = os.path.dirname(os.path.abspath(__file__))
        self.config = os.path.join(self.current_directory, 'assets/test_config.yml')
        self.result_directory = os.path.join(self.current_directory, 'assets/test_result')
        if os.path.exists(self.result_directory):
            os.removedirs(self.result_directory)
        self.tool = Tool(self.config, result_directory=self.result_directory)

    def test_init(self):
        tool = Tool(config=self.config, result_directory=self.result_directory)
        self.assertTrue(os.path.exists(self.result_directory))
        self.assertEquals(tool.result_directory,
                          os.path.join(self.current_directory,
                                       'assets/test_result'))
        self.assertEquals(tool.host, 'http://www.example.com')
        self.assertEquals(tool.requests, 100)
        self.assertEquals(tool.clients, 2)
        self.assertEquals(tool.time, 60)
        self.assertEquals(tool.urls, ['/', '/about'])

    def test_read_config(self):
        with self.assertRaises(IOError) as ex:
            self.tool.read_config(config='foo/bar')
        self.assertEquals(ex.exception.message, 'Config file error "foo/bar".')
        with self.assertRaises(KeyError) as ex:
            self.tool.read_config(config=os.path.join(self.current_directory, 'assets/test_no_host_config.yml'))
        self.assertEquals(ex.exception.message, 'host')
        with self.assertRaises(KeyError) as ex:
            self.tool.read_config(config=os.path.join(self.current_directory, 'assets/test_no_requests_config.yml'))
        self.assertEquals(ex.exception.message, 'requests')
        with self.assertRaises(KeyError) as ex:
            self.tool.read_config(config=os.path.join(self.current_directory, 'assets/test_no_clients_config.yml'))
        self.assertEquals(ex.exception.message, 'clients')
        with self.assertRaises(KeyError) as ex:
            self.tool.read_config(config=os.path.join(self.current_directory, 'assets/test_no_time_config.yml'))
        self.assertEquals(ex.exception.message, 'time')
        with self.assertRaises(KeyError) as ex:
            self.tool.read_config(config=os.path.join(self.current_directory, 'assets/test_no_urls_config.yml'))
        self.assertEquals(ex.exception.message, 'urls')

{'fraction_non_alphanumeric': 0.11742006615214995, 'fraction_numerical': 0.0033076074972436605, 'mean_word_length': 3.161697247706422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624184', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1061, 'n_words': 142}