-
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
1 parent
cb46630
commit 3ceb4a8
Showing
32 changed files
with
490 additions
and
253 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
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 |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import sys | ||
import logging | ||
import os | ||
import sys | ||
import time | ||
|
||
import pytest | ||
|
||
from tuxeatpi_common.cli import main_cli, set_daemon_class | ||
from tuxeatpi_common.cli import main_cli, set_daemon_class, cli | ||
from tuxeatpi_common.daemon import TepBaseDaemon | ||
from tuxeatpi_common.initializer import Initializer | ||
|
||
from click.testing import CliRunner | ||
|
||
|
||
class FakeDaemon(TepBaseDaemon): | ||
|
||
def __init__(self, name, workdir, intent_folder, dialog_folder, logging_level=logging.INFO): | ||
TepBaseDaemon.__init__(self, name, workdir, intent_folder, dialog_folder, logging_level) | ||
self._initializer = Initializer(self, True, True, True) | ||
|
||
def main_loop(self): | ||
self.shutdown() | ||
|
||
|
||
class TestCli(object): | ||
@pytest.mark.order1 | ||
def test_help(self, capsys): | ||
# Start | ||
daemon = True | ||
user = None | ||
group = None | ||
workdir = None | ||
pid_file = None | ||
|
||
# --help | ||
runner = CliRunner() | ||
set_daemon_class(TepBaseDaemon) | ||
set_daemon_class(FakeDaemon) | ||
result = runner.invoke(main_cli, ['--help']) | ||
|
||
assert 'Usage: ' in result.output | ||
assert result.exit_code == 0 | ||
|
||
@pytest.mark.order2 | ||
def test_status(self, capsys): | ||
# Status | ||
runner = CliRunner() | ||
set_daemon_class(TepBaseDaemon) | ||
result = runner.invoke(main_cli, ['status']) | ||
assert result.output == 'tepbasedaemon -- not running\n' | ||
assert result.exit_code == 1 | ||
|
||
@pytest.mark.order3 | ||
def test_stop(self, capsys): | ||
# Stop | ||
runner = CliRunner() | ||
set_daemon_class(TepBaseDaemon) | ||
result = runner.invoke(main_cli, ['stop']) | ||
assert result.output == 'WARNING: tepbasedaemon is not running\n' | ||
assert result.exit_code == 0 | ||
# Test cli with workdir | ||
sys.argv = ['fakedaemon', '-I', 'tests/cli_test/intents/', '-w', 'tests/cli_test/workdir/', '-D', 'tests/cli_test/dialogs'] | ||
with pytest.raises(SystemExit) as exp: | ||
cli(FakeDaemon) | ||
assert str(exp) == "Stop main loop" | ||
|
||
# Test cli without workdir | ||
sys.argv = ['fakedaemon', '-I', 'tests/cli_test/intents/', '-D', 'tests/cli_test/dialogs'] | ||
with pytest.raises(SystemExit) as exp: | ||
cli(FakeDaemon) | ||
assert str(exp) == "Stop main loop" |
Empty file.
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 @@ | ||
This is a rendering test {{ test }} |
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,2 @@ | ||
This is a test | ||
This is an other test |
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 @@ | ||
NLU test file |
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
Empty file.
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 @@ | ||
This is a rendering test {{ test }} |
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,2 @@ | ||
This is a test | ||
This is an other test |
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 @@ | ||
NLU test file |
Empty file.
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 @@ | ||
This is a rendering test {{ test }} |
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,2 @@ | ||
This is a test | ||
This is an other test |
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,34 @@ | ||
import sys | ||
import os | ||
import time | ||
import threading | ||
import logging | ||
|
||
import pytest | ||
|
||
from tuxeatpi_common.error import TuxEatPiError | ||
from tuxeatpi_common.dialogs import DialogsHandler | ||
|
||
|
||
class TestDialog(object): | ||
|
||
def test_dialog(self): | ||
# Create bad message | ||
dialogs_test = DialogsHandler("tests/dialogs", "test_dialog") | ||
dialogs_test.load() | ||
loaded_dialogs = {'en_US': {'render_test': {'This is a rendering test {{ test }}'}, | ||
'empty': set(), | ||
'test': {'This is a test', 'This is an other test'}}} | ||
assert dialogs_test._dialogs == loaded_dialogs | ||
|
||
dialog_rendered = dialogs_test.get_dialog("en_US", "render_test", test="mytest") | ||
assert dialog_rendered == "This is a rendering test mytest" | ||
|
||
dialog_rendered = dialogs_test.get_dialog("bad_lang", "render_test", test="mytest") | ||
assert dialog_rendered is None | ||
|
||
dialog_rendered = dialogs_test.get_dialog("en_US", "bad_key", test="mytest") | ||
assert dialog_rendered is None | ||
|
||
dialog_rendered = dialogs_test.get_dialog("en_US", "empty") | ||
assert dialog_rendered is None |
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,81 @@ | ||
import sys | ||
import os | ||
import time | ||
import threading | ||
import logging | ||
|
||
|
||
import pytest | ||
|
||
|
||
from tuxeatpi_common.error import TuxEatPiError | ||
from tuxeatpi_common.initializer import Initializer | ||
from tuxeatpi_common.daemon import TepBaseDaemon | ||
|
||
|
||
class FakeDaemon(TepBaseDaemon): | ||
|
||
def __init__(self, name, workdir, intent_folder, dialog_folder, logging_level=logging.INFO): | ||
TepBaseDaemon.__init__(self, name, workdir, intent_folder, dialog_folder, logging_level) | ||
self.args1 = None | ||
self.started = False | ||
|
||
def set_config(self, config): | ||
self.args1 = config.get("arg1") | ||
return True | ||
|
||
def main_loop(self): | ||
self.started = True | ||
time.sleep(1) | ||
|
||
|
||
class TestInit(object): | ||
|
||
@classmethod | ||
def setup_class(self): | ||
intents_folder = "tests/init/intents" | ||
dialogs_folder = "tests/init/dialogs" | ||
workdir = "tests/init/init" | ||
if not os.path.exists(intents_folder): | ||
os.makedirs(intents_folder) | ||
if not os.path.exists(dialogs_folder): | ||
os.makedirs(dialogs_folder) | ||
if not os.path.exists(workdir): | ||
os.makedirs(workdir) | ||
self.fake_daemon = FakeDaemon("fake_daemon", workdir, intents_folder, dialogs_folder) | ||
|
||
@classmethod | ||
def teardown_class(self): | ||
self.fake_daemon.shutdown() | ||
intents_folder = "tests/init/intents" | ||
dialogs_folder = "tests/init/dialogs" | ||
workdir = "tests/init/init" | ||
if os.path.exists(intents_folder): | ||
shutil.rmtree(intents_folder) | ||
if os.path.exists(dialogs_folder): | ||
shutil.rmtree(dialogs_folder) | ||
if os.path.exists(workdir): | ||
shutil.rmtree(workdir) | ||
|
||
@pytest.mark.skip | ||
def test_init(self): | ||
# Create bad message | ||
|
||
init_test = Initializer(selffake_daemon) | ||
init_test.run() | ||
|
||
|
||
|
||
assert dialog_test._dialogs == loaded_dialogs | ||
|
||
dialog_rendered = dialog_test.get_dialog("en_US", "render_test", test="mytest") | ||
assert dialog_rendered == "This is a rendering test mytest" | ||
|
||
dialog_rendered = dialog_test.get_dialog("bad_lang", "render_test", test="mytest") | ||
assert dialog_rendered is None | ||
|
||
dialog_rendered = dialog_test.get_dialog("en_US", "bad_key", test="mytest") | ||
assert dialog_rendered is None | ||
|
||
dialog_rendered = dialog_test.get_dialog("en_US", "empty") | ||
assert dialog_rendered is None |
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 @@ | ||
NLU test file |
Oops, something went wrong.