Пример #1
0
    def test_no_change(self):
        s = SkillSettings(join(dirname(__file__), 'settings'),
                          "test-skill-settings")
        s.allow_overwrite = True
        s['d'] = {'a': 1, 'b': 2}
        s.store()

        s2 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s2.allow_overwrite = True
        s2.load_skill_settings_from_file()
        self.assertTrue(len(s) == len(s2))
Пример #2
0
    def test_store(self):
        s = SkillSettings(join(dirname(__file__), 'settings'),
                          "test-skill-settings")
        s.allow_overwrite = True
        s.load_skill_settings_from_file()
        s['bool'] = True
        s['int'] = 42
        s['float'] = 4.2
        s['string'] = 'Always carry a towel'
        s['list'] = ['batman', 2, True, 'superman']
        s.store()

        s2 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s2.allow_overwrite = True
        s2.load_skill_settings_from_file()
        for key in s:
            self.assertEqual(s[key], s2[key])
Пример #3
0
 def test_load_existing(self):
     directory = join(dirname(__file__), 'settings', 'settings.json')
     with open(directory, 'w') as f:
         json.dump({"test": "1"}, f)
     s = SkillSettings(join(dirname(__file__), 'settings'),
                       "test-skill-settings")
     s.allow_overwrite = True
     s.load_skill_settings_from_file()
     self.assertEqual(len(s), 1)
Пример #4
0
    def test_update_dict(self):
        s = SkillSettings(join(dirname(__file__), 'settings'),
                          "test-skill-settings")
        s.allow_overwrite = True
        s['d'] = {'a': 1, 'b': 2}
        s.store()
        s2 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s2.allow_overwrite = True
        s2.load_skill_settings_from_file()
        self.assertEqual(s['d'], s2['d'])

        # Update dict
        s2['d']['c'] = 3
        s2.store()
        s3 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s3.allow_overwrite = True
        s3.load_skill_settings_from_file()
        self.assertEqual(s2['d'], s3['d'])
Пример #5
0
    def test_update_list(self):
        s = SkillSettings(join(dirname(__file__), 'settings'),
                          "test-skill-settings")
        s.allow_overwrite = True
        s.load_skill_settings_from_file()
        s['l'] = ['a', 'b', 'c']
        s.store()
        s2 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s2.allow_overwrite = True
        s2.load_skill_settings_from_file()
        self.assertEqual(s['l'], s2['l'])

        # Update list
        s2['l'].append('d')
        s2.store()
        s3 = SkillSettings(join(dirname(__file__), 'settings'),
                           "test-skill-settings")
        s3.allow_overwrite = True
        s3.load_skill_settings_from_file()
        self.assertEqual(s2['l'], s3['l'])
Пример #6
0
    def __init__(self, name=None, bus=None):
        self.name = name or self.__class__.__name__
        # Get directory of skill
        self._dir = dirname(abspath(sys.modules[self.__module__].__file__))
        self.settings = SkillSettings(self._dir, self.name)

        self.bus = None
        self.bind(bus)
        self.config_core = Configuration.get()
        self.config = self.config_core.get(self.name) or {}
        self.dialog_renderer = None
        self.root_dir = None
        self.file_system = FileSystemAccess(join('skills', self.name))
        self.registered_intents = []
        self.log = LOG.create_logger(self.name)
        self.reload_skill = True  # allow reloading
        self.events = []
        self.scheduled_repeats = []
        self.skill_id = ''  # will be set from the path, so guaranteed unique
        self.voc_match_cache = {}
Пример #7
0
 def test_add_value(self):
     s = SkillSettings(join(dirname(__file__), 'settings'),
                       "test-skill-settings")
     s['test_val'] = 1
     self.assertEqual(s['test_val'], 1)
Пример #8
0
 def test_new(self):
     s = SkillSettings(join(dirname(__file__), 'settings'),
                       "test-skill-settings")
     self.assertEqual(len(s), 0)