def test_save_load_settings(self): m = Model() m.settings['my_new_setting'] = "setting1" m.settings['db_path'] = "db.txt" m.save_settings() m2 = Model() m2.load_settings() self.assertEqual(m.settings, m2.settings)
def print_database(filename): m = Model() m.settings['db_path'] = filename m.load_tasks() for it in range(len(m.tasks)): id = m.tasks[it].id print("\nTASK index:{} id:{}-----------------------".format( it, id)) print("CONTENT: {}".format(m.tasks[it].get_content())) print("STATUS: {}".format(m.tasks[it].get_status()))
def test_del_task(self): m = Model() t = Task() t.set_content("test content") t.set_status(TaskStatus.DONE) t.id = 5 m.add_task(t) t.set_content("test content2") t.set_status(TaskStatus.DOING) t.id = 11 m.add_task(t) m.del_task(5) self.assertEqual(len(m.tasks), 1) gt = m.get_task(11) self.assertEqual(gt.get_status(), TaskStatus.DOING) self.assertEqual(gt.get_content(), "test content2") self.assertEqual(m.get_task(5), False)
def test_get_task_index(self): m = Model() t1 = Task() t1.set_content("test content") t1.set_status(TaskStatus.DONE) t1.id = 5 m.add_task(t1) t2 = Task() t2.set_content("test content2") t2.set_status(TaskStatus.DOING) t2.id = 7 m.add_task(t2) self.assertEqual(m.get_task_index(t2), 1) self.assertEqual(m.get_task_index(t1), 0)
def test_add_task(self): m = Model() t = Task() t.set_content("test content") t.set_status(TaskStatus.DONE) t.id = 5 m.add_task(t) t.set_content("test content2") t.set_status(TaskStatus.DOING) t.id = 10 m.add_task(t) gt2 = m.get_task(5) self.assertEqual(gt2.get_status(), TaskStatus.DONE) self.assertEqual(gt2.get_content(), "test content") gt = m.get_task(10) self.assertEqual(gt.get_status(), TaskStatus.DOING) self.assertEqual(gt.get_content(), "test content2")
def test_get_task(self): m = Model() t1 = Task() t1.set_content("test content") t1.set_status(TaskStatus.DONE) t1.id = 5 m.add_task(t1) t2 = Task() t2.set_content("test content2") t2.set_status(TaskStatus.DOING) t2.id = 7 m.add_task(t2) gt1 = m.get_task(5) gt2 = m.get_task(7) self.assertEqual(gt1, t1) self.assertEqual(gt2, t2)
import sys import interface import newInterface from debug import tic from classModel import Model tic() # for debug window loading time if __name__ == '__main__': print("--------------- M A I N -----------------") model = Model() # window = interface.MainWindow(model) # sys.exit(window.app.exec_()) window = newInterface.MainWindow(model) if not window.engine.rootObjects(): sys.exit(-1) sys.exit(window.app.exec_())
def test_init(self): m = Model() self.assertEqual(m.settings, {}) self.assertEqual(m.tasks, [])
def find_free_id(self): m = Model() t = Task() t.id = 1 m.add_task(t) t.id = 3 m.add_task(t) t.id = 6 m.add_task(t) t.id = 9 m.add_task(t) self.assertEqual(m.find_free_id(), 0) t.id = 0 m.add_task(t) self.assertEqual(m.find_free_id(), 2)
def add_empty_task(self): m = Model() self.assertEqual(m.add_empty_task(), 0) m.add_empty_task() m.add_empty_task() m.add_empty_task() self.assertEqual(m.add_empty_task(), 4) t = Task() t.id = 5 m.add_task(t) t.id = 6 m.add_task(t) self.assertEqual(m.add_empty_task(), 7)
def test_save_load_tasks(self): m = Model() t = Task() m.add_task(t) m.add_task(t) m.add_task(t) m.add_task(t) m.add_task(t) m.settings['db_path'] = "test_db.txt" m.save_tasks() m2 = Model() m2.settings['db_path'] = "test_db.txt" m2.load_tasks() self.assertEqual(m.tasks, m2.tasks)
t6 = Task() t6.set_content("""Calls pharmacies to refill prescriptions""") t6.set_status(TaskStatus.DONE) t6.id = 6 t7 = Task() t7.set_content("""Meet David at 11:00""") t7.set_status(TaskStatus.DONE) t7.id = 7 t8 = Task() t8.set_content("""Call to Mary till tomorrow""") t8.set_status(TaskStatus.TODO) t8.id = 10 m = Model() m.add_task(t1) m.add_task(t2) m.add_task(t3) m.add_task(t4) m.add_task(t5) m.add_task(t6) m.add_task(t7) m.add_task(t8) m.settings['db_path'] = 'database.dat' m.save_settings() # it overwrites "settings.dat" m.save_tasks() debug.print_database('database.dat')