示例#1
0
 def test_it_should_compute_a_path_relative_to_the_loaded_config_one(self):
     s = SettingsStore(additional_lookup={
         'PATHS_A_KEY': '../skills',
     })
     s.load_from_file(os.path.abspath('my_pytlas/pytlas.ini'))
     expect(s.getpath('a key', section='paths')).to.equal(
         os.path.abspath('my_pytlas/../skills'))
示例#2
0
 def test_it_should_leave_absolute_path_as_it(self):
     s = SettingsStore(additional_lookup={
         'PATHS_A_KEY': os.path.abspath('skills'),
     })
     s.load_from_file(os.path.abspath('my_pytlas/pytlas.ini'))
     expect(s.getpath('a key',
                      section='paths')).to.equal(os.path.abspath('skills'))
示例#3
0
 def test_it_should_load_settings_from_a_path(self):
     s = SettingsStore()
     expect(s.get('some_key', section='some_section')).to.be.none
     s.load_from_file(os.path.join(os.path.dirname(__file__),
                                   '__test.conf'))
     expect(s.get('some_key',
                  section='some_section')).to.equal('some_value')
     expect(s._loaded_from_path).to.equal(
         os.path.abspath(
             os.path.join(os.path.dirname(__file__), '__test.conf')))
示例#4
0
    def test_it_should_convert_all_settings_to_a_dict_representation(self):
        s = SettingsStore(additional_lookup={
            'A_SETTING': 'with a string value',
            'ANOTHER_ONE': '42',
        })
        s.load_from_file(os.path.join(os.path.dirname(__file__),
                                      '__test.conf'))

        expect(s.to_dict()).to.equal({
            'A_SETTING': 'with a string value',
            'ANOTHER_ONE': '42',
            'SOME_SECTION_SOME_KEY': 'some_value'
        })
示例#5
0
    def test_it_should_write_the_store_to_a_file(self):
        s = SettingsStore(additional_lookup={
            'A_SETTING': 'with a string value',
            'SOME_SECTION_SOME_KEY': '42',
        })
        s.load_from_file(os.path.join(os.path.dirname(__file__),
                                      '__test.conf'))
        s.set('my_value', '1337', section='weather')

        with patch('builtins.open', mock_open()) as mopen:
            s.write_to_file('a/file/path.ini')

            mopen().write.assert_has_calls([
                call('[some_section]\n'),
                call('some_key=42\n'),
                call('\n'),
                call('[weather]\n'),
                call('my_value=1337\n'),
                call('\n'),
            ])
示例#6
0
    def create(self, uid: str) -> Agent:
        cache_dir, conf_path = get_config_directories_path(
            self._directory, uid)
        meta = {}

        if os.path.isfile(conf_path):
            store = SettingsStore()
            store.load_from_file(conf_path)
            meta = store.to_dict()
            self._logger.info('Using settings from "%s"', conf_path)
        else:
            cache_dir = self._default_cache_dir
            self._logger.warning(
                'Could not find a pytlas.ini file in "%s", using the default one',
                conf_path)

        interpreter = SnipsInterpreter(meta.get(
            to_env_key(DEFAULT_SECTION, LANGUAGE_KEY), DEFAULT_LANGUAGE),
                                       cache_directory=cache_dir)
        interpreter.fit_from_skill_data()
        return Agent(interpreter, **meta)