Skip to content

Commit

Permalink
Move Padatious and FANN to padatious extras with handling for unins…
Browse files Browse the repository at this point in the history
…talled dependency

Document Chatbot unit test usage
  • Loading branch information
NeonDaniel committed Dec 8, 2023
1 parent 063763b commit 28d9229
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The `minerva` entrypoint is available to interact with a bus via CLI.
Help is available via `minerva --help`.

## Installation
Since skill intents may use Padatious, the following system packages must be
If testing Padatious intents, the following system packages must be
installed before installing this package:
```shell
sudo apt install swig libfann-dev
Expand All @@ -17,6 +17,11 @@ To install this package from PyPI, simply run:
pip install neon-minerva
```

If testing with Padatious, install with the `padatious` extras:
```shell
pip install neon-minerva[padatious]
```

## Usage
This package provides a CLI for local testing of skills. Skills installed with
`pip` can be specified by entrypoint, or skills cloned locally can be specified
Expand Down Expand Up @@ -59,4 +64,31 @@ class MySkillTest(SkillTestCase):
```

Be sure to review the base class for mocked methods and test paths as these may
change in the future.
change in the future.

### Chatbot Unit Tests
`neon_minerva.chatbots` contains mocked data for testing as well as some utility
methods. `neon_minerva.tests.chatbot_v1_test_base` provides `TestSubmind` which
may be extended to test a submind bot in a mocked v1 environment. For example:

```python
from os import environ
from datetime import datetime
from chatbot_core.utils.enum import ConversationState

from neon_minerva.tests.chatbot_v1_test_base import TestSubmind
from neon_minerva.chatbots.test_constants import PROMPT, RESPONSES

environ["TEST_BOT_ENTRYPOINT"] = "tester"


class TestTester(TestSubmind):
def test_submind_chatbot(self):
self.submind.state = ConversationState.RESP
response = self.submind.ask_chatbot("testrunner", PROMPT,
datetime.now().strftime(
"%I:%M:%S %p"))
self.assertIsInstance(response, str)
self.assertIsNotNone(response)
```
> Make sure to install the `chatbots` extra to use this test case
2 changes: 1 addition & 1 deletion neon_minerva/intent_services/padatious.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from padatious import IntentContainer
from ovos_utils.log import LOG
from ovos_utils.messagebus import FakeBus

Expand All @@ -36,6 +35,7 @@

class PadatiousContainer:
def __init__(self, lang: str, cache_path: str, bus: FakeBus):
from padatious import IntentContainer
self.cache_dir = cache_path
self.lang = lang.lower()
self.bus = bus
Expand Down
13 changes: 12 additions & 1 deletion neon_minerva/tests/test_skill_intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ class TestSkillIntentMatching(unittest.TestCase):
if getenv("TEST_PADACIOSO") == "true":
container = PadaciosoContainer
else:
container = PadatiousContainer
try:
from padatious import IntentContainer
container = PadatiousContainer
except ImportError as e:
LOG.error(f"Padatious not installed. Install "
f"neon-minerva[padatious] to get Padatious requirements")
if getenv("TEST_PADACIOSO") is None:
# Ambiguous request, just use Padacioso
container = PadaciosoContainer
else:
# Explicitly requested Padatious/non-Padacioso
raise e
padatious_services = dict()
adapt_services = dict()
for lang in languages:
Expand Down
2 changes: 2 additions & 0 deletions requirements/padatious.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
padatious~=0.4.8
fann2==1.0.7
2 changes: 0 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ click~=8.0
click-default-group~=1.2
ovos-utils~=0.0.35
ovos-workshop~=0.0.12
fann2==1.0.7
padatious~=0.4.8
padacioso~=0.1
pyyaml>=5.4,<7.0
# PyYaml 5.4 support left for ovos-core 0.0.7 compat
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get_requirements(requirements_filename: str):
],
python_requires='>=3.6',
install_requires=get_requirements("requirements.txt"),
extras_require={"chatbots": get_requirements("chatbots.txt")},
extras_require={"chatbots": get_requirements("chatbots.txt"),
"padatious": get_requirements("padatious.txt")},
entry_points={
'console_scripts': ['minerva=neon_minerva.cli:neon_minerva_cli']
}
Expand Down

0 comments on commit 28d9229

Please sign in to comment.