This repository was archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feature/skill configuration #933
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e3b4e7c
[WIP] modify settings.py to post metadata to api, and get settings fo…
LearnedVector 344d53c
[WIP]
LearnedVector d3621b7
[WIP] refactored
LearnedVector 01d8a0c
[WIP] need to add PATCH for settingsmeta.json
LearnedVector b6a7234
Merge branch 'dev' of https://github.com/MycroftAI/mycroft-core into …
LearnedVector de51d9a
fixed test
LearnedVector 565b8a5
Merge branch 'dev' of https://github.com/MycroftAI/mycroft-core into …
LearnedVector bf48d7b
[WIP] need to implement PATCH
LearnedVector f361392
Merge branch 'dev' of https://github.com/MycroftAI/mycroft-core into …
LearnedVector bb0dd95
changed server from test to prod in mycroft.conf
LearnedVector b891e03
implement patch functionality, chaged json structure
LearnedVector 00bde77
fixed test
LearnedVector 6eb1c19
add try except
LearnedVector 37ada28
refactored skill settings and fixed test
LearnedVector 1e8ee03
fixed pep8 issues
LearnedVector 0c0bc6f
fixed bugs
LearnedVector 05852f3
removed logger messages
LearnedVector 48b26d1
added new test and put back is_stored property
LearnedVector File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,74 +2,79 @@ | |
|
|
||
| from os.path import join, dirname, abspath | ||
| from os import remove | ||
| import json | ||
| import unittest | ||
|
|
||
|
|
||
| class SkillSettingsTest(unittest.TestCase): | ||
| def setUp(self): | ||
| try: | ||
| remove(join(dirname(__file__), 'settings', 'store.json')) | ||
| remove(join(dirname(__file__), 'settings', 'settings.json')) | ||
| except OSError: | ||
| pass | ||
|
|
||
| def test_new(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertEqual(len(s), 0) | ||
|
|
||
| def test_add_value(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| s['test_val'] = 1 | ||
|
|
||
| def test_load_existing(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings', 'existing.json')) | ||
| self.assertEqual(len(s), 4) | ||
| self.assertEqual(s['test_val'], 1) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a kind of important test case and should be implemented in some way
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
|
|
||
| def test_store(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| 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', 'store.json')) | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| for key in s: | ||
| self.assertEqual(s[key], s2[key]) | ||
|
|
||
| def test_update_list(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| s['l'] = ['a', 'b', 'c'] | ||
| s.store() | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertEqual(s['l'], s2['l']) | ||
|
|
||
| # Update list | ||
| s2['l'].append('d') | ||
| s2.store() | ||
| s3 = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s3 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertEqual(s2['l'], s3['l']) | ||
|
|
||
| def test_update_dict(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| s['d'] = {'a': 1, 'b': 2} | ||
| s.store() | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertEqual(s['d'], s2['d']) | ||
|
|
||
| # Update dict | ||
| s2['d']['c'] = 3 | ||
| s2.store() | ||
| s3 = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s3 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertEqual(s2['d'], s3['d']) | ||
|
|
||
| def test_no_change(self): | ||
| s = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| s = SkillSettings(join(dirname(__file__), 'settings')) | ||
| s['d'] = {'a': 1, 'b': 2} | ||
| s.store() | ||
|
|
||
| s = SkillSettings(join(dirname(__file__), 'settings', 'store.json')) | ||
| self.assertTrue(s._is_stored) | ||
| s2 = SkillSettings(join(dirname(__file__), 'settings')) | ||
| self.assertTrue(len(s) == len(s2)) | ||
|
|
||
| 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')) | ||
| self.assertEqual(len(s), 1) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"d": {"a": 1, "c": 3, "b": 2}, "int": 42, "float": 4.2, "list": ["batman", 2, true, "superman"], "l": ["a", "b", "c", "d"], "bool": true, "string": "Always carry a towel"} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the settings_file option to keep this more a general class that can be instantiated multiple times with multiple settings-files. Can you append a
.metato thesettings_filepath to keep the api?Makes testing easier as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved