def test_write_to_file(self): todo_text = "(A) Do one thing\n (B) Do another thing\n x One last thing" expected_output = "(A) Do one thing\n(B) Do another thing\nx One last thing" test_list = TodoTxtList(None, todo_text) # Write to a temporary output file: output_file = tempfile.NamedTemporaryFile(mode='w+') test_list.todo_filename = output_file.name test_list.write_to_file() # Now read the file in and see that it all matches up: self.assertEqual(expected_output, output_file.read())
def test_reload_from_file(self): test_list = TodoTxtList() # Start with an empty list test_list.reload_from_file() # Should do nothing test_list.todo_filename = 'sample-todo.txt' test_list.reload_from_file() self.assertEqual(8, test_list.num_items()) self.assertEqual('Do that really important thing', test_list.items[0].text) self.assertEqual('A', test_list.items[0].priority) self.assertFalse(test_list.items[0].is_completed) self.assertEqual('Summon AppIndicator documentation from my ass', test_list.items[1].text) self.assertEqual('D', test_list.items[1].priority) self.assertFalse(test_list.items[1].is_completed) self.assertEqual('This other important thing', test_list.items[2].text) self.assertEqual('A', test_list.items[2].priority) self.assertFalse(test_list.items[2].is_completed) self.assertEqual('Walk the cat', test_list.items[3].text) self.assertEqual('B', test_list.items[3].priority) self.assertFalse(test_list.items[3].is_completed) self.assertEqual('Something with no priority!', test_list.items[4].text) self.assertEqual(None, test_list.items[4].priority) self.assertFalse(test_list.items[4].is_completed) self.assertEqual('Cook the dog', test_list.items[5].text) self.assertEqual('C', test_list.items[5].priority) self.assertFalse(test_list.items[5].is_completed) self.assertEqual('Be annoyed at GTK3 docs', test_list.items[6].text) self.assertEqual(None, test_list.items[6].priority) self.assertTrue(test_list.items[6].is_completed) self.assertEqual('Something I already did', test_list.items[7].text) self.assertEqual(None, test_list.items[7].priority) self.assertTrue(test_list.items[7].is_completed)