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
21 changes: 4 additions & 17 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ jobs:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up python ${{ matrix.python-version }}
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install System Dependencies
run: |-
sudo apt-get update
sudo apt install python3-dev
python -m pip install build wheel
- name: Install core repo
run: |
pip install build wheel
pip install .
- name: Install test dependencies
run: |
Expand All @@ -49,17 +45,8 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install System Dependencies
run: |-
sudo apt-get update
sudo apt install libfann-dev
- name: Install ovos dependencies
run: |-
pip install ovos-plugin-manager "ovos-core[skills_lgpl]>=0.0.5a28"
mkdir -p ~/.config/mycroft/
echo '{"language": {"detection_module": "libretranslate_plug"}}' > ~/.config/mycroft/mycroft.conf
- name: Run unittests
run: |
run: |-
pytest --cov=. --cov-report xml tests
- name: Upload coverage
env:
Expand Down
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.python-version
23 changes: 0 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ NOTE: this will automatically blacklist the official mycroft skill
* "Tell me a joke about dentists."
* "Do you know any Chuck Norris jokes?"

# 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


## Category
**Entertainment**

Expand Down
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
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pytest
pytest-cov
neon-lang-plugin-libretranslate~=0.2
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ovos_plugin_manager
ovos_workshop
ovos_utils
ovos_classifiers
pyjokes
ovos-translate-server-plugin
ovos-translate-server-plugin>=0.0.0a5
neon-lang-plugin-libretranslate
60 changes: 60 additions & 0 deletions skill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"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": [
"neon-lang-plugin-libretranslate",
"ovos-translate-server-plugin>=0.0.0a5",
"ovos_classifiers",
"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"
}
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