From 522e461deec25a01f61f4346a84c20ff327c5c15 Mon Sep 17 00:00:00 2001 From: "Christian T. Jacobs" Date: Tue, 11 Apr 2017 23:40:06 +0100 Subject: [PATCH] More tests. --- pyqso/logbook.py | 18 ++++++++++++++---- res/test.db | Bin 3072 -> 4096 bytes 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pyqso/logbook.py b/pyqso/logbook.py index 6dfa7bd..435acab 100644 --- a/pyqso/logbook.py +++ b/pyqso/logbook.py @@ -1220,10 +1220,7 @@ class Logbook: :returns: The total number of QSOs/records in the whole logbook. :rtype: int """ - total = 0 - for log in self.logs: - total += log.record_count - return total + return sum([log.record_count for log in self.logs]) def log_name_exists(self, table_name): """ Determine whether a Log object with a given name exists in the SQL database. @@ -1280,6 +1277,11 @@ class TestLogbook(unittest.TestCase): path_to_test_database = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, "res/test.db") success = self.logbook.db_connect(path_to_test_database) assert success + # Populate test logs. + for log_name in ["test", "test2"]: + l = Log(self.logbook.connection, log_name) + l.populate() + self.logbook.logs.append(l) def tearDown(self): """ Disconnect from the test database. """ @@ -1291,5 +1293,13 @@ class TestLogbook(unittest.TestCase): assert self.logbook.log_name_exists("test") # Log 'test' exists. assert not self.logbook.log_name_exists("hello") # Log 'hello' should not exist. + def test_log_count(self): + """ Check that the log count equals 2. """ + assert self.logbook.log_count == 2 # A total of 2 logs in the logbook. + + def test_record_count(self): + """ Check that the record count equals 5. """ + assert self.logbook.record_count == 5 # A total of 5 records over all the logs in the logbook. + if(__name__ == '__main__'): unittest.main() diff --git a/res/test.db b/res/test.db index fedcb4b648c2cf83080feb68f6419540013ac565..c931dbfb3656169f8a1d266d617a54ae965e0588 100644 GIT binary patch delta 350 zcmZpWXi%6SEy~5fz`z2;Fu)9CuuL@27v^Hn{kVe{$YW-B!@x9~$&=yD#KJ0_rYL51 zadC0RR^gJwq@2`})Z!8&Fu~#+ delta 104 zcmZorXpop7Ey~QmzyQK9zzAe8PBhRLWMPjLf2pC8@