Skip to content

Commit

Permalink
Merge pull request #277 from OpenVoiceOS/release-0.3.1a2
Browse files Browse the repository at this point in the history
Release 0.3.1a2
  • Loading branch information
JarbasAl authored Oct 15, 2024
2 parents 9c7f9fa + cede398 commit 9da92e1
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 8 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Changelog

## [0.3.0a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.0a1) (2024-09-24)
## [0.3.1a2](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.1a2) (2024-10-15)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.2.1...0.3.0a1)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.1a1...0.3.1a2)

**Merged pull requests:**

- feat:prepare for other gui frameworks [\#270](https://github.com/OpenVoiceOS/ovos-utils/pull/270) ([JarbasAl](https://github.com/JarbasAl))
- support latest pyee [\#276](https://github.com/OpenVoiceOS/ovos-utils/pull/276) ([JarbasAl](https://github.com/JarbasAl))

## [0.3.1a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.1a1) (2024-10-15)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.0...0.3.1a1)

**Merged pull requests:**

- port/tests\_from\_core [\#274](https://github.com/OpenVoiceOS/ovos-utils/pull/274) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
4 changes: 2 additions & 2 deletions ovos_utils/fakebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from copy import deepcopy
from threading import Event

from pyee import BaseEventEmitter
from pyee import EventEmitter

from ovos_utils.log import LOG, log_deprecation

Expand All @@ -20,7 +20,7 @@ class FakeBus:
def __init__(self, *args, **kwargs):
self.started_running = False
self.session_id = "default"
self.ee = kwargs.get("emitter") or BaseEventEmitter()
self.ee = kwargs.get("emitter") or EventEmitter()
self.ee.on("error", self.on_error)
self.on_open()
try:
Expand Down
4 changes: 2 additions & 2 deletions ovos_utils/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 0
VERSION_MINOR = 3
VERSION_BUILD = 0
VERSION_ALPHA = 0
VERSION_BUILD = 1
VERSION_ALPHA = 2
# END_VERSION_BLOCK
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requests~=2.26
json_database~=0.7
kthread~=0.2
watchdog
pyee
pyee>=8.0.0
combo-lock~=0.2
rich-click~=1.7
rich~=13.7
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/unittests/dialog/multiple_dialogs/one.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ONE
1 change: 1 addition & 0 deletions test/unittests/dialog/multiple_dialogs/two.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TWO
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Chris",
"value": 10000,
"taxed_value": 6000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{name}}, You have just won {{value}} dollars! Well, {{taxed_value}} dollars, after taxes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello Chris, You have just won 10000 dollars! Well, 6000 dollars, after taxes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello there!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello there!
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a commented line
This is a line without comment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a line without comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Sherlock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello there {{name}}!
Another possible outcome, {{name}}
Oh, {{name}} look at the capabilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello there Sherlock!
Another possible outcome, Sherlock
Oh, Sherlock look at the capabilities
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello there!
Another possible outcome
Oh look at the capabilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello there!
Another possible outcome
Oh look at the capabilities
107 changes: 107 additions & 0 deletions test/unittests/dialog/test_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# Copyright 2017 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import unittest
import pathlib
import json


from ovos_utils.dialog import MustacheDialogRenderer, load_dialogs, get_dialog


# TODO - move to ovos-workshop
class DialogTest(unittest.TestCase):
def setUp(self):
self.stache = MustacheDialogRenderer()
self.topdir = pathlib.Path(__file__).parent

def test_general_dialog(self):
""" Test the loading and filling of valid simple mustache dialogs """
template_path = self.topdir.joinpath('./mustache_templates')
for file in template_path.iterdir():
if file.suffix == '.dialog':
self.stache.load_template_file(file.name, str(file.absolute()))
context = json.load(
file.with_suffix('.context.json').open(
'r', encoding='utf-8'))
self.assertEqual(
self.stache.render(file.name, context),
file.with_suffix('.result').open('r',
encoding='utf-8').read())

def test_unknown_dialog(self):
""" Test for returned file name literals in case of unkown dialog """
self.assertEqual(
self.stache.render("unknown.template"), "unknown template")

def test_multiple_dialog(self):
"""
Test the loading and filling of valid mustache dialogs
where a dialog file contains multiple text versions
"""
template_path = self.topdir.joinpath('./mustache_templates_multiple')
for file in template_path.iterdir():
if file.suffix == '.dialog':
self.stache.load_template_file(file.name, str(file.absolute()))
context = json.load(
file.with_suffix('.context.json').open(
'r', encoding='utf-8'))
results = [
line.strip() for line in file.with_suffix('.result').open(
'r', encoding='utf-8')
]
# Try all lines
for index, line in enumerate(results):
self.assertEqual(
self.stache.render(
file.name, index=index, context=context),
line.strip())
# Test random index function
# (bad test because non-deterministic?)
self.assertIn(
self.stache.render(file.name, context=context), results)

def test_comment_dialog(self):
"""
Test the loading and filling of valid mustache dialogs
where a dialog file contains multiple text versions
"""
template_path = self.topdir.joinpath('./mustache_templates_comments')
for f in template_path.iterdir():
if f.suffix == '.dialog':
self.stache.load_template_file(f.name, str(f.absolute()))
results = [line.strip()
for line in f.with_suffix('.result').open('r')]
# Try all lines
for index, line in enumerate(results):
self.assertEqual(self.stache.render(f.name, index=index),
line.strip())

def test_dialog_loader(self):
template_path = self.topdir.joinpath('./multiple_dialogs')
renderer = load_dialogs(template_path)
self.assertEqual(renderer.render('one'), 'ONE')
self.assertEqual(renderer.render('two'), 'TWO')

def test_dialog_loader_missing(self):
template_path = self.topdir.joinpath('./missing_dialogs')
renderer = load_dialogs(template_path)
self.assertEqual(renderer.render('test'), 'test')




if __name__ == "__main__":
unittest.main()
68 changes: 68 additions & 0 deletions test/unittests/test_event_container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import unittest
from unittest import mock
from ovos_utils.events import EventContainer


def example_handler(message):
pass


class TestEventContainer(unittest.TestCase):
def test_init(self):
bus = mock.MagicMock()

# Set bus via init
container = EventContainer(bus)
self.assertEqual(container.bus, bus)

# Set bus using .set_bus
container = EventContainer(None)
self.assertIsNotNone(container.bus)
container.set_bus(bus)
self.assertEqual(container.bus, bus)

def test_add(self):
bus = mock.MagicMock()
container = EventContainer(bus)
self.assertEqual(len(container.events), 0)

# Test add normal event handler
container.add('test1', example_handler)
self.assertTrue(bus.on.called)

# Test add single shot event handler
len_before = len(container.events)
container.add('test2', example_handler, once=True)
self.assertEqual(len_before + 1, len(container.events))
self.assertTrue(bus.once.called)

# Verify correct content in event container
self.assertTrue(('test1', example_handler) in container.events)
self.assertEqual(len(container.events), 2)

def test_remove(self):
bus = mock.MagicMock()
container = EventContainer(bus)
self.assertEqual(len(container.events), 0)

container.add('test1', example_handler)
container.add('test2', example_handler)
container.add('test3', example_handler)
self.assertEqual(len(container.events), 3)

self.assertTrue(('test2', example_handler) in container.events)
container.remove('test2')
self.assertTrue(('test2', example_handler) not in container.events)
self.assertTrue(bus.remove_all_listeners.called)

def test_clear(self):
bus = mock.MagicMock()
container = EventContainer(bus)

container.add('test1', example_handler)
container.add('test2', example_handler)
container.add('test3', example_handler)
self.assertEqual(len(container.events), 3)

container.clear()
self.assertEqual(len(container.events), 0)
Loading

0 comments on commit 9da92e1

Please sign in to comment.