-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" # See documentation for possible values | ||
directory: "/requirements" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Run UnitTests | ||
on: | ||
pull_request: | ||
branches: | ||
- dev | ||
paths-ignore: | ||
- "ovos_utterance_corrections_transformer/version.py" | ||
- "examples/**" | ||
- ".github/**" | ||
- ".gitignore" | ||
- "LICENSE" | ||
- "CHANGELOG.md" | ||
- "MANIFEST.in" | ||
- "README.md" | ||
- "scripts/**" | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "ovos_utterance_corrections_transformer/version.py" | ||
- "requirements/**" | ||
- "examples/**" | ||
- ".github/**" | ||
- ".gitignore" | ||
- "LICENSE" | ||
- "CHANGELOG.md" | ||
- "MANIFEST.in" | ||
- "README.md" | ||
- "scripts/**" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
unit_tests: | ||
strategy: | ||
max-parallel: 2 | ||
matrix: | ||
python-version: [3.8, 3.9, "3.10", "3.11"] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "pip" | ||
- name: Install System Dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt install python3-dev swig libssl-dev | ||
python -m pip install build wheel | ||
- name: Install core repo | ||
run: | | ||
pip install . | ||
- name: Install test dependencies | ||
run: | | ||
pip install -r tests/requirements.txt | ||
- name: Run unittests | ||
run: | | ||
pytest --cov=ovos_utterance_corrections_transformer --cov-report xml tests | ||
# NOTE: additional pytest invocations should also add the --cov-append flag | ||
# or they will overwrite previous invocations' coverage reports | ||
# (for an example, see OVOS Skill Manager's workflow) | ||
- name: Upload coverage | ||
env: | ||
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} | ||
uses: codecov/codecov-action@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ovos-plugin-manager>=0.0.1,<1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coveralls==1.8.2 | ||
flake8==3.7.9 | ||
pytest==8.2.2 | ||
pytest-cov==2.8.1 | ||
cov-core==1.15.0 | ||
ovos-plugin-manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from ovos_utterance_corrections_transformer import UtteranceCorrectionsPlugin | ||
|
||
|
||
class TestUtteranceCorrectionsPlugin(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.plugin = UtteranceCorrectionsPlugin() | ||
|
||
def test_transform_full_utterance_replacement(self): | ||
# Mock the match_one function | ||
self.plugin.config = {"thresh": 0.85} # Set threshold for replacement | ||
self.plugin.db = {"test utterance": "replaced utterance"} | ||
|
||
# Test input | ||
utterances = ["test utterance"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["replaced utterance"]) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_regex_no_match(self): | ||
# Mock the regex_db with a pattern that won't match | ||
self.plugin.config = {"ignore_case": True} | ||
self.plugin.regex_db = { | ||
r"\bsh(\w*)": "sch\\1" | ||
} | ||
|
||
# Test input with no match | ||
utterances = ["hello"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["hello"]) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_regex_replacement(self): | ||
# Mock the regex_db with a valid pattern and replacement | ||
self.plugin.config = {"ignore_case": True} | ||
self.plugin.regex_db = { | ||
r"\bsh(\w*)": "sch\\1" | ||
} | ||
|
||
# Test input with matching regex pattern | ||
utterances = ["shalter"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["schalter"]) | ||
self.assertEqual(context, {}) | ||
|
||
@patch("ovos_utterance_corrections_transformer.regex.compile") # Mock regex compile | ||
def test_transform_regex_timeout(self, MockRegexCompile): | ||
# Mock the regex_db with a valid pattern and replacement | ||
self.plugin.config = {"ignore_case": True} | ||
self.plugin.regex_db = { | ||
r"\bsh(\w*)": "sch\\1" | ||
} | ||
|
||
# Mock regex to raise a TimeoutError | ||
MockRegexCompile.side_effect = TimeoutError("Regex pattern timed out") | ||
|
||
# Test input with matching regex pattern | ||
utterances = ["shalter"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions - no change because of timeout | ||
self.assertEqual(transformed, ["shalter"]) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_oversized_regex_pattern(self): | ||
# Mock the regex_db with a large pattern that exceeds the size limit | ||
self.plugin.config = {"ignore_case": True} | ||
self.plugin.regex_db = { | ||
"a" * 1001: "replaced" # Pattern longer than 1000 characters | ||
} | ||
|
||
# Test input | ||
utterances = ["this is a test"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["this is a test"]) # No change due to oversized pattern | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_word_replacement(self): | ||
# Mock the words_db with a valid word and replacement | ||
self.plugin.words_db = {"test": "exam"} | ||
|
||
# Test input with word replacement | ||
utterances = ["this is a test"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["this is a exam"]) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_multiple_replacements(self): | ||
# Mock the words_db with multiple words and replacements | ||
self.plugin.words_db = {"test": "exam", "hello": "hi"} | ||
|
||
# Test input with multiple word replacements | ||
utterances = ["hello, this is a test"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["hi, this is a exam"]) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_empty_input(self): | ||
# Test with empty input | ||
utterances = [] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, []) | ||
self.assertEqual(context, {}) | ||
|
||
def test_transform_no_match(self): | ||
# Test input with no matching patterns | ||
self.plugin.regex_db = { | ||
r"\bxyz(\w*)": "abc\\1" | ||
} | ||
|
||
utterances = ["test"] | ||
transformed, context = self.plugin.transform(utterances) | ||
|
||
# Assertions | ||
self.assertEqual(transformed, ["test"]) | ||
self.assertEqual(context, {}) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |