Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add skill.json, resolve failing tests #9

Merged
merged 14 commits into from
Oct 10, 2023
2 changes: 2 additions & 0 deletions .github/workflows/update_skill_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ on:

jobs:
update_skill_json:
permissions:
contents: write
uses: neongeckocom/.github/.github/workflows/skill_update_json_spec.yml@master
22 changes: 11 additions & 11 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


class JokingSkill(OVOSSkill):
def __init__(self):
super(JokingSkill, self).__init__(name="JokingSkill")
def __init__(self, *args, **kwargs):
super(JokingSkill, self).__init__(*args, **kwargs)
# TODO config from settings
self.translator = OVOSLangTranslationFactory.create()

Expand All @@ -39,17 +39,17 @@ def _fix_encoding(self, string: str) -> str:
"\r": " ",
"\n": " ",
"â\x80\x99": "'", # right single quotation mark
'â\x80\x98': "'", # left single quotation mark
"â\x80\x98": "'", # left single quotation mark
"â\x80\x93": "–", # en dash
'â\x80\x94': '—', # em dash
"â\x80\x94": "—", # em dash
"â\x80¦": "…", # ellipsis
'â\x82¬': '€', # euro sign
'â\x80\x8b': '‐', # hyphen (non-breaking)
'Â\xa0': ' ', # non-breaking space
'â\x80\x9e': '"', # double low-9 quotation mark
'â\x80\x9a': "'", # single low-9 quotation mark
'â\x80\xba': '›', # single right-pointing angle quotation mark
'â\x80\xb9': '‹' # single left-pointing angle quotation mark
"â\x82¬": "€", # euro sign
"â\x80\x8b": "‐", # hyphen (non-breaking)
"Â\xa0": " ", # non-breaking space
"â\x80\x9e": '"', # double low-9 quotation mark
"â\x80\x9a": "'", # single low-9 quotation mark
"â\x80\xba": "›", # single right-pointing angle quotation mark
"â\x80\xb9": "‹", # single left-pointing angle quotation mark
}

for old, new in replacements.items():
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pytest-cov
neon-lang-plugin-libretranslate~=0.2
ovos-translate-server-plugin
tox
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ovos_plugin_manager
ovos_workshop
ovos_utils
pyjokes
ovos-translate-server-plugin
ovos-translate-server-plugin
59 changes: 59 additions & 0 deletions skill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"title": "Jokes",
"url": "https://github.com/JarbasSkills/skill-icanhazdadjokes",
"summary": "Let Mycroft brighten your day with a little humor from [icanhazdadjoke](icanhazdadjoke.com) ![](./ui/logo.png) Chuck Norris jokes powered by [pyjokes](https://github.com/pyjokes/pyjokes)",
"short_description": "Let Mycroft brighten your day with a little humor from [icanhazdadjoke](icanhazdadjoke.com) ![](./ui/logo.png) Chuck Norris jokes powered by [pyjokes](https://github.com/pyjokes/pyjokes)",
"description": "Brighten your day with dad humor. _WARNING: Laughter is not guaranteed, but eye rolls are likely._ Works in all languages NOTE: this will automatically blacklist the official mycroft skill",
"examples": [
"Tell me a joke.",
"Say a joke.",
"Do you know any jokes?",
"Can you tell jokes?",
"Make me laugh.",
"Tell me a joke about dentists.",
"Do you know any Chuck Norris jokes?"
],
"desktopFile": false,
"warning": "",
"systemDeps": false,
"requirements": {
"python": [
"ovos-translate-server-plugin",
"ovos_plugin_manager",
"ovos_utils",
"ovos_workshop",
"pyjokes"
],
"system": {},
"skill": []
},
"incompatible_skills": [],
"platforms": [
"arm",
"arm64",
"i386",
"x86_64",
"ia64"
],
"branch": "master",
"license": "Unknown",
"icon": "res/icon/dadjokes.png",
"category": "Entertainment",
"categories": [
"Entertainment"
],
"tags": [
"joke",
"jokes",
"humor",
"humour",
"funny"
],
"credits": [],
"skillname": "skill-icanhazdadjokes",
"authorname": "JarbasSkills",
"foldername": null,
"name": "Jokes",
"logo": "action/skill/ui/logo.png",
"platform support": "- :heavy_check_mark: - tested and confirmed working - :x: - incompatible/non-functional - :question: - untested - :construction: - partial support | platform | status | tag | version | last tested | |:---------------:|:----------:|:-----:|:-------:|:-----------:| | [Chatterbox](https://hellochatterbox.com) | :question: | dev | | never | | [HolmesV](https://github.com/HelloChatterbox/HolmesV) | :question: | dev | | never | | [LocalHive](https://github.com/JarbasHiveMind/LocalHive) | :question: | dev | | never | | [Mycroft Mark1](https://github.com/MycroftAI/enclosure-mark1) | :question: | dev | | never | | [Mycroft Mark2](https://github.com/MycroftAI/hardware-mycroft-mark-II) | :question: | dev | | never | | [NeonGecko](https://neon.ai) | :question: | dev | | never | | [OVOS](https://github.com/OpenVoiceOS) | :question: | dev | | never | | [Picroft](https://github.com/MycroftAI/enclosure-picroft) | :question: | dev | | never | | [Plasma Bigscreen](https://plasma-bigscreen.org/) | :question: | dev | | never | - `tag` - link to github release / branch / commit - `version` - link to release/commit of platform repo where this was tested"
}
21 changes: 8 additions & 13 deletions tests/test_joking.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,25 @@ def test_fix_encoding(self):
result = self.skill._fix_encoding(broken)
self.assertEqual(result, expected, f"Expected '{expected}', but got '{result}'")

def test_handle_joke(self):
@patch("requests.get", return_value=Mock(text="joke\r\n", raise_for_status=Mock()))
def test_handle_joke(self, mock_requests):
# Arrange
get_joke = self.skill.get_generic_joke = Mock(return_value="joke\r\n")
mock_requests.raise_for_status.return_value = None
fix = self.skill._fix_encoding = Mock(return_value="joke")
translate = self.skill.translate = Mock(return_value="blague")
self.skill.speak = Mock()
# Act
self.skill.handle_joke(
Message(
"skill-icanhazdadjokes.jarbasskills:joke.intent",
data={
"data": {
"utterances": ["tell me a joke", "tell me joke"],
"lang": "en-us",
"utterance": "tell me a joke",
}
"utterances": ["tell me a joke", "tell me joke"],
"lang": "fr-fr",
"utterance": "tell me a joke",
},
)
)
# Assert
get_joke.assert_called_once()
fix.assert_called_once_with(get_joke.return_value)
translate.assert_called_once_with(fix.return_value)
self.skill.speak.assert_called_once_with(translate.return_value)
fix.assert_called_once_with("joke\r\n")
self.skill.speak.assert_called_once_with("blague")

@patch("requests.get")
def test_get_generic_joke(self, mock_get):
Expand Down