<commit_before>import unittest
from mock import patch, Mock

from cbas.configuration import CBASConfig


class TestCBASConfig(unittest.TestCase):

    @patch('getpass.getuser', Mock(return_value='ANY_USER'))
    def test_default_initialization(self):
        config = CBASConfig()
        self.assertEqual(config.username, 'ANY_USER')
        self.assertEqual(config.auth_url, None)
        self.assertEqual(config.client_secret, None)
        self.assertEqual(config.password_provider, 'prompt')
        self.assertEqual(config.jump_host, None)
        self.assertEqual(config.ssh_key_file, '~/.ssh/id_rsa.pub')

    @patch('getpass.getuser', Mock(return_value='ANY_USER'))
    def test_str_defaults(self):
        config = CBASConfig()
        expected = eval("{'username': 'ANY_USER', "
                        "'auth_url': None, "
                        "'client_secret': None, "
                        "'password_provider': 'prompt', "
                        "'jump_host': None,"
                        "'ssh_key_file': '~/.ssh/id_rsa.pub'}"
                        )
        received = eval(str(config))
        self.assertEqual(expected, received)

    @patch('getpass.getuser', Mock(return_value='NO_USER'))
    def test_inject(self):
        config = CBASConfig()
        to_inject = {
            'username': 'ANY_USER',
            'auth_url': 'ANY_URL',
            'client_secret': 'ANY_SECRET',
            'password_provider': 'ANY_PROVIDER',
            # exclude jump_host to make sure it remains None
        }
        config.inject(to_inject)
        self.assertEqual(config.username, 'ANY_USER')
        self.assertEqual(config.auth_url, 'ANY_URL')
        self.assertEqual(config.client_secret, 'ANY_SECRET')
        self.assertEqual(config.password_provider, 'ANY_PROVIDER')
        self.assertEqual(config.jump_host, None)

<commit_msg>test loading and normalizing config<commit_after>import unittest
from mock import patch, Mock

from cbas.configuration import CBASConfig


class TestCBASConfig(unittest.TestCase):

    @patch('getpass.getuser', Mock(return_value='ANY_USER'))
    def test_default_initialization(self):
        config = CBASConfig()
        self.assertEqual(config.username, 'ANY_USER')
        self.assertEqual(config.auth_url, None)
        self.assertEqual(config.client_secret, None)
        self.assertEqual(config.password_provider, 'prompt')
        self.assertEqual(config.jump_host, None)
        self.assertEqual(config.ssh_key_file, '~/.ssh/id_rsa.pub')

    @patch('getpass.getuser', Mock(return_value='ANY_USER'))
    def test_str_defaults(self):
        config = CBASConfig()
        expected = eval("{'username': 'ANY_USER', "
                        "'auth_url': None, "
                        "'client_secret': None, "
                        "'password_provider': 'prompt', "
                        "'jump_host': None,"
                        "'ssh_key_file': '~/.ssh/id_rsa.pub'}"
                        )
        received = eval(str(config))
        self.assertEqual(expected, received)

    @patch('getpass.getuser', Mock(return_value='NO_USER'))
    def test_inject(self):
        config = CBASConfig()
        to_inject = {
            'username': 'ANY_USER',
            'auth_url': 'ANY_URL',
            'client_secret': 'ANY_SECRET',
            'password_provider': 'ANY_PROVIDER',
            # exclude jump_host to make sure it remains None
        }
        config.inject(to_inject)
        self.assertEqual(config.username, 'ANY_USER')
        self.assertEqual(config.auth_url, 'ANY_URL')
        self.assertEqual(config.client_secret, 'ANY_SECRET')
        self.assertEqual(config.password_provider, 'ANY_PROVIDER')
        self.assertEqual(config.jump_host, None)

    @patch('yamlreader.yaml_load',
           Mock(return_value={'nospecial': 'ANY_VALUE_ONE',
                              'with-hyphen': 'ANY_VALUE_TWO',
                              'with-many-hyphens': 'ANY_VALUE_THREE',
                              'with_underscore': 'ANY_VALUE_FOUR',
                              'with_under_scores': 'ANY_VALUE_FIVE',
                              }))
    def test_load_config(self):
        received = CBASConfig.load_config('ANY_PATH')
        expected = {'nospecial': 'ANY_VALUE_ONE',
                    'with_hyphen': 'ANY_VALUE_TWO',
                    'with_many_hyphens': 'ANY_VALUE_THREE',
                    'with_underscore': 'ANY_VALUE_FOUR',
                    'with_under_scores': 'ANY_VALUE_FIVE',
                    }
        self.assertEqual(expected, received)

{'fraction_non_alphanumeric': 0.11953671328671328, 'fraction_numerical': 0.0, 'mean_word_length': 2.25997150997151, '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': '7547034', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1292, 'n_words': 208}