def test_nothing(): print "Testing Nothing" s = "This is a test.\nThis is only a test.\nHad this been an actual...\n" for ending in ("\n", "\r", "\r\n"): data = string.replace(s, "\n", ending) for look in (0, 1, 2, 5): reader = RecordReader.Nothing(StringIO(data[look:]), sizehint=1, lookahead=data[:look]) rec = reader.next() assert rec is None, "should be empty, not %r" % rec rec = reader.next() assert rec is None, "2nd time should also be empty, not %r" % rec infile, remainder = reader.remainder() remainder = remainder + infile.read() assert remainder == data, "Why %r when input was %r?" % \ (remainder, data)
def test_nothing_lines(): lookahead = "1\n2\n3\n4\n5\n6\n7\n8\n" reader = RecordReader.Nothing(StringIO(""), lookahead = lookahead) assert test_count(reader, check_remainder = 0) == 0 file, result = reader.remainder() assert result == lookahead, (result, lookahead)
def test_nothing(): s = "1\n2\n3\n4\n5\n6\n7\n8\n" infile = StringIO(s) reader = RecordReader.Nothing(infile) assert test_count(reader, check_remainder = 0) == 0 assert infile.readline() == "1\n"