diff --git a/tests/test_adif.py b/tests/test_adif.py index 032428e..e007ac9 100644 --- a/tests/test_adif.py +++ b/tests/test_adif.py @@ -23,7 +23,7 @@ from pyqso.adif import * class TestADIF(unittest.TestCase): - """ The unit tests for the ADIF module. """ + """ The unit tests for the ADIF class. """ def setUp(self): """ Set up the ADIF object needed for the unit tests. """ diff --git a/tests/test_awards.py b/tests/test_awards.py index 4eaa85f..a7ecf0e 100644 --- a/tests/test_awards.py +++ b/tests/test_awards.py @@ -42,10 +42,6 @@ class TestAwards(unittest.TestCase): self.logbook.logs = self.logbook.get_logs() assert(self.logbook.logs is not None) - def tearDown(self): - """ Destroy any unit test resources. """ - pass - def test_count(self): """ Check that there are 3 FM/AM/SSB/SSTV QSOs and 1 CW QSO. Note that the BAND must be specified in order to be counted. """ count = self.awards.count(self.logbook) diff --git a/tests/test_cabrillo.py b/tests/test_cabrillo.py index 0934608..c632709 100644 --- a/tests/test_cabrillo.py +++ b/tests/test_cabrillo.py @@ -26,12 +26,10 @@ class TestCabrillo(unittest.TestCase): """ The unit tests for the Cabrillo class. """ def setUp(self): + """ Set up the Cabrillo object needed for the unit tests. """ self.cabrillo = Cabrillo() return - def tearDown(self): - return - def test_write(self): """ Check that QSOs are written correctly in Cabrillo format. """ records = [{'TIME_ON': '1955', 'BAND': '40m', 'CALL': 'TEST', 'FREQ': "145.550", 'MODE': 'FM', 'QSO_DATE': '20130322', 'RST_SENT': '59 001', 'RST_RCVD': '59 002'}, {'TIME_ON': '0820', 'BAND': '20m', 'CALL': 'TEST2ABC', 'FREQ': "144.330", 'MODE': 'SSB', 'QSO_DATE': '20150227', 'RST_SENT': '55 020', 'RST_RCVD': '57 003'}, {'TIME_ON': '0832', 'BAND': '2m', 'CALL': 'HELLO', 'FREQ': "145.550", 'MODE': 'FM', 'QSO_DATE': '20150227', 'RST_SENT': '59 001', 'RST_RCVD': '59 002'}] diff --git a/tests/test_calendar_dialog.py b/tests/test_calendar_dialog.py index 81b2417..dc59523 100644 --- a/tests/test_calendar_dialog.py +++ b/tests/test_calendar_dialog.py @@ -37,10 +37,6 @@ class TestCalendarDialog(unittest.TestCase): self.cd.calendar.select_month(3, 2017) # Note: Months start from 0 when using the Calendar widget. So "3" represents April here. self.cd.calendar.select_day(2) - def tearDown(self): - """ Destroy any unit test resources. """ - pass - def test_date(self): """ Check that the date obtained from the Calendar is in the correct format. """ assert(self.cd.date == "20170402") diff --git a/tests/test_callsign_lookup.py b/tests/test_callsign_lookup.py index 090f477..5470980 100644 --- a/tests/test_callsign_lookup.py +++ b/tests/test_callsign_lookup.py @@ -27,17 +27,13 @@ from pyqso.callsign_lookup import * class TestCallsignLookup(unittest.TestCase): - """ The unit tests for the CallsignLookup class. """ + """ The unit tests for the callsign lookup functionality. """ def setUp(self): """ Set up the objects needed for the unit tests. """ self.qrz = CallsignLookupQRZ(parent=None) self.hamqth = CallsignLookupHamQTH(parent=None) - def tearDown(self): - """ Destroy any unit test resources. """ - pass - def test_strip(self): """ Check that a callsign with a prefix and a suffix is stripped correctly. """ callsign = "EA3/MYCALL/MM" diff --git a/tests/test_compare.py b/tests/test_compare.py index bd355f2..b1aeda6 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -24,9 +24,11 @@ from pyqso.compare import * class TestCompare(unittest.TestCase): - """ The unit tests for the Compare class. """ + """ The unit tests for the comparison schemes. """ def setUp(self): + """ Set up the objects needed for the unit tests. """ + data_types = [int] + [str]*3 self.model = Gtk.ListStore(*data_types) row1 = [0, "100", "20150323", "1433"] @@ -39,9 +41,6 @@ class TestCompare(unittest.TestCase): self.model.append(row4) return - def tearDown(self): - return - def test_compare_default(self): """ Check the correctness of the default comparison scheme. """ diff --git a/tests/test_dx_cluster.py b/tests/test_dx_cluster.py index 05a334e..12a8f04 100644 --- a/tests/test_dx_cluster.py +++ b/tests/test_dx_cluster.py @@ -31,13 +31,10 @@ class TestDXCluster(unittest.TestCase): def setUp(self): """ Set up the objects needed for the unit tests. """ + PyQSO = mock.MagicMock() self.dxcluster = DXCluster(application=PyQSO()) - def tearDown(self): - """ Destroy any unit test resources. """ - pass - def test_on_telnet_io(self): """ Check that the response from the Telnet server can be correctly decoded. """ diff --git a/tests/test_log.py b/tests/test_log.py index faed907..d63adfa 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -26,6 +26,7 @@ class TestLog(unittest.TestCase): """ The unit tests for the Log class. """ def setUp(self): + """ Create a connection to a temporary database and set up the objects needed for the unit tests. """ self.connection = sqlite.connect(":memory:") self.connection.row_factory = sqlite.Row @@ -43,21 +44,26 @@ class TestLog(unittest.TestCase): self.log = Log(self.connection, "test") def tearDown(self): + """ Destroy the connection to the temporary database. """ self.connection.close() def test_add_missing_db_columns(self): - - column_names_before = [] - column_names_after = [] + """ Check that any missing columns in the database are added successfully. """ c = self.connection.cursor() + + # 'Before' state. + column_names_before = [] c.execute("PRAGMA table_info(test)") result = c.fetchall() for t in result: column_names_before.append(t[1].upper()) + # Add missing columns. self.log.add_missing_db_columns() + # 'After' state. + column_names_after = [] c.execute("PRAGMA table_info(test)") result = c.fetchall() for t in result: @@ -66,24 +72,43 @@ class TestLog(unittest.TestCase): print("Column names before: ", column_names_before) print("Column names after: ", column_names_after) - assert(len(column_names_before) == len(self.field_names) + 1) # Added 1 here because of the "ID" column in all database tables. + assert(len(column_names_before) == len(self.field_names) + 1) # Added 1 here because of the "id" column in all database tables. assert(len(column_names_after) == len(AVAILABLE_FIELD_NAMES_ORDERED) + 1) for field_name in AVAILABLE_FIELD_NAMES_ORDERED: assert(field_name in column_names_after) def test_add_record(self): + """ Check that a single record can be successfully added. """ + self.log.add_record(self.fields_and_data) + c = self.connection.cursor() c.execute("SELECT * FROM test") records = c.fetchall() - assert len(records) == 1 + # Check that all the data has been added to all the fields. for field_name in self.field_names: print(self.fields_and_data[field_name], records[0][field_name]) assert self.fields_and_data[field_name] == records[0][field_name] + # Check consistency of index between Gtk.ListStore and the database. + assert(records[0]["id"] == 1) + iter = self.log.get_iter_first() + row_index = self.log.get_value(iter, 0) + assert(records[0]["id"] == row_index) + + def test_add_record_multiple(self): + """ Check that multiple records can be successfully added in one go. """ + self.log.add_record([self.fields_and_data]*5) + + c = self.connection.cursor() + c.execute("SELECT * FROM test") + records = c.fetchall() + assert len(records) == 5 + def test_delete_record(self): + """ Check that a record can be successfully deleted. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() c.execute(query, (self.fields_and_data["CALL"], self.fields_and_data["QSO_DATE"], self.fields_and_data["TIME_ON"], self.fields_and_data["FREQ"], self.fields_and_data["BAND"], self.fields_and_data["MODE"], self.fields_and_data["RST_SENT"], self.fields_and_data["RST_RCVD"])) @@ -100,6 +125,7 @@ class TestLog(unittest.TestCase): assert(len(records_after) == 0) def test_edit_record(self): + """ Check that a record's fields can be successfully edited. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() c.execute(query, (self.fields_and_data["CALL"], self.fields_and_data["QSO_DATE"], self.fields_and_data["TIME_ON"], self.fields_and_data["FREQ"], self.fields_and_data["BAND"], self.fields_and_data["MODE"], self.fields_and_data["RST_SENT"], self.fields_and_data["RST_RCVD"])) @@ -119,6 +145,7 @@ class TestLog(unittest.TestCase): assert(record_after["FREQ"] == "145.450") def test_get_record_by_index(self): + """ Check that a record can be retrieved using its index. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() c.execute(query, (self.fields_and_data["CALL"], self.fields_and_data["QSO_DATE"], self.fields_and_data["TIME_ON"], self.fields_and_data["FREQ"], self.fields_and_data["BAND"], self.fields_and_data["MODE"], self.fields_and_data["RST_SENT"], self.fields_and_data["RST_RCVD"])) @@ -133,6 +160,7 @@ class TestLog(unittest.TestCase): assert(len(record) == len(self.fields_and_data) + 1) def test_records(self): + """ Check that all records in a log can be successfully retrieved. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() # Add the same record twice @@ -147,6 +175,7 @@ class TestLog(unittest.TestCase): assert(records[1][field_name] == self.fields_and_data[field_name]) def test_record_count(self): + """ Check that the total number of records in a log is calculated correctly. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() # Add the same record twice @@ -158,6 +187,7 @@ class TestLog(unittest.TestCase): assert(record_count == 2) # There should be 2 records def test_get_duplicates(self): + """ Insert n records, n-1 of which are duplicates, and check that the duplicates are successfully identified. """ query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)" c = self.connection.cursor() n = 5 # The total number of records to insert. @@ -165,7 +195,20 @@ class TestLog(unittest.TestCase): c.execute(query, (self.fields_and_data["CALL"], self.fields_and_data["QSO_DATE"], self.fields_and_data["TIME_ON"], self.fields_and_data["FREQ"], self.fields_and_data["BAND"], self.fields_and_data["MODE"], self.fields_and_data["RST_SENT"], self.fields_and_data["RST_RCVD"])) assert(len(self.log.get_duplicates()) == n-1) # Expecting n-1 duplicates. + def test_remove_duplicates(self): + """ Insert n records, n-1 of which are duplicates, and check that the duplicates are successfully removed. """ + n = 5 # The total number of records to insert. + for i in range(0, n): + self.log.add_record(self.fields_and_data) + (number_of_duplicates, number_of_duplicates_removed) = self.log.remove_duplicates() + print("Number of duplicates: %d" % number_of_duplicates) + print("Number of duplicates removed: %d" % number_of_duplicates_removed) + assert(number_of_duplicates == number_of_duplicates_removed) + assert(number_of_duplicates == 4) + assert(self.log.record_count == 1) + def test_rename(self): + """ Check that a log can be successfully renamed. """ old_name = "test" new_name = "hello" success = self.log.rename(new_name) diff --git a/tests/test_printer.py b/tests/test_printer.py index b767d4c..82358d5 100644 --- a/tests/test_printer.py +++ b/tests/test_printer.py @@ -37,10 +37,6 @@ class TestPrinter(unittest.TestCase): self.printer = Printer(application=PyQSO()) self.printer.application.window = Gtk.Window() - def tearDown(self): - """ Destroy any unit test resources. """ - return - def test_print_records(self): """ Check that a list of records can be printed to a PDF file. """ self.printer.action = Gtk.PrintOperationAction.EXPORT diff --git a/tests/test_record_dialog.py b/tests/test_record_dialog.py index 500ed37..b6ec67b 100644 --- a/tests/test_record_dialog.py +++ b/tests/test_record_dialog.py @@ -31,6 +31,7 @@ class TestRecordDialog(unittest.TestCase): """ The unit tests for the RecordDialog class. """ def setUp(self): + """ Set up the objects needed for the unit tests. """ PyQSO = mock.MagicMock() self.record_dialog = RecordDialog(application=PyQSO(), log=None) @@ -51,9 +52,6 @@ class TestRecordDialog(unittest.TestCase): return - def tearDown(self): - return - def test_autocomplete_band(self): """ Given a frequency, check that the band field is automatically set to the correct value. """ self.record_dialog.sources["FREQ"].set_text("145.525") diff --git a/tests/test_summary.py b/tests/test_summary.py index f105ea6..018d267 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -32,7 +32,7 @@ class TestSummary(unittest.TestCase): """ The unit tests for the Summary class. """ def setUp(self): - """ Set up the objects needed for the unit tests. """ + """ Set up the objects needed for the unit tests and create a connection to the test database. """ PyQSO = mock.MagicMock() self.summary = Summary(application=PyQSO()) self.summary.logbook = Logbook(application=PyQSO()) @@ -43,7 +43,7 @@ class TestSummary(unittest.TestCase): assert(self.summary.logbook.logs is not None) def tearDown(self): - """ Destroy any unit test resources. """ + """ Destroy the connection to the test database. """ success = self.summary.logbook.db_disconnect() assert(success)