Compare two files as text, optionally filtering local content.
(
cpython_path: pathlib.Path,
local_path: pathlib.Path,
*,
local_filter: Callable[[str], str] | None = None,
encoding: str = "utf-8",
)
| 243 | |
| 244 | |
| 245 | def compare_file_contents( |
| 246 | cpython_path: pathlib.Path, |
| 247 | local_path: pathlib.Path, |
| 248 | *, |
| 249 | local_filter: Callable[[str], str] | None = None, |
| 250 | encoding: str = "utf-8", |
| 251 | ) -> bool: |
| 252 | """Compare two files as text, optionally filtering local content.""" |
| 253 | try: |
| 254 | cpython_content = cpython_path.read_text(encoding=encoding) |
| 255 | local_content = local_path.read_text(encoding=encoding) |
| 256 | except (OSError, UnicodeDecodeError): |
| 257 | return False |
| 258 | |
| 259 | if local_filter is not None: |
| 260 | local_content = local_filter(local_content) |
| 261 | |
| 262 | return cpython_content == local_content |
| 263 | |
| 264 | |
| 265 | def compare_dir_contents( |
no test coverage detected