intercom_test.augmentation.origin_mapping_stream module¶
-
class
intercom_test.augmentation.origin_mapping_stream.
OriginMapper
(mapper)[source]¶ Bases:
object
-
corrections
¶
-
discontinuities
¶
-
tell_of_chr
(n)[source]¶ Given a character index, compute the byte index in the source file
Due to character encodings and line-ending conventions, each character produced from a stream comes from one or more bytes in the input file. Partial-reading a YAML file requires knowing the exact byte offset into the file at which to start. This function allows “back mapping” from the
index
in a YAML event’sstart_mark
to the byte offset within the file.
-
-
intercom_test.augmentation.origin_mapping_stream.
open
(path: os.PathLike, *, buffer_size: int = 8192) → io.TextIOBase[source]¶ Open a UTF-8 encoded file for reading with origin-byte tracking
Parameters: - path – file path to open, like
io.open()
- buffer_size – size of buffer to use for
io.BufferedReader
Returns: text reader with an
origin_mapper
To correctly jump to the starting point of a test case,
intercom_test
needs the byte offset in the file, while the YAML parser reports position in terms of characters. This requires taking the text encoding into account. To do this efficiently, the object returned by this function provides anorigin_mapper
, which is anOriginMapper
instance.As a consequence of needing to start in the middle of the file, the only Unicode encoding that can be supported is UTF-8.
The stream does not currently support seeking forward.
- path – file path to open, like