MCPcopy
hub / github.com/nltk/nltk / check_reader

Function check_reader

nltk/test/unit/test_seekable_unicode_stream_reader.py:9–32  ·  view source on GitHub ↗
(unicode_string, encoding)

Source from the content-addressed store, hash-verified

7
8
9def check_reader(unicode_string, encoding):
10 bytestr = unicode_string.encode(encoding)
11 stream = BytesIO(bytestr)
12 reader = SeekableUnicodeStreamReader(stream, encoding)
13
14 # Should open at the start of the file
15 assert reader.tell() == 0
16
17 # Compare original string to contents from `.readlines()`
18 assert unicode_string == "".join(reader.readlines())
19
20 # Should be at the end of the file now
21 stream.seek(0, os.SEEK_END)
22 assert reader.tell() == stream.tell()
23
24 reader.seek(0) # go back to start
25
26 # Compare original string to contents from `.read()`
27 contents = ""
28 char = None
29 while char != "":
30 char = reader.read(1)
31 contents += char
32 assert unicode_string == contents
33
34
35# Call `check_reader` with a variety of input strings and encodings.

Callers 1

test_readerFunction · 0.85

Calls 7

tellMethod · 0.95
readlinesMethod · 0.95
seekMethod · 0.95
readMethod · 0.95
encodeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…