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

unitests/converse #359

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
pip install ./test/end2end/session/skill-ovos-hello-world
pip install ./test/end2end/session/skill-ovos-fallback-unknown
pip install ./test/end2end/session/skill-ovos-fallback-unknownv1
pip install ./test/end2end/session/skill-converse_test
- name: Run unittests
run: |
pytest --cov=ovos_core --cov-report xml test/unittests
Expand All @@ -76,9 +77,17 @@ jobs:
pip install .[lgpl]
- name: Run unittests with padatious
run: |
pytest --cov=ovos_core --cov-report xml test/unittests/skills
pytest --cov-append --cov=ovos_core --cov-report xml test/unittests/skills
- name: Upload coverage
if: "${{ matrix.python-version == '3.9' }}"
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/reports/
fail_ci_if_error: true
files: ./coverage.xml,!./cache
flags: unittests
name: codecov-umbrella
verbose: true
5 changes: 4 additions & 1 deletion test/end2end/session/minicroft.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def stop(self):


def get_minicroft(skill_id):
croft1 = MiniCroft([skill_id])
if isinstance(skill_id, str):
skill_id = [skill_id]
assert isinstance(skill_id, list)
croft1 = MiniCroft(skill_id)
croft1.start()
while croft1.status.state != ProcessState.READY:
sleep(0.2)
Expand Down
71 changes: 71 additions & 0 deletions test/end2end/session/skill-converse_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from ovos_workshop.decorators import killable_intent
from ovos_workshop.skills.ovos import OVOSSkill
from mycroft.skills import intent_file_handler
from time import sleep


class TestAbortSkill(OVOSSkill):
"""
send "mycroft.skills.abort_question" and confirm only get_response is aborted
send "mycroft.skills.abort_execution" and confirm the full intent is aborted, except intent3
send "my.own.abort.msg" and confirm intent3 is aborted
say "stop" and confirm all intents are aborted
"""
def initialize(self):
self.stop_called = False
self._converse = False
self.add_event(f"{self.skill_id}.converse_enable", self.handle_converse_on)
self.add_event(f"{self.skill_id}.converse_disable", self.handle_converse_off)

@intent_file_handler("converse_on.intent")
def handle_converse_on(self, message):
self._converse = True
self.speak("on")

@intent_file_handler("converse_off.intent")
def handle_converse_off(self, message):
self._converse = False
self.speak("off")

def handle_intent_aborted(self):
self.speak("I am dead")

@intent_file_handler("test_get_response.intent")
def handle_test_get_response(self, message):
ans = self.get_response("get")
self.speak(ans)

@killable_intent(callback=handle_intent_aborted)
@intent_file_handler("test.intent")
def handle_test_abort_intent(self, message):
self.stop_called = False
self.my_special_var = "changed"
while True:
sleep(1)
self.speak("still here")

@intent_file_handler("test2.intent")
@killable_intent(callback=handle_intent_aborted)
def handle_test_get_response_intent(self, message):
self.stop_called = False
self.my_special_var = "CHANGED"
ans = self.get_response("question", num_retries=99999)
self.log.debug("get_response returned: " + str(ans))
if ans is None:
self.speak("question aborted")

@killable_intent(msg="my.own.abort.msg", callback=handle_intent_aborted)
@intent_file_handler("test3.intent")
def handle_test_msg_intent(self, message):
self.stop_called = False
if self.my_special_var != "default":
self.speak("someone forgot to cleanup")
while True:
sleep(1)
self.speak("you can't abort me")

def stop(self):
self.stop_called = True

def converse(self, message):
return self._converse
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
give me an answer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a question
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test again
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
one more test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test get response
39 changes: 39 additions & 0 deletions test/end2end/session/skill-converse_test/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
from setuptools import setup
from os import getenv, path, walk


def find_resource_files():
resource_base_dirs = ("locale", "ui", "vocab", "dialog", "regex")
base_dir = path.dirname(__file__)
package_data = ["skill.json"]
for res in resource_base_dirs:
if path.isdir(path.join(base_dir, res)):
for (directory, _, files) in walk(path.join(base_dir, res)):
if files:
package_data.append(
path.join(directory.replace(base_dir, "").lstrip('/'),
'*'))
return package_data


# skill_id=package_name:SkillClass
PLUGIN_ENTRY_POINT = 'ovos-tskill-abort.openvoiceos=ovos_tskill_abort:TestAbortSkill'

setup(
# this is the package name that goes on pip
name='ovos-tskill-abort',
version='0.0.1',
description='this is a OVOS test skill for the killable_intents decorator',
url='https://github.com/OpenVoiceOS/skill-abort-test',
author='JarbasAi',
author_email='[email protected]',
license='Apache-2.0',
package_dir={"ovos_tskill_abort": ""},
package_data={'ovos_tskill_abort': find_resource_files()},
packages=['ovos_tskill_abort'],
include_package_data=True,
install_requires=["ovos-workshop"],
keywords='ovos skill plugin',
entry_points={'ovos.plugin.skill': PLUGIN_ENTRY_POINT}
)
Loading
Loading