示例#1
0
def test_init_environment(mock_file):
    mock_file('not_default.ini',
              dedent('''
        [section]
        key: value
    '''))
    environment.init_environment('not_default')
    assert environment._ENVIRONMENT['section']['key'] == 'value'
示例#2
0
def test_get_environment_creates_default_environment(mock_file):
    mock_file('default.ini',
              dedent('''
        [section]
        key: value
    '''))
    env = environment.get_environment()
    assert env['section']['key'] == 'value'
示例#3
0
def test_load_config(mock_file):
    mock_file('default.ini',
              dedent('''
        [section]
        key: value
    '''))
    env = environment.Environment('default')
    assert env['section']['key'] == 'value'
示例#4
0
def test_get_environment_cached(mock_file):
    mock_file('default.ini',
              dedent('''
        [section]
        key: value
    '''))
    env1 = environment.get_environment()
    env2 = environment.get_environment()
    assert env1 == env2
示例#5
0
def test_default_section_not_in_sections(mock_file):
    mock_file(
        'default.ini',
        dedent('''
        [DEFAULT]
        default_key: default_value

        [section]
        key: value
    '''))
    env = environment.Environment('default')
    assert env.sections() == ['section']
示例#6
0
def test_load_multiple_sections(mock_file):
    mock_file(
        'default.ini',
        dedent('''
        [DEFAULT]
        default_key: default_value

        [section]
        key: value
    '''))
    env = environment.Environment('default')
    assert env['section']['key'] == 'value'
    assert env['DEFAULT']['default_key'] == 'default_value'
示例#7
0
def test_interpolation(mock_file):
    mock_file(
        'default.ini',
        dedent('''
        [DEFAULT]
        url: localhost
        sub_url: ${url}/sub_url

        [section]
        section_url: ${DEFAULT:url}/section_url
    '''))
    env = environment.Environment('default')
    assert env['DEFAULT']['sub_url'] == 'localhost/sub_url'
    assert env['section']['section_url'] == 'localhost/section_url'
    def test_set_locale(self):
        with mock_file(locale.XSESSION_RC_FILE):
            params = [
                'LANGUAGE',
                'LC_ADDRESS',
                'LC_COLLATE',
                'LC_CTYPE',
                'LC_MONETARY',
                'LC_MEASUREMENT',
                'LC_MESSAGES',
                'LC_NUMERIC',
                'LC_PAPER',
                'LC_RESPONSE',
                'LC_TELEPHONE',
                'LC_TIME'
            ]

            test_locale = 'en_US.UTF-8'
            config_lines = [
                'export {}={}'.format(param, test_locale) for param in params
            ]
            locale.set_locale(test_locale)

            config = utils.read_file_contents_as_lines(locale.XSESSION_RC_FILE)
            for line in config_lines:
                if line not in config:
                    self.assertFalse(True)

            self.assertTrue(True)
    def run_test_for_param(self, param):
        with mock_file(locale.XSESSION_RC_FILE):
            test_locale = 'en_US.UTF-8'
            config_line = 'export {}={}'.format(param, test_locale)
            locale.set_locale_param(param, test_locale)

            config = utils.read_file_contents_as_lines(locale.XSESSION_RC_FILE)

            self.assertTrue(config_line in config)
示例#10
0
    def run_test_for_param(self, param):
        with mock_file(locale.XSESSION_RC_FILE):
            test_locale = 'en_US.UTF-8'
            config_line = 'export {}={}'.format(param, test_locale)
            locale.set_locale_param(param, test_locale)

            config = utils.read_file_contents_as_lines(locale.XSESSION_RC_FILE)

            self.assertTrue(config_line in config)
示例#11
0
def test_quote(sample_client, sample_params):
    sample_params.update({'function': 'GLOBAL_QUOTE', 'symbol': 'MSFT'})
    want = mock_file('quote')
    responses.add(responses.GET,
                  BASE_URI + 'function=GLOBAL_QUOTE&symbol=MSFT',
                  status=200,
                  body=json.dumps(want),
                  match_querystring=True)
    got = sample_client.quote('MSFT')
    assert got == want['Global Quote']
示例#12
0
def test_search(sample_client, sample_params):
    sample_params.update({'function': 'SYMBOL_SEARCH', 'keywords': 'Micro'})
    want = mock_file('search')
    responses.add(responses.GET,
                  BASE_URI + 'function=SYMBOL_SEARCH&keywords=Micro',
                  status=200,
                  body=json.dumps(want),
                  match_querystring=True)
    got = sample_client.search('Micro')
    assert got == want['bestMatches']
示例#13
0
    def test_set_locale(self):
        with mock_file(locale.XSESSION_RC_FILE):
            params = [
                'LANGUAGE', 'LC_ADDRESS', 'LC_COLLATE', 'LC_CTYPE',
                'LC_MONETARY', 'LC_MEASUREMENT', 'LC_MESSAGES', 'LC_NUMERIC',
                'LC_PAPER', 'LC_RESPONSE', 'LC_TELEPHONE', 'LC_TIME'
            ]

            test_locale = 'en_US.UTF-8'
            config_lines = [
                'export {}={}'.format(param, test_locale) for param in params
            ]
            locale.set_locale(test_locale)

            config = utils.read_file_contents_as_lines(locale.XSESSION_RC_FILE)
            for line in config_lines:
                if line not in config:
                    self.assertFalse(True)

            self.assertTrue(True)
示例#14
0
def test_load_empty_config_doesnt_fail(mock_file):
    mock_file('default.ini', '')
    env = environment.Environment('default')