Skip to content

Commit f5b978f

Browse files
committed
unit tests: Rename test class, use inheritance
- Rename the `TestQueryClass` class to `QueryTests`, which is more in keeping with unittest norms. - Replace all explicit uses of `TestQueryClass` throughout the code with `cls` or `self` as appropriate, to eliminate friction against any future name changes.
1 parent 43da4ac commit f5b978f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/tests/query_tests.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,18 @@
5252

5353
app = None
5454

55-
class TestQueryClass(unittest.TestCase):
55+
56+
class QueryTests(unittest.TestCase):
5657
""" Unit test class for Query class """
5758

5859
@classmethod
59-
def setUpClass(TestQueryClass):
60+
def setUpClass(cls):
6061
""" Init unit test data """
6162
# Create Qt application
62-
TestQueryClass.app = QGuiApplication.instance()
63-
TestQueryClass.clip_ids = []
64-
TestQueryClass.file_ids = []
65-
TestQueryClass.transition_ids = []
66-
67-
# Import additional classes that need the app defined first
68-
from classes.query import Clip, File, Transition
63+
cls.app = QGuiApplication.instance()
64+
cls.clip_ids = []
65+
cls.file_ids = []
66+
cls.transition_ids = []
6967

7068
clips = []
7169

@@ -85,7 +83,7 @@ def setUpClass(TestQueryClass):
8583
query_clip.save()
8684

8785
# Keep track of the ids
88-
TestQueryClass.clip_ids.append(query_clip.id)
86+
cls.clip_ids.append(query_clip.id)
8987
clips.append(query_clip)
9088

9189
# Insert some files into the project data
@@ -104,7 +102,7 @@ def setUpClass(TestQueryClass):
104102
query_file.save()
105103

106104
# Keep track of the ids
107-
TestQueryClass.file_ids.append(query_file.id)
105+
cls.file_ids.append(query_file.id)
108106

109107
# Insert some transitions into the project data
110108
for c in clips:
@@ -124,7 +122,7 @@ def setUpClass(TestQueryClass):
124122
query_transition.save()
125123

126124
# Keep track of the ids
127-
TestQueryClass.transition_ids.append(query_transition.id)
125+
cls.transition_ids.append(query_transition.id)
128126

129127
# Don't keep the full query objects around
130128
del clips
@@ -158,7 +156,7 @@ def test_add_clip(self):
158156
def test_update_clip(self):
159157
""" Test the Clip.save method """
160158

161-
update_id = TestQueryClass.clip_ids[0]
159+
update_id = self.clip_ids[0]
162160
clip = Clip.get(id=update_id)
163161
self.assertTrue(clip)
164162

@@ -172,10 +170,13 @@ def test_update_clip(self):
172170
self.assertEqual(clip.data["layer"], 2)
173171
self.assertEqual(clip.data["title"], "My Title")
174172

173+
clips = Clip.filter(layer=2)
174+
self.assertEqual(len(clips), 1)
175+
175176
def test_delete_clip(self):
176177
""" Test the Clip.delete method """
177178

178-
delete_id = TestQueryClass.clip_ids[4]
179+
delete_id = self.clip_ids[4]
179180
clip = Clip.get(id=delete_id)
180181
self.assertTrue(clip)
181182

@@ -193,7 +194,7 @@ def test_delete_clip(self):
193194
def test_filter_clip(self):
194195
""" Test the Clip.filter method """
195196

196-
clips = Clip.filter(id=TestQueryClass.clip_ids[0])
197+
clips = Clip.filter(id=self.clip_ids[0])
197198
self.assertTrue(clips)
198199

199200
# Do not find a clip
@@ -203,7 +204,7 @@ def test_filter_clip(self):
203204
def test_get_clip(self):
204205
""" Test the Clip.get method """
205206

206-
clip = Clip.get(id=TestQueryClass.clip_ids[1])
207+
clip = Clip.get(id=self.clip_ids[1])
207208
self.assertTrue(clip)
208209

209210
# Do not find a clip
@@ -254,7 +255,7 @@ def get_times(item):
254255
def test_update_File(self):
255256
""" Test the File.save method """
256257

257-
update_id = TestQueryClass.file_ids[0]
258+
update_id = self.file_ids[0]
258259
file = File.get(id=update_id)
259260
self.assertTrue(file)
260261

@@ -271,7 +272,7 @@ def test_update_File(self):
271272
def test_delete_File(self):
272273
""" Test the File.delete method """
273274

274-
delete_id = TestQueryClass.file_ids[4]
275+
delete_id = self.file_ids[4]
275276
file = File.get(id=delete_id)
276277
self.assertTrue(file)
277278

@@ -289,7 +290,7 @@ def test_delete_File(self):
289290
def test_filter_File(self):
290291
""" Test the File.filter method """
291292

292-
files = File.filter(id=TestQueryClass.file_ids[0])
293+
files = File.filter(id=self.file_ids[0])
293294
self.assertTrue(files)
294295

295296
# Do not find a File
@@ -299,7 +300,7 @@ def test_filter_File(self):
299300
def test_get_File(self):
300301
""" Test the File.get method """
301302

302-
file = File.get(id=TestQueryClass.file_ids[1])
303+
file = File.get(id=self.file_ids[1])
303304
self.assertTrue(file)
304305

305306
# Do not find a File

0 commit comments

Comments
 (0)