Utility classes and functions¶
- class mtrchk.org.momotor.evaluate.compare.level.CompareLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Enum to indicate the difference between two strings.
- BLANK_LINES = 'blank'¶
The two strings compare identical except for case, whitespace, and blank lines.
- CASE = 'case'¶
The two strings compare identical except for case.
- DIFFERENT = 'different'¶
The two strings compare different
- IDENTICAL = 'identical'¶
The two strings compare identical.
- WHITESPACE = 'whitespace'¶
The two strings compare identical except for case and whitespace.
- mtrchk.org.momotor.evaluate.compare.mixin.casefold(line)¶
Fold the casefor the given line.
- mtrchk.org.momotor.evaluate.compare.mixin.collapse_ws(line)¶
Collapse all whitespace in the given line to a single space.
- mtrchk.org.momotor.evaluate.compare.mixin.compare_streams(left, right, *, ignore_last_newline=False, ignore_trailing_whitespace=False, sort_left=False, sort_right=False, encoding=None)¶
Compare two files as efficient as possible.
Consumes each stream line-by-line if no sorting is required, otherwise reads the entire file into memory, sorts it, and then compares the sorted lines.
Returns a
CompareLevelindicating the amount of difference between the two streams.- Parameters:
left (
File) – first streamright (
File) – second streamignore_last_newline (
bool)ignore_trailing_whitespace (
bool)sort_left (
str|bool|None) – Sort the left file before comparisonsort_right (
str|bool|None) – Sort the right file before comparisonencoding (
str|None) – Encoding to use for reading the files
- Return type:
- Returns:
The level of difference
- mtrchk.org.momotor.evaluate.compare.mixin.get_sort_fn(sort_opt)¶
Return a sort function based on the given option value.
sort_opt is either a boolean value (
yes,no,true,false, etc.), orhuman,nat,os,realto sort using a natural sort algorithm.See the documentation of the natsort package for details on the natural sort algorithms.
- mtrchk.org.momotor.evaluate.compare.mixin.iter_file(stream)¶
Iterate over the given stream, yielding lines without trailing newlines.
The return value of the generator (available as
StopIteration.value) is a boolean, indicating whether the final line ended with a newline.
- mtrchk.org.momotor.evaluate.compare.mixin.iter_sorted(stream, sort_fn)¶
Iterate over the given stream, yielding lines without trailing newlines, sorted by the given function.
The return value of the generator (available as
StopIteration.value) is a boolean, indicating whether the final line ended with a newline.
- mtrchk.org.momotor.evaluate.compare.mixin.rstrip(line)¶
Strip trailing whitespace from the given line.