25
25
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26
26
"""
27
27
28
- import sys , os
28
+ import sys
29
+ import os
30
+ import random
31
+ import unittest
32
+ import uuid
33
+ import json
34
+
35
+ import openshot
36
+
37
+ from PyQt5 .QtGui import QGuiApplication
38
+ try :
39
+ # QtWebEngineWidgets must be loaded prior to creating a QApplication
40
+ # But on systems with only WebKit, this will fail (and we ignore the failure)
41
+ from PyQt5 .QtWebEngineWidgets import QWebEngineView
42
+ except ImportError :
43
+ pass
44
+
29
45
# Import parent folder (so it can find other imports)
30
46
PATH = os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))
31
47
if PATH not in sys .path :
32
48
sys .path .append (PATH )
33
49
34
- import random
35
- import unittest
36
- import uuid
37
- from PyQt5 .QtGui import QGuiApplication
38
50
from classes .app import OpenShotApp
39
51
from classes import info
40
- import openshot # Python module for libopenshot (required video editing module installed separately)
41
- import json
52
+
53
+
54
+ app = None
42
55
43
56
class TestQueryClass (unittest .TestCase ):
44
57
""" Unit test class for Query class """
@@ -47,7 +60,7 @@ class TestQueryClass(unittest.TestCase):
47
60
def setUpClass (TestQueryClass ):
48
61
""" Init unit test data """
49
62
# Create Qt application
50
- TestQueryClass .app = OpenShotApp ([], mode = "unittest" )
63
+ TestQueryClass .app = QGuiApplication . instance ( )
51
64
TestQueryClass .clip_ids = []
52
65
TestQueryClass .file_ids = []
53
66
TestQueryClass .transition_ids = []
@@ -106,8 +119,7 @@ def setUpClass(TestQueryClass):
106
119
@classmethod
107
120
def tearDownClass (cls ):
108
121
"Hook method for deconstructing the class fixture after running all tests in the class."
109
- print ('Exiting Unittests: Quitting QApplication' )
110
- TestQueryClass .app .window .actionQuit .trigger ()
122
+ TestQueryClass .app .quit ()
111
123
112
124
def test_add_clip (self ):
113
125
""" Test the Clip.save method by adding multiple clips """
@@ -318,6 +330,19 @@ def test_add_file(self):
318
330
self .assertEqual (len (File .filter ()), num_files + 1 )
319
331
320
332
321
- if __name__ == '__main__' :
322
- app = QGuiApplication (sys .argv )
333
+ def main ():
334
+ global app
335
+ info .LOG_LEVEL_CONSOLE = "ERROR"
336
+ try :
337
+ app = OpenShotApp (sys .argv , mode = "unittest" )
338
+ except Exception :
339
+ from logging import logger
340
+ log = logger .getlog ("." )
341
+ log .error ("Failed to instantiate OpenShotApp" , exc_info = 1 )
342
+ sys .exit ()
323
343
unittest .main ()
344
+ app .exec_ ()
345
+
346
+
347
+ if __name__ == '__main__' :
348
+ main ()
0 commit comments