Renaming tests for consistency reasons.

pull/61/head
Christian T. Jacobs 2017-06-24 21:31:21 +01:00
rodzic 5c1d3aeef0
commit 7b1c452f3e
3 zmienionych plików z 44 dodań i 37 usunięć

Wyświetl plik

@ -29,7 +29,7 @@ class TestADIF(unittest.TestCase):
""" Set up the ADIF object needed for the unit tests. """
self.adif = ADIF()
def test_adif_read(self):
def test_read(self):
""" Check that a single ADIF record can be read and parsed correctly. """
f = open("ADIF.test_read.adi", 'w')
f.write("""Some test ADI data.<eoh>
@ -46,7 +46,7 @@ class TestADIF(unittest.TestCase):
assert(len(list(records[0].keys())) == len(list(expected_records[0].keys())))
assert(records == expected_records)
def test_adif_read_multiple(self):
def test_read_multiple(self):
""" Check that multiple ADIF records can be read and parsed correctly. """
f = open("ADIF.test_read_multiple.adi", 'w')
f.write("""Some test ADI data.<eoh>
@ -69,7 +69,7 @@ class TestADIF(unittest.TestCase):
assert(len(list(records[i].keys())) == len(list(expected_records[i].keys())))
assert(records == expected_records)
def test_adif_read_alphabet(self):
def test_read_alphabet(self):
""" Check that none of the letters of the alphabet are ignored during parsing. """
f = open("ADIF.test_read_alphabet.adi", 'w')
f.write("""Some test ADI data.<eoh>
@ -84,7 +84,7 @@ class TestADIF(unittest.TestCase):
assert(len(list(records[0].keys())) == len(list(expected_records[0].keys())))
assert(records == expected_records)
def test_adif_read_capitalisation(self):
def test_read_capitalisation(self):
""" Check that the CALL field is capitalised correctly. """
f = open("ADIF.test_read_capitalisation.adi", 'w')
f.write("""Some test ADI data.<eoh>
@ -99,7 +99,7 @@ class TestADIF(unittest.TestCase):
assert(len(list(records[0].keys())) == len(list(expected_records[0].keys())))
assert(records == expected_records)
def test_adif_read_header_only(self):
def test_read_header_only(self):
""" Check that no records are read in if the ADIF file only contains header information. """
f = open("ADIF.test_read_header_only.adi", 'w')
f.write("""Some test ADI data.<eoh>""")
@ -112,7 +112,7 @@ class TestADIF(unittest.TestCase):
assert(len(records) == 0)
assert(records == expected_records)
def test_adif_read_no_header(self):
def test_read_no_header(self):
""" Check that an ADIF file can be parsed with no header information. """
f = open("ADIF.test_read_no_header.adi", 'w')
f.write("""<call:4>TEST<band:3>40m<mode:2>CW<qso_date:8:d>20130322<time_on:4>1955<eor>""")
@ -126,7 +126,7 @@ class TestADIF(unittest.TestCase):
assert(len(list(records[0].keys())) == len(list(expected_records[0].keys())))
assert(records == expected_records)
def test_adif_write(self):
def test_write(self):
""" Check that records can be written to an ADIF file correctly. """
records = [{"CALL": "TEST123", "QSO_DATE": "20120402", "TIME_ON": "1234", "FREQ": "145.500", "BAND": "2m", "MODE": "FM", "RST_SENT": "59", "RST_RCVD": "59"},
{"CALL": "TEST123", "QSO_DATE": "20130312", "TIME_ON": "0101", "FREQ": "145.750", "BAND": "2m", "MODE": "FM"}]
@ -159,7 +159,7 @@ class TestADIF(unittest.TestCase):
""" in text) # Ignore the header line here, since it contains the date and time the ADIF file was written, which will change each time 'make unittest' is run.
f.close()
def test_adif_write_sqlite3_Row(self):
def test_write_sqlite3_Row(self):
""" Check that records can be written to an ADIF file from a test database file. """
import sqlite3
import os.path
@ -203,7 +203,7 @@ class TestADIF(unittest.TestCase):
self.connection.close()
def test_adif_is_valid(self):
def test_is_valid(self):
""" Check that ADIF field validation is working correctly for different data types. """
assert(self.adif.is_valid("CALL", "TEST123", "S"))
assert(self.adif.is_valid("QSO_DATE", "20120402", "D"))

Wyświetl plik

@ -45,7 +45,7 @@ class TestLog(unittest.TestCase):
def tearDown(self):
self.connection.close()
def test_log_add_missing_db_columns(self):
def test_add_missing_db_columns(self):
column_names_before = []
column_names_after = []
@ -71,7 +71,7 @@ class TestLog(unittest.TestCase):
for field_name in AVAILABLE_FIELD_NAMES_ORDERED:
assert(field_name in column_names_after)
def test_log_add_record(self):
def test_add_record(self):
self.log.add_record(self.fields_and_data)
c = self.connection.cursor()
c.execute("SELECT * FROM test")
@ -83,7 +83,7 @@ class TestLog(unittest.TestCase):
print(self.fields_and_data[field_name], records[0][field_name])
assert self.fields_and_data[field_name] == records[0][field_name]
def test_log_delete_record(self):
def test_delete_record(self):
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"]))
@ -99,7 +99,7 @@ class TestLog(unittest.TestCase):
assert(len(records_before) == 1)
assert(len(records_after) == 0)
def test_log_edit_record(self):
def test_edit_record(self):
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"]))
@ -118,7 +118,7 @@ class TestLog(unittest.TestCase):
assert(record_before["FREQ"] == "145.500")
assert(record_after["FREQ"] == "145.450")
def test_log_get_record_by_index(self):
def test_get_record_by_index(self):
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"]))
@ -132,7 +132,7 @@ class TestLog(unittest.TestCase):
assert(record[field_name.upper()] == self.fields_and_data[field_name.upper()])
assert(len(record) == len(self.fields_and_data) + 1)
def test_log_records(self):
def test_records(self):
query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)"
c = self.connection.cursor()
# Add the same record twice
@ -146,7 +146,7 @@ class TestLog(unittest.TestCase):
assert(records[0][field_name] == self.fields_and_data[field_name])
assert(records[1][field_name] == self.fields_and_data[field_name])
def test_log_record_count(self):
def test_record_count(self):
query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)"
c = self.connection.cursor()
# Add the same record twice
@ -157,7 +157,7 @@ class TestLog(unittest.TestCase):
print("Number of records in the log: ", record_count)
assert(record_count == 2) # There should be 2 records
def test_log_get_duplicates(self):
def test_get_duplicates(self):
query = "INSERT INTO test VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)"
c = self.connection.cursor()
n = 5 # The total number of records to insert.
@ -165,7 +165,7 @@ 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_log_rename(self):
def test_rename(self):
old_name = "test"
new_name = "hello"
success = self.log.rename(new_name)

Wyświetl plik

@ -23,6 +23,7 @@ try:
except ImportError:
import mock
import os
from shutil import copyfile
from pyqso.logbook import *
@ -61,11 +62,14 @@ class TestLogbook(unittest.TestCase):
disconnected = self.logbook.db_disconnect()
assert(disconnected)
def test_new(self):
""" """
#path_to_new_database = "Logbook.test_new.db"
#opened = self.logbook.open(path=path_to_invalid_database)
pass
@mock.patch('pyqso.auxiliary_dialogs.handle_gtk_dialog')
@mock.patch('gi.repository.Gtk.FileChooserDialog')
def test_new(self, mock_FileChooserDialog, mock_handle_gtk_dialog):
""" Check that a new logbook can be created. """
mock_FileChooserDialog().run.return_value = Gtk.ResponseType.OK
mock_FileChooserDialog().get_filename.return_value = "Logbook.test_new.db"
self.logbook.new()
assert(os.path.isfile("Logbook.test_new.db"))
@mock.patch('pyqso.auxiliary_dialogs.handle_gtk_dialog')
def test_open_invalid_logbook(self, mock_handle_gtk_dialog):
@ -75,6 +79,23 @@ class TestLogbook(unittest.TestCase):
assert(not opened)
assert(self.logbook.logs is None)
@mock.patch('pyqso.logbook.Logbook.render_log')
@mock.patch('pyqso.auxiliary_dialogs.handle_gtk_dialog')
@mock.patch('pyqso.logbook.LogNameDialog')
def test_new_log(self, mock_LogNameDialog, mock_handle_gtk_dialog, mock_render_log):
""" Create an empty logbook file, open it, and check that a new log can successfully be added. """
# Create a copy of the test database just for use in this particular test, since the contents will need to be modified.
path_to_test_database = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, "res/test.db")
destination = "Logbook.test_new_log.db"
copyfile(path_to_test_database, destination)
opened = self.logbook.open(path=destination)
assert(opened)
mock_LogNameDialog().dialog.run.return_value = Gtk.ResponseType.OK
mock_LogNameDialog().name = "my_new_log"
self.logbook.new_log()
assert(len(self.logbook.logs) == 3)
assert(self.logbook.logs[-1].name == "my_new_log")
def test_log_name_exists(self):
""" Check that only the log called 'test' exists. """
assert(self.logbook.log_name_exists("test")) # Log 'test' exists.
@ -118,19 +139,5 @@ class TestLogbook(unittest.TestCase):
assert(self.logbook.get_log_index(name="test2") == 1)
assert(self.logbook.get_log_index(name="helloworld") is None)
@mock.patch('pyqso.logbook.Logbook.render_log')
@mock.patch('pyqso.auxiliary_dialogs.handle_gtk_dialog')
@mock.patch('pyqso.logbook.LogNameDialog')
def test_new_log(self, mock_LogNameDialog, mock_handle_gtk_dialog, mock_render_log):
""" Create an empty logbook file, open it, and check that a new log can successfully be added. """
open("Logbook.test_new_log.db", "w").close()
opened = self.logbook.open(path="Logbook.test_new_log.db")
assert(opened)
mock_LogNameDialog().dialog.run.return_value = Gtk.ResponseType.OK
mock_LogNameDialog().name = "my_new_log"
self.logbook.new_log()
assert(len(self.logbook.logs) == 1)
assert(self.logbook.logs[0].name == "my_new_log")
if(__name__ == '__main__'):
unittest.main()