def test_empty_file(self): """ make sure an empty file does not throw an error when reverse_readline is called this was a problem with an earlier implementation """ with open(os.path.join(test_dir, "empty_file.txt")) as f: for idx, line in enumerate(reverse_readline(f)): raise ValueError("an empty file is being read!")
def test_reverse_readline(self): """ We are making sure a file containing line numbers is read in reverse order, i.e. the first line that is read corresponds to the last line. number """ with open(os.path.join(test_dir, "three_thousand_lines.txt")) as f: for idx, line in enumerate(reverse_readline(f)): self.assertEqual(int(line), self.NUMLINES - idx, "read_backwards read {} whereas it should " "have read {}".format( int(line), self.NUMLINES - idx))
def test_reverse_readline(self): """ We are making sure a file containing line numbers is read in reverse order, i.e. the first line that is read corresponds to the last line. number """ with open(os.path.join(test_dir, "three_thousand_lines.txt")) as f: for idx, line in enumerate(reverse_readline(f)): self.assertEqual( int(line), self.NUMLINES - idx, "read_backwards read {} whereas it should " "have read {}".format(int(line), self.NUMLINES - idx))