<commit_before>import unittest2

from cfn_sphere.stack_configuration import Config, StackConfig, NoConfigException
from cfn_sphere.exceptions import CfnSphereException


class ConfigTests(unittest2.TestCase):
    def test_properties_parsing(self):
        config = Config(
            config_dict={'region': 'eu-west-1', 'tags': {'global-tag': 'global-tag-value'},
                         'stacks': {'any-stack': {'template-url': 'foo.json', 'tags': {'any-tag': 'any-tag-value'},
                                                  'parameters': {'any-parameter': 'any-value'}}}})
        self.assertEqual('eu-west-1', config.region)
        self.assertEqual(1, len(config.stacks.keys()))
        self.assertTrue(isinstance(config.stacks['any-stack'], StackConfig))
        self.assertEqual('foo.json', config.stacks['any-stack'].template_url)
        self.assertEqual({'any-tag': 'any-tag-value'}, config.stacks['any-stack'].tags)
        self.assertEqual({'global-tag': 'global-tag-value'}, config.tags)
        self.assertEqual({'any-parameter': 'any-value'}, config.stacks['any-stack'].parameters)

    def test_raises_exception_if_no_region_key(self):
        with self.assertRaises(NoConfigException):
            Config(config_dict={'foo': '', 'stacks': {'any-stack': {'template': 'foo.json'}}})

    def test_raises_exception_if_no_stacks_key(self):
        with self.assertRaises(NoConfigException):
            Config(config_dict={'region': 'eu-west-1'})

    def test_properties_parsing_cli_params(self):
        config = Config(cli_params=("stack1.p1=v1", "stack1.p2=v2"),
                        config_dict={'region': 'eu-west-1', 'stacks': {'foo': {'template-url': 'foo.json'}}})
        self.assertTrue('p1' in config.cli_params['stack1'])
        self.assertTrue('p2' in config.cli_params['stack1'])
        self.assertTrue('v1' in config.cli_params['stack1'].values())
        self.assertTrue('v2' in config.cli_params['stack1'].values())

    def test_config_raises_exception_if_only_cli_params_given(self):
        with self.assertRaises(NoConfigException):
            Config(cli_params="foo")

    def test_parse_cli_parameters_throws_exception_on_invalid_syntax(self):
        with self.assertRaises(CfnSphereException):
            Config._parse_cli_parameters(("foo",))



    def test_parse_cli_parameters_parses_multiple_parameters(self):
        self.assertDictEqual({'stack1': {'p1': 'v1', 'p2': 'v2'}, 'stack2': {'p1': 'v1'}},
                             Config._parse_cli_parameters(("stack1.p1=v1", "stack1.p2=v2", "stack2.p1=v1")))

    def test_parse_cli_parameters_accepts_spaces(self):
        self.assertDictEqual({'stack1': {'p1': 'v1', 'p2': 'v2'}, 'stack2': {'p1': 'v1'}},
                             Config._parse_cli_parameters(("stack1.p1 = v1 ", "stack1.p2=v2", "stack2.p1=v1 ")))
<commit_msg>Add test for timeout parameter<commit_after>import unittest2

from cfn_sphere.stack_configuration import Config, StackConfig, NoConfigException
from cfn_sphere.exceptions import CfnSphereException


class ConfigTests(unittest2.TestCase):
    def test_properties_parsing(self):
        config = Config(
                config_dict={
                    'region': 'eu-west-1',
                    'tags':   {
                        'global-tag': 'global-tag-value'
                    },
                    'stacks': {
                        'any-stack': {
                            'timeout': 99,
                            'template-url': 'foo.json',
                            'tags':         {
                                'any-tag': 'any-tag-value'
                            },
                            'parameters':   {
                                'any-parameter': 'any-value'
                            }
                        }
                    }
                }
        )
        self.assertEqual('eu-west-1', config.region)
        self.assertEqual(1, len(config.stacks.keys()))
        self.assertTrue(isinstance(config.stacks['any-stack'], StackConfig))
        self.assertEqual('foo.json', config.stacks['any-stack'].template_url)
        self.assertEqual({'any-tag': 'any-tag-value'}, config.stacks['any-stack'].tags)
        self.assertEqual({'global-tag': 'global-tag-value'}, config.tags)
        self.assertEqual({'any-parameter': 'any-value'}, config.stacks['any-stack'].parameters)
        self.assertEqual(99, config.stacks['any-stack'].timeout)

    def test_raises_exception_if_no_region_key(self):
        with self.assertRaises(NoConfigException):
            Config(config_dict={'foo': '', 'stacks': {'any-stack': {'template': 'foo.json'}}})

    def test_raises_exception_if_no_stacks_key(self):
        with self.assertRaises(NoConfigException):
            Config(config_dict={'region': 'eu-west-1'})

    def test_properties_parsing_cli_params(self):
        config = Config(cli_params=("stack1.p1=v1", "stack1.p2=v2"),
                        config_dict={'region': 'eu-west-1', 'stacks': {'foo': {'template-url': 'foo.json'}}})
        self.assertTrue('p1' in config.cli_params['stack1'])
        self.assertTrue('p2' in config.cli_params['stack1'])
        self.assertTrue('v1' in config.cli_params['stack1'].values())
        self.assertTrue('v2' in config.cli_params['stack1'].values())

    def test_config_raises_exception_if_only_cli_params_given(self):
        with self.assertRaises(NoConfigException):
            Config(cli_params="foo")

    def test_parse_cli_parameters_throws_exception_on_invalid_syntax(self):
        with self.assertRaises(CfnSphereException):
            Config._parse_cli_parameters(("foo",))

    def test_parse_cli_parameters_parses_multiple_parameters(self):
        self.assertDictEqual({'stack1': {'p1': 'v1', 'p2': 'v2'}, 'stack2': {'p1': 'v1'}},
                             Config._parse_cli_parameters(("stack1.p1=v1", "stack1.p2=v2", "stack2.p1=v1")))

    def test_parse_cli_parameters_accepts_spaces(self):
        self.assertDictEqual({'stack1': {'p1': 'v1', 'p2': 'v2'}, 'stack2': {'p1': 'v1'}},
                             Config._parse_cli_parameters(("stack1.p1 = v1 ", "stack1.p2=v2", "stack2.p1=v1 ")))

{'fraction_non_alphanumeric': 0.1558589306029579, 'fraction_numerical': 0.018527547537786446, 'mean_word_length': 2.7139408569704284, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6643596', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1885, 'n_words': 259}