diff options
| author | tassaron | 2022-05-09 22:04:50 -0400 |
|---|---|---|
| committer | tassaron | 2022-05-09 22:05:05 -0400 |
| commit | e1cb15c639b950014bfce24ad292491292c50b0f (patch) | |
| tree | 61e490c1c65a25d4d8bc2e93e2bbc7024da73423 | |
| parent | 401fbb9e395c266923b2ae46d0a7af14e0bf71fa (diff) | |
include test data in package, pytest-qt plugin for testing Qt event loop, remove useless pytest fixtures
| -rw-r--r-- | MANIFEST.in | 2 | ||||
| -rw-r--r-- | setup.py | 3 | ||||
| -rw-r--r-- | src/tests/__init__.py | 15 | ||||
| -rw-r--r-- | src/tests/test_commandline_parser.py | 19 | ||||
| -rw-r--r-- | src/tests/test_core_init.py | 8 |
5 files changed, 22 insertions, 25 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index 2b2d794..6dda6ba 100644 --- a/MANIFEST.in +++ b/MANIFEST.in | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | recursive-include src/tests | 1 | include src/tests/* |
| 2 | include src/components/*.ui | 2 | include src/components/*.ui |
| 3 | include src/gui/*.ui | 3 | include src/gui/*.ui |
| 4 | include src/gui/background.png | 4 | include src/gui/background.png |
| @@ -52,7 +52,8 @@ setup( | |||
| 52 | 'Pillow', | 52 | 'Pillow', |
| 53 | 'PyQt5', | 53 | 'PyQt5', |
| 54 | 'numpy', | 54 | 'numpy', |
| 55 | 'pytest' | 55 | 'pytest', |
| 56 | 'pytest-qt', | ||
| 56 | ], | 57 | ], |
| 57 | entry_points={ | 58 | entry_points={ |
| 58 | 'console_scripts': [ | 59 | 'console_scripts': [ |
diff --git a/src/tests/__init__.py b/src/tests/__init__.py index 062dca7..345bd96 100644 --- a/src/tests/__init__.py +++ b/src/tests/__init__.py | |||
| @@ -2,26 +2,15 @@ import pytest | |||
| 2 | import os | 2 | import os |
| 3 | import sys | 3 | import sys |
| 4 | from ..core import Core | 4 | from ..core import Core |
| 5 | from ..command import Command | ||
| 6 | 5 | ||
| 7 | 6 | ||
| 8 | @pytest.fixture | 7 | def getTestDataPath(filename): |
| 9 | def core(): | ||
| 10 | return Core() | ||
| 11 | |||
| 12 | |||
| 13 | @pytest.fixture | ||
| 14 | def command(): | ||
| 15 | """Like a MainWindow for commandline mode, this owns the Core""" | ||
| 16 | return Command() | ||
| 17 | |||
| 18 | |||
| 19 | def getTestData(filename): | ||
| 20 | return os.path.join(Core.wd, 'tests', 'data', filename) | 8 | return os.path.join(Core.wd, 'tests', 'data', filename) |
| 21 | 9 | ||
| 22 | 10 | ||
| 23 | def run(logFile): | 11 | def run(logFile): |
| 24 | """Run Pytest, which then imports and runs all tests in this module.""" | 12 | """Run Pytest, which then imports and runs all tests in this module.""" |
| 13 | os.environ["PYTEST_QT_API"] = "pyqt5" | ||
| 25 | with open(logFile, "w") as f: | 14 | with open(logFile, "w") as f: |
| 26 | # temporarily redirect stdout to a text file so we capture pytest's output | 15 | # temporarily redirect stdout to a text file so we capture pytest's output |
| 27 | sys.stdout = f | 16 | sys.stdout = f |
diff --git a/src/tests/test_commandline_parser.py b/src/tests/test_commandline_parser.py index d672441..0813e00 100644 --- a/src/tests/test_commandline_parser.py +++ b/src/tests/test_commandline_parser.py | |||
| @@ -1,39 +1,44 @@ | |||
| 1 | import sys | 1 | import sys |
| 2 | import pytest | 2 | import pytest |
| 3 | from .__init__ import command | 3 | from ..command import Command |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | def test_commandline_help(command): | 6 | def test_commandline_help(): |
| 7 | command = Command() | ||
| 7 | sys.argv = ['', '--help'] | 8 | sys.argv = ['', '--help'] |
| 8 | with pytest.raises(SystemExit): | 9 | with pytest.raises(SystemExit): |
| 9 | command.parseArgs() | 10 | command.parseArgs() |
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | def test_commandline_help_if_bad_args(command): | 13 | def test_commandline_help_if_bad_args(): |
| 14 | command = Command() | ||
| 13 | sys.argv = ['', '--junk'] | 15 | sys.argv = ['', '--junk'] |
| 14 | with pytest.raises(SystemExit): | 16 | with pytest.raises(SystemExit): |
| 15 | command.parseArgs() | 17 | command.parseArgs() |
| 16 | 18 | ||
| 17 | 19 | ||
| 18 | def test_commandline_launches_gui_if_debug(command): | 20 | def test_commandline_launches_gui_if_debug(): |
| 21 | command = Command() | ||
| 19 | sys.argv = ['', '--debug'] | 22 | sys.argv = ['', '--debug'] |
| 20 | mode = command.parseArgs() | 23 | mode = command.parseArgs() |
| 21 | assert mode == "GUI" | 24 | assert mode == "GUI" |
| 22 | 25 | ||
| 23 | 26 | ||
| 24 | def test_commandline_launches_gui_if_debug_with_project(command): | 27 | def test_commandline_launches_gui_if_debug_with_project(): |
| 28 | command = Command() | ||
| 25 | sys.argv = ['', 'test', '--debug'] | 29 | sys.argv = ['', 'test', '--debug'] |
| 26 | mode = command.parseArgs() | 30 | mode = command.parseArgs() |
| 27 | assert mode == "GUI" | 31 | assert mode == "GUI" |
| 28 | 32 | ||
| 29 | 33 | ||
| 30 | def test_commandline_export_creates_audio_visualization(command): | 34 | def test_commandline_tries_to_export(): |
| 35 | command = Command() | ||
| 31 | didCallFunction = False | 36 | didCallFunction = False |
| 32 | def captureFunction(*args): | 37 | def captureFunction(*args): |
| 33 | nonlocal didCallFunction | 38 | nonlocal didCallFunction |
| 34 | didCallFunction = True | 39 | didCallFunction = True |
| 35 | 40 | ||
| 36 | sys.argv = ['', '-c', '0', 'classic', '-i', '_', '-o', '_'] | 41 | sys.argv = ['', '-c', '0', 'classic', '-i', '_', '-o', '_'] |
| 37 | command.createAudioVisualisation = captureFunction | 42 | command.createAudioVisualization = captureFunction |
| 38 | command.parseArgs() | 43 | command.parseArgs() |
| 39 | assert didCallFunction | 44 | assert didCallFunction |
diff --git a/src/tests/test_core_init.py b/src/tests/test_core_init.py index 696533a..438f7fe 100644 --- a/src/tests/test_core_init.py +++ b/src/tests/test_core_init.py | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | from .__init__ import core | 1 | from ..core import Core |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | def test_component_names(core): | 4 | def test_component_names(): |
| 5 | core = Core() | ||
| 5 | assert core.compNames == [ | 6 | assert core.compNames == [ |
| 6 | 'Classic Visualizer', | 7 | 'Classic Visualizer', |
| 7 | 'Color', | 8 | 'Color', |
| @@ -15,5 +16,6 @@ def test_component_names(core): | |||
| 15 | ] | 16 | ] |
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | def test_moduleindex(core): | 19 | def test_moduleindex(): |
| 20 | core = Core() | ||
| 19 | assert core.moduleIndexFor("Classic Visualizer") == 0 | 21 | assert core.moduleIndexFor("Classic Visualizer") == 0 |
