import unittest
import os
import shutil
from performance_testing.command_line import Tool
from performance_testing.errors import ConfigFileError, ConfigKeyError


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):
            shutil.rmtree(self.result_directory)
        self.tool = Tool(config=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.assertRegex(tool.result_file,
                         os.path.join(self.current_directory,
                                      'assets/test_result') + '/[1-9][0-9][0-9][0-9]-[0-9]?[0-9]-[0-9][0-9]_[0-9][0-9]-[0-9][0-9]-[0-9][0-9]')
        self.assertEqual(tool.host, 'http://www.example.com')
        self.assertEqual(tool.requests, 100)
        self.assertEqual(tool.clients, 2)
        self.assertEqual(tool.time, 60)
        self.assertEqual(tool.urls, ['/', '/about'])

    def test_read_config(self):
        with self.assertRaises(ConfigFileError) as ex:
            self.tool.read_config(config_file='foo/bar')
        self.assertEqual(ex.exception.message, 'Config file not exists "foo/bar".')

        with self.assertRaises(ConfigKeyError) as ex:
            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_host_config.yml'))
        self.assertEqual(ex.exception.message, 'Config with key "host" not set.')

        with self.assertRaises(ConfigKeyError) as ex:
            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_requests_config.yml'))
        self.assertEqual(ex.exception.message, 'Config with key "requests" not set.')

        with self.assertRaises(ConfigKeyError) as ex:
            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_clients_config.yml'))
        self.assertEqual(ex.exception.message, 'Config with key "clients" not set.')

        with self.assertRaises(ConfigKeyError) as ex:
            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_time_config.yml'))
        self.assertEqual(ex.exception.message, 'Config with key "time" not set.')

        with self.assertRaises(ConfigKeyError) as ex:
            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_urls_config.yml'))
        self.assertEqual(ex.exception.message, 'Config with key "urls" not set.')

@@ -479,2365 +479,110 @@
 t')%0A
-        if os.path.exists(self.result_directory):%0A            shutil.rmtree(self.result_directory)%0A        self.tool = Tool(config=self.config, result_directory=self.result_directory)%0A%0A    def test_init(self):%0A        tool = Tool(config=self.config, result_directory=self.result_directory)%0A        self.assertTrue(os.path.exists(self.result_directory))%0A        self.assertRegex(tool.result_file,%0A                         os.path.join(self.current_directory,%0A                                      'assets/test_result') + '/%5B1-9%5D%5B0-9%5D%5B0-9%5D%5B0-9%5D-%5B0-9%5D?%5B0-9%5D-%5B0-9%5D%5B0-9%5D_%5B0-9%5D%5B0-9%5D-%5B0-9%5D%5B0-9%5D-%5B0-9%5D%5B0-9%5D')%0A        self.assertEqual(tool.host, 'http://www.example.com')%0A        self.assertEqual(tool.requests, 100)%0A        self.assertEqual(tool.clients, 2)%0A        self.assertEqual(tool.time, 60)%0A        self.assertEqual(tool.urls, %5B'/', '/about'%5D)%0A%0A    def test_read_config(self):%0A        with self.assertRaises(ConfigFileError) as ex:%0A            self.tool.read_config(config_file='foo/bar')%0A        self.assertEqual(ex.exception.message, 'Config file not exists %22foo/bar%22.')%0A%0A        with self.assertRaises(ConfigKeyError) as ex:%0A            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_host_config.yml'))%0A        self.assertEqual(ex.exception.message, 'Config with key %22host%22 not set.')%0A%0A        with self.assertRaises(ConfigKeyError) as ex:%0A            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_requests_config.yml'))%0A        self.assertEqual(ex.exception.message, 'Config with key %22requests%22 not set.')%0A%0A        with self.assertRaises(ConfigKeyError) as ex:%0A            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_clients_config.yml'))%0A        self.assertEqual(ex.exception.message, 'Config with key %22clients%22 not set.')%0A%0A        with self.assertRaises(ConfigKeyError) as ex:%0A            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_time_config.yml'))%0A        self.assertEqual(ex.exception.message, 'Config with key %22time%22 not set.')%0A%0A        with self.assertRaises(ConfigKeyError) as ex:%0A            self.tool.read_config(config_file=os.path.join(self.current_directory, 'assets/test_no_urls_config.yml'))%0A        self.assertEqual(ex.exception.message, 'Config with key %22urls%22 not set.'
+%0A    def test_init(self):%0A        tool = Tool(config=self.config, result_directory=self.result_directory
 )%0A

Remove senseless testcode