Shows a unified_diff for the provided input and output against the provided file path. - **file_input**: A string that represents the contents of a file before changes. - **file_output**: A string that represents the contents of a file after changes. - **file_path**: A Path object that
(
*,
file_input: str,
file_output: str,
file_path: Path | None,
output: TextIO | None = None,
color_output: bool = False,
)
| 41 | |
| 42 | |
| 43 | def show_unified_diff( |
| 44 | *, |
| 45 | file_input: str, |
| 46 | file_output: str, |
| 47 | file_path: Path | None, |
| 48 | output: TextIO | None = None, |
| 49 | color_output: bool = False, |
| 50 | ) -> None: |
| 51 | """Shows a unified_diff for the provided input and output against the provided file path. |
| 52 | |
| 53 | - **file_input**: A string that represents the contents of a file before changes. |
| 54 | - **file_output**: A string that represents the contents of a file after changes. |
| 55 | - **file_path**: A Path object that represents the file path of the file being changed. |
| 56 | - **output**: A stream to output the diff to. If non is provided uses sys.stdout. |
| 57 | - **color_output**: Use color in output if True. |
| 58 | """ |
| 59 | printer = create_terminal_printer(color_output, output) |
| 60 | file_name = "" if file_path is None else str(file_path) |
| 61 | file_mtime = str( |
| 62 | datetime.now() if file_path is None else datetime.fromtimestamp(file_path.stat().st_mtime) |
| 63 | ) |
| 64 | unified_diff_lines = unified_diff( |
| 65 | file_input.splitlines(keepends=True), |
| 66 | file_output.splitlines(keepends=True), |
| 67 | fromfile=file_name + ":before", |
| 68 | tofile=file_name + ":after", |
| 69 | fromfiledate=file_mtime, |
| 70 | tofiledate=str(datetime.now()), |
| 71 | ) |
| 72 | for line in unified_diff_lines: |
| 73 | printer.diff_line(line) |
| 74 | |
| 75 | |
| 76 | def ask_whether_to_apply_changes_to_file(file_path: str) -> bool: |
no test coverage detected
searching dependent graphs…