diff --git a/pyqso/logbook.py b/pyqso/logbook.py index baa28a3..7093480 100644 --- a/pyqso/logbook.py +++ b/pyqso/logbook.py @@ -940,7 +940,7 @@ class Logbook: """ Given the name of a log, return its index in the list of Log objects. :arg str name: The name of the log. If None, use the name of the currently-selected log. - :returns: The index of the named log in the list of Log objects. + :returns: The index of the named log in the list of Log objects. Returns None is the log cannot be found. :rtype: int """ if(name is None): @@ -954,6 +954,7 @@ class Logbook: # If a page of the logbook (and therefore a Log object) gets deleted, # then the page_index may not correspond to the index of the log in the self.logs list. # Therefore, we have to search for the tab with the same name as the log. + log_index = None for i in range(0, len(self.logs)): if(self.logs[i].name == name): log_index = i diff --git a/tests/test_logbook.py b/tests/test_logbook.py index 6e39fed..d22ac76 100644 --- a/tests/test_logbook.py +++ b/tests/test_logbook.py @@ -89,5 +89,11 @@ class TestLogbook(unittest.TestCase): present = self.logbook.filter_by_callsign(model, iter, data=None) assert(not present) # "HELLOWORLD" is not present in "TEST123" + def test_get_log_index(self): + """ Check that a log's index can be resolved using the log's name. """ + assert(self.logbook.get_log_index(name="test") == 0) + assert(self.logbook.get_log_index(name="test2") == 1) + assert(self.logbook.get_log_index(name="helloworld") is None) + if(__name__ == '__main__'): unittest.main()