def test(msg, has_path=False): with test_app("editor") as app: editor = app.windows[0].projects[0].editors[0] if has_path: path = editor.file_path = "/file-that-does-not-exist.not" msg = msg.format(path) if editor.file_path and os.path.exists(editor.file_path): raise RuntimeError("cannot run test because file exists: {}" .format(editor.file_path)) msg.format(editor.file_path) m = Mocker() with m, assert_raises(mod.CommandError, msg=msg): mod.diff(editor, None)
def test(original, config="editor"): diffed = [] text_name = "file.txt" rm = [] def diff_stub(path1, path2, diff_program, remove=None): for path in remove: os.remove(path) eq_(path1, path_1) eq_(path2, path_2) eq_(diff_program, "opendiff") diffed.append(1) with tempdir() as tmp, test_app(config) as app, \ replattr(mod, "external_diff", diff_stub): window = app.windows[0] editor = text_editor = window.projects[0].editors[0] if config == "editor": path = editor.file_path = join(tmp, "file.txt") with open(path, mode="w", encoding="utf8") as fh: fh.write("abc") m = Mocker() text_view = editor.text_view = m.mock(TextView) path_1 = editor.file_path if original: make_dirty(editor.document) name_ext = splitext(test_app(app).name(editor)) path_2 = Regex(r"/file-.*\.txt$") args = None text_view.string() >> "def" elif len(window.selected_items) == 2: editor2 = window.selected_items[1] editor2.text_view = m.mock(TextView) name_ext = splitext(test_app(app).name(editor)[7:-1]) path_1 = Regex(r"/{}-.*{}$".format(*name_ext)) name_ext = splitext(test_app(app).name(editor2)[7:-1]) path_2 = Regex(r"/{}-.*{}$".format(*name_ext)) args = None text_view.string() >> "def" editor2.text_view.string() >> "ghi" else: path_1 = join(tmp, "other.txt") path_2 = editor.file_path with open(path_1, mode="w", encoding="utf8") as fh: fh.write("other") assert " " not in path_1, path_1 args = mod.diff.arg_parser.parse(path_1) with m: mod.diff(editor, args) assert diffed
def diff_with_original(): from editxt.command.diff import diff from editxt.command.parser import Options diff(editor, Options(file=editor.file_path))
def diff_with_original(): from editxt.command.diff import diff save_with_path(None) # cancel save operation diff(editor.text_view, self, None)