def test_sort_method(self):
     """ Test self.sort() method. """
     test_file = FileAsObj()
     test_file.sorted = False
     test_file.add('3')
     test_file.add('2')
     test_file.add('1')
     self.assertTrue(test_file.changed)
     self.assertIsNone(test_file.sort())
     self.assertTrue(test_file.contents == ['1', '2', '3'])
示例#2
0
def example_sort_in_place():
    """ To sort contents in place after the file is read. """
    my_file = FileAsObj('/tmp/example_file.txt')
    my_file.sort()