MCPcopy Index your code
hub / github.com/pathwaycom/pathway / FileLinesNumberChecker

Class FileLinesNumberChecker

python/pathway/tests/utils.py:430–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428
429
430class FileLinesNumberChecker:
431 def __init__(self, path: pathlib.Path, n_lines: int):
432 self.expected_states = [(path, n_lines)]
433
434 def add_path(self, path: pathlib.Path, n_lines: int) -> FileLinesNumberChecker:
435 self.expected_states.append((path, n_lines))
436 return self
437
438 def __call__(self) -> bool:
439 for path, n_lines in self.expected_states:
440 if not path.exists():
441 return False
442 n_lines_actual = 0
443 with open(path) as f:
444 for row in f:
445 n_lines_actual += 1
446 print(
447 f"Actual (expected) lines number: {n_lines_actual} ({n_lines})",
448 file=sys.stderr,
449 )
450 if n_lines_actual != n_lines:
451 return False
452 return True
453
454 def provide_information_on_failure(self) -> str:
455 result = []
456 for path, _ in self.expected_states:
457 if path.exists():
458 with open(path, encoding="utf-8") as f:
459 lines = f.readlines()
460 total_lines = len(lines)
461 if total_lines > 50:
462 result.append(
463 f"Final output contents for {path}:\n{total_lines} lines"
464 )
465 else:
466 result.append(
467 f"Final output contents for {path}:\n{''.join(lines)}"
468 )
469 else:
470 result.append(f"{path} does not exist")
471 return "\n".join(result)
472
473
474def expect_csv_checker(expected, output_path, usecols=("k", "v"), index_col=("k")):

Calls

no outgoing calls