Skip to content

Commit

Permalink
unit tests: Rename test class, use inheritance
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
ferdnyc committed Jun 29, 2021
1 parent 43da4ac commit c9b6ad0
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/tests/query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@

app = None

class TestQueryClass(unittest.TestCase):

class QueryTests(unittest.TestCase):
""" Unit test class for Query class """

@classmethod
def setUpClass(TestQueryClass):
def setUpClass(cls):
""" Init unit test data """
# Create Qt application
TestQueryClass.app = QGuiApplication.instance()
TestQueryClass.clip_ids = []
TestQueryClass.file_ids = []
TestQueryClass.transition_ids = []
cls.app = QGuiApplication.instance()
cls.clip_ids = []
cls.file_ids = []
cls.transition_ids = []

# Import additional classes that need the app defined first
from classes.query import Clip, File, Transition
clips = []

clips = []

Expand All @@ -85,7 +85,7 @@ def setUpClass(TestQueryClass):
query_clip.save()

# Keep track of the ids
TestQueryClass.clip_ids.append(query_clip.id)
cls.clip_ids.append(query_clip.id)
clips.append(query_clip)

# Insert some files into the project data
Expand All @@ -104,7 +104,7 @@ def setUpClass(TestQueryClass):
query_file.save()

# Keep track of the ids
TestQueryClass.file_ids.append(query_file.id)
cls.file_ids.append(query_file.id)

# Insert some transitions into the project data
for c in clips:
Expand All @@ -124,7 +124,7 @@ def setUpClass(TestQueryClass):
query_transition.save()

# Keep track of the ids
TestQueryClass.transition_ids.append(query_transition.id)
cls.transition_ids.append(query_transition.id)

# Don't keep the full query objects around
del clips
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_add_clip(self):
def test_update_clip(self):
""" Test the Clip.save method """

update_id = TestQueryClass.clip_ids[0]
update_id = self.clip_ids[0]
clip = Clip.get(id=update_id)
self.assertTrue(clip)

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

clips = Clip.filter(layer=2)
self.assertEqual(len(clips), 1)

def test_delete_clip(self):
""" Test the Clip.delete method """

delete_id = TestQueryClass.clip_ids[4]
delete_id = self.clip_ids[4]
clip = Clip.get(id=delete_id)
self.assertTrue(clip)

Expand All @@ -193,7 +196,7 @@ def test_delete_clip(self):
def test_filter_clip(self):
""" Test the Clip.filter method """

clips = Clip.filter(id=TestQueryClass.clip_ids[0])
clips = Clip.filter(id=self.clip_ids[0])
self.assertTrue(clips)

# Do not find a clip
Expand All @@ -203,7 +206,7 @@ def test_filter_clip(self):
def test_get_clip(self):
""" Test the Clip.get method """

clip = Clip.get(id=TestQueryClass.clip_ids[1])
clip = Clip.get(id=self.clip_ids[1])
self.assertTrue(clip)

# Do not find a clip
Expand Down Expand Up @@ -254,7 +257,7 @@ def get_times(item):
def test_update_File(self):
""" Test the File.save method """

update_id = TestQueryClass.file_ids[0]
update_id = self.file_ids[0]
file = File.get(id=update_id)
self.assertTrue(file)

Expand All @@ -271,7 +274,7 @@ def test_update_File(self):
def test_delete_File(self):
""" Test the File.delete method """

delete_id = TestQueryClass.file_ids[4]
delete_id = self.file_ids[4]
file = File.get(id=delete_id)
self.assertTrue(file)

Expand All @@ -289,7 +292,7 @@ def test_delete_File(self):
def test_filter_File(self):
""" Test the File.filter method """

files = File.filter(id=TestQueryClass.file_ids[0])
files = File.filter(id=self.file_ids[0])
self.assertTrue(files)

# Do not find a File
Expand All @@ -299,7 +302,7 @@ def test_filter_File(self):
def test_get_File(self):
""" Test the File.get method """

file = File.get(id=TestQueryClass.file_ids[1])
file = File.get(id=self.file_ids[1])
self.assertTrue(file)

# Do not find a File
Expand Down

0 comments on commit c9b6ad0

Please sign in to comment.