Skip to content

Commit

Permalink
Configuration module tests with bug fixes (#170)
Browse files Browse the repository at this point in the history
* Add configuration module tests with automation
Patch ovos_utils method to use proper config

* Fix automation file formatting bug

* Update neon-utils dependency version

* Update neon-utils dependency version

* Clear cached config after writing neon changes

* Reorg to troubleshoot config issues

* Troubleshoot config issues, append .conf to ovos_utils call

* Bump ovos_utils and cleanup patches
Reorg config tests to resolve config caching errors

* Update neon_utils to release version
  • Loading branch information
NeonDaniel authored Nov 12, 2021
1 parent 455b908 commit d0cb6c6
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,28 @@ jobs:
GITHUB_TOKEN: ${{secrets.neon_token}}
- name: Test Language
run: |
pytest test/test_language.py
pytest test/test_language.py
unit_tests:
strategy:
matrix:
python-version: [ 3.6, 3.7, 3.8 ]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y gcc libfann-dev swig libssl-dev portaudio19-dev git libpulse-dev
pip install -r requirements/requirements.txt
pip install -r requirements/test.txt
env:
GITHUB_TOKEN: ${{secrets.neon_token}}
- name: Test Configuration Module
run: |
pytest test/test_configuration.py
11 changes: 9 additions & 2 deletions neon_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
from os.path import join, dirname
import xdg.BaseDirectory
import json

from ovos_utils.json_helper import merge_dict
from ovos_utils.system import set_root_path
from ovos_utils.configuration import set_config_name

from neon_utils import LOG
from neon_utils.configuration_utils import write_mycroft_compatible_config

NEON_ROOT_PATH = dirname(dirname(__file__))

Expand Down Expand Up @@ -85,7 +85,7 @@ def setup_ovos_config():
# ensure ovos_utils can find neon_core
set_root_path(NEON_ROOT_PATH)
# make ovos_utils load the proper .conf files
set_config_name("neon", "neon_core")
set_config_name("neon.conf", "neon_core")


setup_ovos_config()
Expand All @@ -96,9 +96,16 @@ def setup_ovos_config():
# for now it simply provides correct default values
setup_ovos_core_config()

from neon_utils.configuration_utils import write_mycroft_compatible_config

# Write and reload Mycroft-compat conf file
neon_config_path = join(xdg.BaseDirectory.save_config_path("neon"),
"neon.conf")
write_mycroft_compatible_config(neon_config_path)
from neon_core.configuration import Configuration
Configuration.load_config_stack(cache=True, remote=False)


# TODO: Consider when this log is valid/config is changed or not already synced with neon_config DM
LOG.info(f"{neon_config_path} will be overwritten with Neon YAML config contents.")

Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ neon_audio~=0.4
neon_enclosure~=0.1,>=0.1.2

# utils
neon-utils>=0.12.0
neon-utils>=0.12.6
rapidfuzz
kthread
ovos_utils>=0.0.12a3
ovos_utils>=0.0.12
ovos-skills-manager>=0.0.2

# plugins
Expand Down
73 changes: 73 additions & 0 deletions test/test_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# # NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System
# # All trademark and other rights reserved by their respective owners
# # Copyright 2008-2021 Neongecko.com Inc.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import shutil
import sys
import unittest

from ovos_plugin_manager.templates.language import LanguageDetector, LanguageTranslator

from neon_utils.configuration_utils import get_mycroft_compatible_config

sys.path.append(os.path.dirname(os.path.dirname(__file__)))


class ConfigurationTests(unittest.TestCase):
def test_neon_core_config_init(self):
from neon_core.configuration import Configuration
neon_compat_config = Configuration.get()
neon_config = get_mycroft_compatible_config()
for key, val in neon_config.items():
if isinstance(val, dict):
for k, v in val.items():
if not isinstance(v, dict):
self.assertEqual(neon_compat_config[key][k], v, neon_compat_config[key])
else:
self.assertEqual(neon_compat_config[key], val)

def test_ovos_core_config_init(self):
from mycroft.configuration import Configuration as MycroftConfig
mycroft_config = MycroftConfig.get()
neon_config = get_mycroft_compatible_config()
for key, val in neon_config.items():
if isinstance(val, dict):
for k, v in val.items():
if not isinstance(v, dict):
self.assertEqual(mycroft_config[key][k], v, mycroft_config[key])
else:
self.assertEqual(mycroft_config[key], val)

def test_signal_dir(self):
from neon_utils.skill_override_functions import IPC_DIR as neon_ipc_dir
from ovos_utils.signal import get_ipc_directory as ovos_ipc_dir
from mycroft.util.signal import get_ipc_directory as mycroft_ipc_dir

self.assertEqual(neon_ipc_dir, ovos_ipc_dir())
self.assertEqual(neon_ipc_dir, mycroft_ipc_dir())


if __name__ == '__main__':
unittest.main()

0 comments on commit d0cb6c6

Please sign in to comment.