def test_tail(self): """ Exercise our tail() function with a variety of inputs. """ path = os.path.join(os.path.dirname(__file__), 'text_file') # by file handle with open(path, 'rb') as riddle_file: self.assertEqual([' both the wicked and sweet.'], list(system.tail(riddle_file, 1))) self.assertEqual([], list(system.tail(path, 0))) self.assertEqual([' both the wicked and sweet.'], list(system.tail(path, 1))) self.assertEqual( [' both the wicked and sweet.', "but I'm with people you meet"], list(system.tail(path, 2))) self.assertEqual(14, len(list(system.tail(path)))) self.assertEqual(14, len(list(system.tail(path, 200)))) self.assertRaises(IOError, list, system.tail('/path/doesnt/exist')) fd, temp_path = tempfile.mkstemp() os.chmod(temp_path, 0o077) # remove read permissions self.assertRaises(IOError, list, system.tail(temp_path)) os.close(fd) os.remove(temp_path)
def test_tail(self): """ Exercise our tail() function with a variety of inputs. """ path = os.path.join(os.path.dirname(__file__), 'text_file') # by file handle with open(path, 'rb') as riddle_file: self.assertEqual([' both the wicked and sweet.'], list(system.tail(riddle_file, 1))) self.assertEqual([], list(system.tail(path, 0))) self.assertEqual([' both the wicked and sweet.'], list(system.tail(path, 1))) self.assertEqual([' both the wicked and sweet.', "but I'm with people you meet"], list(system.tail(path, 2))) self.assertEqual(14, len(list(system.tail(path)))) self.assertEqual(14, len(list(system.tail(path, 200)))) self.assertRaises(IOError, list, system.tail('/path/doesnt/exist')) fd, temp_path = tempfile.mkstemp() os.chmod(temp_path, 0o077) # remove read permissions self.assertRaises(IOError, list, system.tail(temp_path)) os.close(fd) os.remove(temp_path)