mirror of
https://github.com/thevickypedia/Jarvis.git
synced 2023-09-11 12:43:25 +03:00
Fix broken unit test trigger by `pre-commit`
Add more tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
venv
|
||||
|
||||
# module generated
|
||||
|
||||
@@ -25,7 +25,7 @@ repos:
|
||||
-
|
||||
id: pytest
|
||||
name: pytest
|
||||
entry: cd tests pytest
|
||||
entry: bash -c 'cd tests && pytest && rm -rf logs fileio .pytest_cache && cd ..'
|
||||
language: system
|
||||
pass_filenames: false
|
||||
always_run: true
|
||||
|
||||
@@ -914,6 +914,44 @@ WakeOnLAN
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
----------Test Cases----------
|
||||
==============================
|
||||
|
||||
TestAPI
|
||||
=======
|
||||
|
||||
.. automodule:: tests.test_api
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestListener
|
||||
============
|
||||
|
||||
.. automodule:: tests.test_listener
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestMain
|
||||
========
|
||||
|
||||
.. automodule:: tests.test_main
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestSpeaker
|
||||
===========
|
||||
|
||||
.. automodule:: tests.test_speaker
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestSpeechSynthesis
|
||||
===================
|
||||
|
||||
.. automodule:: tests.test_speech_synthesis
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
|
||||
@@ -2272,6 +2272,16 @@
|
||||
<li><a href="index.html#module-jarvis.modules.utils.util">jarvis.modules.utils.util</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-jarvis.modules.wakeonlan.wakeonlan">jarvis.modules.wakeonlan.wakeonlan</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-tests.test_api">tests.test_api</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-tests.test_listener">tests.test_listener</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-tests.test_main">tests.test_main</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-tests.test_speaker">tests.test_speaker</a>
|
||||
</li>
|
||||
<li><a href="index.html#module-tests.test_speech_synthesis">tests.test_speech_synthesis</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
@@ -2725,6 +2735,8 @@
|
||||
</li>
|
||||
</ul></li>
|
||||
<li><a href="index.html#jarvis.executors.controls.sentry">sentry() (in module jarvis.executors.controls)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_api.server">server() (in module tests.test_api)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.tv.roku.RokuECP.SESSION">SESSION (jarvis.modules.tv.roku.RokuECP attribute)</a>
|
||||
</li>
|
||||
@@ -2768,6 +2780,8 @@
|
||||
<li><a href="index.html#jarvis.modules.models.classes.Settings">(class in jarvis.modules.models.classes)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li><a href="index.html#tests.test_main.TestActivator.setUp">setUp() (tests.test_main.TestActivator method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.executors.controls.shutdown">shutdown() (in module jarvis.executors.controls)</a>
|
||||
|
||||
<ul>
|
||||
@@ -2795,11 +2809,11 @@
|
||||
<li><a href="index.html#jarvis.modules.speaker.speak.Speaker.speak_english_voices">speak_english_voices() (jarvis.modules.speaker.speak.Speaker method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.speaker.speak.Speaker">Speaker (class in jarvis.modules.speaker.speak)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.models.classes.EnvConfig.speaker_index">speaker_index (jarvis.modules.models.classes.EnvConfig attribute)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="index.html#jarvis.modules.models.classes.EnvConfig.speaker_index">speaker_index (jarvis.modules.models.classes.EnvConfig attribute)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.executors.volume.speaker_volume">speaker_volume() (in module jarvis.executors.volume)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.models.classes.EnvConfig.speech_rate">speech_rate (jarvis.modules.models.classes.EnvConfig attribute)</a>
|
||||
@@ -2941,12 +2955,81 @@
|
||||
<li><a href="index.html#jarvis.modules.models.classes.EnvConfig.temperature_unit">temperature_unit (jarvis.modules.models.classes.EnvConfig attribute)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.executors.controls.terminator">terminator() (in module jarvis.executors.controls)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak.test_audio_driver_usage">test_audio_driver_usage() (tests.test_speaker.TestSpeak method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.api.squire.surveillance_squire.test_camera">test_camera() (in module jarvis.api.squire.surveillance_squire)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer.test_egress_error_handling">test_egress_error_handling() (tests.test_speech_synthesis.TestSpeechSynthesizer method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_main.TestActivator.test_executor">test_executor() (tests.test_main.TestActivator method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_main.TestActivator.test_init_activator">test_init_activator() (tests.test_main.TestActivator method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_listener.TestListener.test_listen">test_listen() (tests.test_listener.TestListener method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.logger.custom_logger.TestLogger.test_log">test_log() (jarvis.modules.logger.custom_logger.TestLogger method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak.test_no_text_input">test_no_text_input() (tests.test_speaker.TestSpeak method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak.test_offline_mode">test_offline_mode() (tests.test_speaker.TestSpeak method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak.test_speech_synthesis_usage">test_speech_synthesis_usage() (tests.test_speaker.TestSpeak method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer.test_successful_synthesis">test_successful_synthesis() (tests.test_speech_synthesis.TestSpeechSynthesizer method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak.test_text_input_and_run">test_text_input_and_run() (tests.test_speaker.TestSpeak method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer.test_unicode_error_handling">test_unicode_error_handling() (tests.test_speech_synthesis.TestSpeechSynthesizer method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer.test_unsuccessful_synthesis">test_unsuccessful_synthesis() (tests.test_speech_synthesis.TestSpeechSynthesizer method)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_main.TestActivator">TestActivator (class in tests.test_main)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_listener.TestListener">TestListener (class in tests.test_listener)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.modules.logger.custom_logger.TestLogger">TestLogger (class in jarvis.modules.logger.custom_logger)</a>
|
||||
</li>
|
||||
<li>
|
||||
tests.test_api
|
||||
|
||||
<ul>
|
||||
<li><a href="index.html#module-tests.test_api">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li>
|
||||
tests.test_listener
|
||||
|
||||
<ul>
|
||||
<li><a href="index.html#module-tests.test_listener">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li>
|
||||
tests.test_main
|
||||
|
||||
<ul>
|
||||
<li><a href="index.html#module-tests.test_main">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li>
|
||||
tests.test_speaker
|
||||
|
||||
<ul>
|
||||
<li><a href="index.html#module-tests.test_speaker">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li>
|
||||
tests.test_speech_synthesis
|
||||
|
||||
<ul>
|
||||
<li><a href="index.html#module-tests.test_speech_synthesis">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="index.html#tests.test_speaker.TestSpeak">TestSpeak (class in tests.test_speaker)</a>
|
||||
</li>
|
||||
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer">TestSpeechSynthesizer (class in tests.test_speech_synthesis)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.api.models.modals.SpeechSynthesisModal.text">text (jarvis.api.models.modals.SpeechSynthesisModal attribute)</a>
|
||||
</li>
|
||||
@@ -2970,8 +3053,6 @@
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.executors.others.time_travel">time_travel() (in module jarvis.executors.others)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="index.html#jarvis.executors.commander.timed_delay">timed_delay() (in module jarvis.executors.commander)</a>
|
||||
</li>
|
||||
<li><a href="index.html#jarvis.api.models.modals.SpeechSynthesisModal.timeout">timeout (jarvis.api.models.modals.SpeechSynthesisModal attribute)</a>
|
||||
|
||||
247
docs/index.html
247
docs/index.html
@@ -10699,6 +10699,247 @@ mac address given as a parameter.</p>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="test-cases">
|
||||
<h1>———-Test Cases———-<a class="headerlink" href="#test-cases" title="Permalink to this heading">¶</a></h1>
|
||||
</section>
|
||||
<section id="module-tests.test_api">
|
||||
<span id="testapi"></span><h1>TestAPI<a class="headerlink" href="#module-tests.test_api" title="Permalink to this heading">¶</a></h1>
|
||||
<dl class="py function">
|
||||
<dt class="sig sig-object py" id="tests.test_api.server">
|
||||
<span class="sig-prename descclassname"><span class="pre">tests.test_api.</span></span><span class="sig-name descname"><span class="pre">server</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_api.server" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Run pytest on APIServer which runs in a thread.</p>
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="module-tests.test_listener">
|
||||
<span id="testlistener"></span><h1>TestListener<a class="headerlink" href="#module-tests.test_listener" title="Permalink to this heading">¶</a></h1>
|
||||
<dl class="py class">
|
||||
<dt class="sig sig-object py" id="tests.test_listener.TestListener">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tests.test_listener.</span></span><span class="sig-name descname"><span class="pre">TestListener</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">methodName</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'runTest'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_listener.TestListener" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>TestCase object for testing listener module.</p>
|
||||
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">TestListener</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Create an instance of the class that will use the named test
|
||||
method when executed. Raises a ValueError if the instance does
|
||||
not have a method with the specified name.</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_listener.TestListener.test_listen">
|
||||
<span class="sig-name descname"><span class="pre">test_listen</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_support</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_playsound</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_recognizer</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_microphone</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_listener.TestListener.test_listen" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test the listen function.</p>
|
||||
<p>Mock the return values and set up necessary mocks to simulate the behavior of the listen function.
|
||||
Ensure that the listen function is called with the correct arguments.
|
||||
Ensure that the playsound function is not called when sound=False is passed.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_support</strong> – Mocked support module.</p></li>
|
||||
<li><p><strong>mock_playsound</strong> – Mocked playsound function.</p></li>
|
||||
<li><p><strong>mock_recognizer</strong> – Mocked recognizer module.</p></li>
|
||||
<li><p><strong>mock_microphone</strong> – Mocked microphone module.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="module-tests.test_main">
|
||||
<span id="testmain"></span><h1>TestMain<a class="headerlink" href="#module-tests.test_main" title="Permalink to this heading">¶</a></h1>
|
||||
<dl class="py class">
|
||||
<dt class="sig sig-object py" id="tests.test_main.TestActivator">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tests.test_main.</span></span><span class="sig-name descname"><span class="pre">TestActivator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">methodName</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'runTest'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_main.TestActivator" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test cases for the Activator class.</p>
|
||||
<p>Create an instance of the class that will use the named test
|
||||
method when executed. Raises a ValueError if the instance does
|
||||
not have a method with the specified name.</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_main.TestActivator.setUp">
|
||||
<span class="sig-name descname"><span class="pre">setUp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_main.TestActivator.setUp" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Set up the Activator instance for testing.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_main.TestActivator.test_init_activator">
|
||||
<span class="sig-name descname"><span class="pre">test_init_activator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_audio_open</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_pvporcupine_create</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_main.TestActivator.test_init_activator" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test whether the Activator is initialized correctly.</p>
|
||||
<p>Mock the return values of the create function.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_audio_open</strong> – Patched audio_engine.open from jarvis.main.py.</p></li>
|
||||
<li><p><strong>mock_pvporcupine_create</strong> – Patched pvporcupine.create from jarvis.main.py.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_main.TestActivator.test_executor">
|
||||
<span class="sig-name descname"><span class="pre">test_executor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_audio_close</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_speak</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_initiator</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_listen</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_main.TestActivator.test_executor" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test the executor method of Activator.</p>
|
||||
<p>Mock return values of the listen function and set up necessary mocks.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_audio_close</strong> – Patched audio_engine.close from jarvis.main.py.</p></li>
|
||||
<li><p><strong>mock_speak</strong> – Patched <code class="docutils literal notranslate"><span class="pre">speaker.speak</span></code> from jarvis.modules.audio.</p></li>
|
||||
<li><p><strong>mock_initiator</strong> – Patched <code class="docutils literal notranslate"><span class="pre">commander.initiator</span></code> from jarvis.executors.</p></li>
|
||||
<li><p><strong>mock_listen</strong> – Patched <code class="docutils literal notranslate"><span class="pre">listener.listen</span></code> from jarvis.modules.audio.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="module-tests.test_speaker">
|
||||
<span id="testspeaker"></span><h1>TestSpeaker<a class="headerlink" href="#module-tests.test_speaker" title="Permalink to this heading">¶</a></h1>
|
||||
<dl class="py class">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tests.test_speaker.</span></span><span class="sig-name descname"><span class="pre">TestSpeak</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">methodName</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'runTest'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_speaker.TestSpeak" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>TestCase object for testing the speaker module.</p>
|
||||
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">TestSpeak</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Create an instance of the class that will use the named test
|
||||
method when executed. Raises a ValueError if the instance does
|
||||
not have a method with the specified name.</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak.test_speech_synthesis_usage">
|
||||
<span class="sig-name descname"><span class="pre">test_speech_synthesis_usage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_playsound</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_speech_synthesizer</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speaker.TestSpeak.test_speech_synthesis_usage" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test speech synthesis usage.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_playsound</strong> – Mock object for playsound module.</p></li>
|
||||
<li><p><strong>mock_speech_synthesizer</strong> – Mock object for speaker.speech_synthesizer function.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak.test_audio_driver_usage">
|
||||
<span class="sig-name descname"><span class="pre">test_audio_driver_usage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_playsound</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_speaker</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_speech_synthesizer</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speaker.TestSpeak.test_audio_driver_usage" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test audio driver usage.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_playsound</strong> – Mock object for playsound module.</p></li>
|
||||
<li><p><strong>mock_speaker</strong> – Mock object for <code class="docutils literal notranslate"><span class="pre">speaker.speak</span></code> function.</p></li>
|
||||
<li><p><strong>mock_speech_synthesizer</strong> – Mock object for speaker.speech_synthesizer function.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak.test_no_text_input">
|
||||
<span class="sig-name descname"><span class="pre">test_no_text_input</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_write_screen</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speaker.TestSpeak.test_no_text_input" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test speak function with no text input.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_write_screen</strong> – Mock object for support.write_screen function.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak.test_text_input_and_run">
|
||||
<span class="sig-name descname"><span class="pre">test_text_input_and_run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_write_screen</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speaker.TestSpeak.test_text_input_and_run" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test speak function with text input and run flag.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_write_screen</strong> – Mock object for support.write_screen function.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speaker.TestSpeak.test_offline_mode">
|
||||
<span class="sig-name descname"><span class="pre">test_offline_mode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_playsound</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mock_speech_synthesizer</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speaker.TestSpeak.test_offline_mode" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test speak function in offline mode.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>mock_playsound</strong> – Mock object for playsound module.</p></li>
|
||||
<li><p><strong>mock_speech_synthesizer</strong> – Mock object for speaker.speech_synthesizer function.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="module-tests.test_speech_synthesis">
|
||||
<span id="testspeechsynthesis"></span><h1>TestSpeechSynthesis<a class="headerlink" href="#module-tests.test_speech_synthesis" title="Permalink to this heading">¶</a></h1>
|
||||
<dl class="py class">
|
||||
<dt class="sig sig-object py" id="tests.test_speech_synthesis.TestSpeechSynthesizer">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tests.test_speech_synthesis.</span></span><span class="sig-name descname"><span class="pre">TestSpeechSynthesizer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">methodName</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'runTest'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tests.test_speech_synthesis.TestSpeechSynthesizer" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>TestSpeechSynthesizer object for testing speech synthesis module.</p>
|
||||
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">TestSpeechSynthesizer</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Create an instance of the class that will use the named test
|
||||
method when executed. Raises a ValueError if the instance does
|
||||
not have a method with the specified name.</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speech_synthesis.TestSpeechSynthesizer.test_successful_synthesis">
|
||||
<span class="sig-name descname"><span class="pre">test_successful_synthesis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_post</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speech_synthesis.TestSpeechSynthesizer.test_successful_synthesis" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test successful speech synthesis.</p>
|
||||
<p>This method tests the behavior of the speech_synthesizer function when a successful
|
||||
response is mocked from the post request call.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_post</strong> – Mock of the <code class="docutils literal notranslate"><span class="pre">requests.post</span></code> function.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speech_synthesis.TestSpeechSynthesizer.test_unsuccessful_synthesis">
|
||||
<span class="sig-name descname"><span class="pre">test_unsuccessful_synthesis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_post</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speech_synthesis.TestSpeechSynthesizer.test_unsuccessful_synthesis" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test unsuccessful speech synthesis.</p>
|
||||
<p>This method tests the behavior of the speech_synthesizer function when an unsuccessful
|
||||
response is mocked from the post request call.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_post</strong> – Mock of the <code class="docutils literal notranslate"><span class="pre">requests.post</span></code> function.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speech_synthesis.TestSpeechSynthesizer.test_unicode_error_handling">
|
||||
<span class="sig-name descname"><span class="pre">test_unicode_error_handling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_post</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speech_synthesis.TestSpeechSynthesizer.test_unicode_error_handling" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test UnicodeError handling in speech synthesis.</p>
|
||||
<p>This method tests the handling of UnicodeError within the speech_synthesizer function.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_post</strong> – Mock of the <code class="docutils literal notranslate"><span class="pre">requests.post</span></code> function with side effect.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="tests.test_speech_synthesis.TestSpeechSynthesizer.test_egress_error_handling">
|
||||
<span class="sig-name descname"><span class="pre">test_egress_error_handling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mock_post</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">MagicMock</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">NoReturn</span></span></span><a class="headerlink" href="#tests.test_speech_synthesis.TestSpeechSynthesizer.test_egress_error_handling" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Test EgressErrors handling in speech synthesis.</p>
|
||||
<p>This method tests the handling of EgressErrors within the speech_synthesizer function.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
<dd class="field-odd"><p><strong>mock_post</strong> – Mock of the <code class="docutils literal notranslate"><span class="pre">requests.post</span></code> function with side effect.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
<section id="indices-and-tables">
|
||||
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this heading">¶</a></h1>
|
||||
@@ -10828,6 +11069,12 @@ mac address given as a parameter.</p>
|
||||
<li><a class="reference internal" href="#module-jarvis.modules.transformer.gpt">Transformer</a></li>
|
||||
<li><a class="reference internal" href="#module-jarvis.modules.tv.lg">TV Connector</a></li>
|
||||
<li><a class="reference internal" href="#module-jarvis.modules.wakeonlan.wakeonlan">WakeOnLAN</a></li>
|
||||
<li><a class="reference internal" href="#test-cases">———-Test Cases———-</a></li>
|
||||
<li><a class="reference internal" href="#module-tests.test_api">TestAPI</a></li>
|
||||
<li><a class="reference internal" href="#module-tests.test_listener">TestListener</a></li>
|
||||
<li><a class="reference internal" href="#module-tests.test_main">TestMain</a></li>
|
||||
<li><a class="reference internal" href="#module-tests.test_speaker">TestSpeaker</a></li>
|
||||
<li><a class="reference internal" href="#module-tests.test_speech_synthesis">TestSpeechSynthesis</a></li>
|
||||
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
BIN
docs/objects.inv
BIN
docs/objects.inv
Binary file not shown.
@@ -45,7 +45,8 @@
|
||||
<h1>Python Module Index</h1>
|
||||
|
||||
<div class="modindex-jumpbox">
|
||||
<a href="#cap-j"><strong>j</strong></a>
|
||||
<a href="#cap-j"><strong>j</strong></a> |
|
||||
<a href="#cap-t"><strong>t</strong></a>
|
||||
</div>
|
||||
|
||||
<table class="indextable modindextable">
|
||||
@@ -628,6 +629,40 @@
|
||||
<td>   
|
||||
<a href="index.html#module-jarvis.modules.wakeonlan.wakeonlan"><code class="xref">jarvis.modules.wakeonlan.wakeonlan</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="pcap"><td></td><td> </td><td></td></tr>
|
||||
<tr class="cap" id="cap-t"><td></td><td>
|
||||
<strong>t</strong></td><td></td></tr>
|
||||
<tr>
|
||||
<td><img src="_static/minus.png" class="toggler"
|
||||
id="toggle-2" style="display: none" alt="-" /></td>
|
||||
<td>
|
||||
<code class="xref">tests</code></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-2">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="index.html#module-tests.test_api"><code class="xref">tests.test_api</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-2">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="index.html#module-tests.test_listener"><code class="xref">tests.test_listener</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-2">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="index.html#module-tests.test_main"><code class="xref">tests.test_main</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-2">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="index.html#module-tests.test_speaker"><code class="xref">tests.test_speaker</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
<tr class="cg-2">
|
||||
<td></td>
|
||||
<td>   
|
||||
<a href="index.html#module-tests.test_speech_synthesis"><code class="xref">tests.test_speech_synthesis</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -914,6 +914,44 @@ WakeOnLAN
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
----------Test Cases----------
|
||||
==============================
|
||||
|
||||
TestAPI
|
||||
=======
|
||||
|
||||
.. automodule:: tests.test_api
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestListener
|
||||
============
|
||||
|
||||
.. automodule:: tests.test_listener
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestMain
|
||||
========
|
||||
|
||||
.. automodule:: tests.test_main
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestSpeaker
|
||||
===========
|
||||
|
||||
.. automodule:: tests.test_speaker
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
TestSpeechSynthesis
|
||||
===================
|
||||
|
||||
.. automodule:: tests.test_speech_synthesis
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ config.multiprocessing_logger(filename=api_config.DEFAULT_LOG_FILENAME,
|
||||
|
||||
|
||||
# Creates log files
|
||||
if not os.path.isfile(config.APIConfig().ACCESS_LOG_FILENAME):
|
||||
pathlib.Path(config.APIConfig().ACCESS_LOG_FILENAME).touch()
|
||||
if not os.path.isfile(api_config.ACCESS_LOG_FILENAME):
|
||||
pathlib.Path(api_config.ACCESS_LOG_FILENAME).touch()
|
||||
|
||||
if not os.path.isfile(config.APIConfig().DEFAULT_LOG_FILENAME):
|
||||
pathlib.Path(config.APIConfig().DEFAULT_LOG_FILENAME).touch()
|
||||
if not os.path.isfile(api_config.DEFAULT_LOG_FILENAME):
|
||||
pathlib.Path(api_config.DEFAULT_LOG_FILENAME).touch()
|
||||
|
||||
# Configure logging
|
||||
importlib.reload(module=logging)
|
||||
|
||||
@@ -19,9 +19,6 @@ from jarvis.modules.models import models
|
||||
from jarvis.modules.peripherals import audio_engine
|
||||
from jarvis.modules.utils import shared, support
|
||||
|
||||
# todo: Rewrite logger.py for jarvis-api and avoid circular imports
|
||||
# todo: Remove all function/method level imports (still exists for api-logger)
|
||||
|
||||
|
||||
def restart_checker() -> NoReturn:
|
||||
"""Operations performed during internal/external request to restart."""
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
7.5.9 (08/07/2023)
|
||||
------------------
|
||||
- Fix broken unit test trigger by ``pre-commit``
|
||||
- Add more tests
|
||||
|
||||
7.5.8 (08/06/2023)
|
||||
------------------
|
||||
- Remove almost all ``function`` level imports
|
||||
|
||||
1
tests/constant.py
Normal file
1
tests/constant.py
Normal file
@@ -0,0 +1 @@
|
||||
SAMPLE_PHRASE = "Welcome to the world of Natural Language Processing."
|
||||
55
tests/test_listener.py
Normal file
55
tests/test_listener.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from jarvis.main import listener # noqa: E402
|
||||
from tests.constant import SAMPLE_PHRASE # noqa: E402
|
||||
|
||||
|
||||
class TestListener(unittest.TestCase):
|
||||
"""TestCase object for testing listener module.
|
||||
|
||||
>>> TestListener
|
||||
|
||||
"""
|
||||
|
||||
@patch("jarvis.modules.audio.listener.microphone")
|
||||
@patch("jarvis.modules.audio.listener.recognizer")
|
||||
@patch("jarvis.modules.audio.listener.playsound")
|
||||
@patch("jarvis.modules.audio.listener.support")
|
||||
def test_listen(self,
|
||||
mock_support: MagicMock,
|
||||
mock_playsound: MagicMock,
|
||||
mock_recognizer: MagicMock,
|
||||
mock_microphone: MagicMock):
|
||||
"""Test the listen function.
|
||||
|
||||
Mock the return values and set up necessary mocks to simulate the behavior of the listen function.
|
||||
Ensure that the listen function is called with the correct arguments.
|
||||
Ensure that the playsound function is not called when sound=False is passed.
|
||||
|
||||
Args:
|
||||
mock_support: Mocked support module.
|
||||
mock_playsound: Mocked playsound function.
|
||||
mock_recognizer: Mocked recognizer module.
|
||||
mock_microphone: Mocked microphone module.
|
||||
"""
|
||||
# Mock the return values and setup necessary mocks
|
||||
mock_listened = MagicMock()
|
||||
mock_recognizer.listen.return_value = mock_listened
|
||||
mock_recognizer.recognize_google.return_value = SAMPLE_PHRASE
|
||||
|
||||
result = listener.listen(sound=False, stdout=False, timeout=5, phrase_time_limit=10)
|
||||
|
||||
# Assertions
|
||||
self.assertEqual(result, SAMPLE_PHRASE)
|
||||
mock_recognizer.listen.assert_called_once_with(source=mock_microphone.__enter__(),
|
||||
timeout=5, phrase_time_limit=10)
|
||||
mock_recognizer.recognize_google.assert_called_once_with(audio_data=mock_listened)
|
||||
mock_support.flush_screen.assert_called_once()
|
||||
|
||||
# Check that playsound function was not called
|
||||
mock_playsound.assert_not_called()
|
||||
@@ -1,12 +1,16 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from typing import NoReturn
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pvporcupine
|
||||
import pyaudio
|
||||
|
||||
from jarvis.main import Activator, models
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
SAMPLE_PHRASE = "Welcome to the world of Natural Language Processing."
|
||||
from jarvis.main import Activator, models # noqa: E402
|
||||
from tests.constant import SAMPLE_PHRASE # noqa: E402
|
||||
|
||||
|
||||
class TestActivator(unittest.TestCase):
|
||||
@@ -18,7 +22,7 @@ class TestActivator(unittest.TestCase):
|
||||
|
||||
@patch("pvporcupine.create")
|
||||
@patch("jarvis.main.audio_engine.open")
|
||||
def test_init_activator(self, mock_audio_open: MagicMock, mock_pvporcupine_create: MagicMock):
|
||||
def test_init_activator(self, mock_audio_open: MagicMock, mock_pvporcupine_create: MagicMock) -> NoReturn:
|
||||
"""Test whether the Activator is initialized correctly.
|
||||
|
||||
Mock the return values of the create function.
|
||||
@@ -58,16 +62,16 @@ class TestActivator(unittest.TestCase):
|
||||
mock_audio_close: MagicMock,
|
||||
mock_speak: MagicMock,
|
||||
mock_initiator: MagicMock,
|
||||
mock_listen: MagicMock):
|
||||
mock_listen: MagicMock) -> NoReturn:
|
||||
"""Test the executor method of Activator.
|
||||
|
||||
Mock return values of the listen function and set up necessary mocks.
|
||||
|
||||
Args:
|
||||
mock_audio_close: Patched audio_engine.close from jarvis.main.py.
|
||||
mock_speak: Patched speaker.speak from jarvis.modules.audio.
|
||||
mock_initiator: Patched commander.initiator from jarvis.executors.
|
||||
mock_listen: Patched listener.listen from jarvis.modules.audio.
|
||||
mock_speak: Patched ``speaker.speak`` from jarvis.modules.audio.
|
||||
mock_initiator: Patched ``commander.initiator`` from jarvis.executors.
|
||||
mock_listen: Patched ``listener.listen`` from jarvis.modules.audio.
|
||||
"""
|
||||
mock_listen.return_value = SAMPLE_PHRASE
|
||||
mock_initiator.return_value = None # Not testing the behavior of initiator here
|
||||
88
tests/test_speaker.py
Normal file
88
tests/test_speaker.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from typing import NoReturn
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from jarvis.modules.audio import speaker # noqa: E402
|
||||
from jarvis.modules.utils import shared # noqa: E402
|
||||
from tests.constant import SAMPLE_PHRASE # noqa: E402
|
||||
|
||||
|
||||
class TestSpeak(unittest.TestCase):
|
||||
"""TestCase object for testing the speaker module.
|
||||
|
||||
>>> TestSpeak
|
||||
|
||||
"""
|
||||
|
||||
@patch('jarvis.modules.audio.speaker.speech_synthesizer', return_value=False)
|
||||
@patch('playsound.playsound')
|
||||
def test_speech_synthesis_usage(self, mock_playsound: MagicMock, mock_speech_synthesizer: MagicMock) -> NoReturn:
|
||||
"""Test speech synthesis usage.
|
||||
|
||||
Args:
|
||||
mock_playsound: Mock object for playsound module.
|
||||
mock_speech_synthesizer: Mock object for speaker.speech_synthesizer function.
|
||||
"""
|
||||
speaker.speak(text=SAMPLE_PHRASE, run=False, block=True)
|
||||
mock_speech_synthesizer.assert_called_once_with(text=SAMPLE_PHRASE)
|
||||
mock_playsound.assert_not_called()
|
||||
|
||||
@patch('playsound.playsound')
|
||||
@patch('jarvis.modules.audio.speaker.speak', return_value=False)
|
||||
@patch('jarvis.modules.audio.speaker.speech_synthesizer', return_value=False)
|
||||
def test_audio_driver_usage(self, mock_playsound: MagicMock, mock_speaker: MagicMock,
|
||||
mock_speech_synthesizer: MagicMock) -> NoReturn:
|
||||
"""Test audio driver usage.
|
||||
|
||||
Args:
|
||||
mock_playsound: Mock object for playsound module.
|
||||
mock_speaker: Mock object for ``speaker.speak`` function.
|
||||
mock_speech_synthesizer: Mock object for speaker.speech_synthesizer function.
|
||||
"""
|
||||
speaker.speak(text=SAMPLE_PHRASE, run=True)
|
||||
mock_speaker.assert_called_once_with(text=SAMPLE_PHRASE, run=True)
|
||||
mock_playsound.assert_not_called()
|
||||
mock_speech_synthesizer.assert_not_called()
|
||||
|
||||
@patch('jarvis.modules.utils.support.write_screen')
|
||||
def test_no_text_input(self, mock_write_screen: MagicMock) -> NoReturn:
|
||||
"""Test speak function with no text input.
|
||||
|
||||
Args:
|
||||
mock_write_screen: Mock object for support.write_screen function.
|
||||
"""
|
||||
speaker.speak(text=None, run=False, block=True)
|
||||
mock_write_screen.assert_not_called()
|
||||
|
||||
@patch('jarvis.modules.utils.support.write_screen')
|
||||
def test_text_input_and_run(self, mock_write_screen: MagicMock) -> NoReturn:
|
||||
"""Test speak function with text input and run flag.
|
||||
|
||||
Args:
|
||||
mock_write_screen: Mock object for support.write_screen function.
|
||||
"""
|
||||
speaker.speak(text=SAMPLE_PHRASE, run=True, block=True)
|
||||
mock_write_screen.assert_called_once_with(text=SAMPLE_PHRASE)
|
||||
|
||||
@patch('jarvis.modules.audio.speaker.speech_synthesizer', return_value=False)
|
||||
@patch('playsound.playsound')
|
||||
def test_offline_mode(self, mock_playsound: MagicMock, mock_speech_synthesizer: MagicMock) -> NoReturn:
|
||||
"""Test speak function in offline mode.
|
||||
|
||||
Args:
|
||||
mock_playsound: Mock object for playsound module.
|
||||
mock_speech_synthesizer: Mock object for speaker.speech_synthesizer function.
|
||||
"""
|
||||
shared.called_by_offline = True
|
||||
speaker.speak(text=SAMPLE_PHRASE)
|
||||
mock_speech_synthesizer.assert_not_called()
|
||||
mock_playsound.assert_not_called()
|
||||
shared.called_by_offline = False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
88
tests/test_speech_synthesis.py
Normal file
88
tests/test_speech_synthesis.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from typing import NoReturn
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
from jarvis.modules.audio import speaker # noqa: E402
|
||||
from jarvis.modules.exceptions import EgressErrors # noqa: E402
|
||||
from tests.constant import SAMPLE_PHRASE # noqa: E402
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
class TestSpeechSynthesizer(unittest.TestCase):
|
||||
"""TestSpeechSynthesizer object for testing speech synthesis module.
|
||||
|
||||
>>> TestSpeechSynthesizer
|
||||
|
||||
"""
|
||||
|
||||
@patch('requests.post')
|
||||
def test_successful_synthesis(self, mock_post: MagicMock) -> NoReturn:
|
||||
"""Test successful speech synthesis.
|
||||
|
||||
This method tests the behavior of the speech_synthesizer function when a successful
|
||||
response is mocked from the post request call.
|
||||
|
||||
Args:
|
||||
mock_post: Mock of the ``requests.post`` function.
|
||||
"""
|
||||
mock_response = MagicMock()
|
||||
mock_response.ok = True
|
||||
mock_response.content = SAMPLE_PHRASE.encode(encoding='UTF-8')
|
||||
mock_post.return_value = mock_response
|
||||
|
||||
result = speaker.speech_synthesizer(SAMPLE_PHRASE)
|
||||
|
||||
self.assertTrue(result)
|
||||
|
||||
@patch('requests.post')
|
||||
def test_unsuccessful_synthesis(self, mock_post: MagicMock) -> NoReturn:
|
||||
"""Test unsuccessful speech synthesis.
|
||||
|
||||
This method tests the behavior of the speech_synthesizer function when an unsuccessful
|
||||
response is mocked from the post request call.
|
||||
|
||||
Args:
|
||||
mock_post: Mock of the ``requests.post`` function.
|
||||
"""
|
||||
mock_response = MagicMock()
|
||||
mock_response.ok = False
|
||||
mock_response.status_code = 500
|
||||
mock_post.return_value = mock_response
|
||||
|
||||
result = speaker.speech_synthesizer(SAMPLE_PHRASE)
|
||||
|
||||
self.assertFalse(result)
|
||||
|
||||
@patch('requests.post', side_effect=UnicodeError("Test UnicodeError"))
|
||||
def test_unicode_error_handling(self, mock_post: MagicMock) -> NoReturn:
|
||||
"""Test UnicodeError handling in speech synthesis.
|
||||
|
||||
This method tests the handling of UnicodeError within the speech_synthesizer function.
|
||||
|
||||
Args:
|
||||
mock_post: Mock of the ``requests.post`` function with side effect.
|
||||
"""
|
||||
result = speaker.speech_synthesizer(SAMPLE_PHRASE)
|
||||
|
||||
self.assertFalse(result)
|
||||
|
||||
@patch('requests.post', side_effect=EgressErrors)
|
||||
def test_egress_error_handling(self, mock_post: MagicMock) -> NoReturn:
|
||||
"""Test EgressErrors handling in speech synthesis.
|
||||
|
||||
This method tests the handling of EgressErrors within the speech_synthesizer function.
|
||||
|
||||
Args:
|
||||
mock_post: Mock of the ``requests.post`` function with side effect.
|
||||
"""
|
||||
result = speaker.speech_synthesizer(SAMPLE_PHRASE)
|
||||
|
||||
self.assertFalse(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user