summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortassaron2022-05-09 22:04:50 -0400
committertassaron2022-05-09 22:05:05 -0400
commite1cb15c639b950014bfce24ad292491292c50b0f (patch)
tree61e490c1c65a25d4d8bc2e93e2bbc7024da73423
parent401fbb9e395c266923b2ae46d0a7af14e0bf71fa (diff)
include test data in package, pytest-qt plugin for testing Qt event loop, remove useless pytest fixtures
-rw-r--r--MANIFEST.in2
-rw-r--r--setup.py3
-rw-r--r--src/tests/__init__.py15
-rw-r--r--src/tests/test_commandline_parser.py19
-rw-r--r--src/tests/test_core_init.py8
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 @@
1recursive-include src/tests 1include src/tests/*
2include src/components/*.ui 2include src/components/*.ui
3include src/gui/*.ui 3include src/gui/*.ui
4include src/gui/background.png 4include src/gui/background.png
diff --git a/setup.py b/setup.py
index 0ed943c..9a8c5ca 100644
--- a/setup.py
+++ b/setup.py
@@ -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
2import os 2import os
3import sys 3import sys
4from ..core import Core 4from ..core import Core
5from ..command import Command
6 5
7 6
8@pytest.fixture 7def getTestDataPath(filename):
9def core():
10 return Core()
11
12
13@pytest.fixture
14def command():
15 """Like a MainWindow for commandline mode, this owns the Core"""
16 return Command()
17
18
19def 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
23def run(logFile): 11def 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 @@
1import sys 1import sys
2import pytest 2import pytest
3from .__init__ import command 3from ..command import Command
4 4
5 5
6def test_commandline_help(command): 6def 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
12def test_commandline_help_if_bad_args(command): 13def 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
18def test_commandline_launches_gui_if_debug(command): 20def 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
24def test_commandline_launches_gui_if_debug_with_project(command): 27def 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
30def test_commandline_export_creates_audio_visualization(command): 34def 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 @@
1from .__init__ import core 1from ..core import Core
2 2
3 3
4def test_component_names(core): 4def 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
18def test_moduleindex(core): 19def test_moduleindex():
20 core = Core()
19 assert core.moduleIndexFor("Classic Visualizer") == 0 21 assert core.moduleIndexFor("Classic Visualizer") == 0