def test(config, expected_calls=[]): with test_app(config) as app: for item in config.split(): if "(" in item: editor = test_app(app).get(item) if "/doc.save" in editor.file_path: test_app(app).set_content(editor) make_dirty(editor.document) calls = [] def callback(ok): calls.append(ok) answer = app.should_terminate(callback) eq_(answer, (callback if calls else True)) eq_(calls, expected_calls)
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 test(config, prompt=[], dirty=False, close=True): calls = [] def callback(): calls.append(True) with test_app(config) as app: window = app.windows[0] editor = window.current_editor if "/doc.save" in editor.file_path: test_app(app).set_content(editor) if dirty: make_dirty(editor.document) editor.interactive_close(callback) eq_(calls, [True] if close else []) eq_(window.wc.prompts, prompt) post_config = "window project " + config eq_(test_app(app).state, post_config)
def test(c): with test_app(c.app) as app: m = Mocker() teardown_main_view = m.replace(mod, 'teardown_main_view') window = app.windows[0] editor = window.projects[0].editors[0] make_dirty(editor.document) assert window.is_dirty editor.text_view = None if c.tv_is_none else m.mock(ak.NSTextView) doc = editor.document undo = editor.undo_manager if c.ts_is_none: doc.text_storage = None else: with replattr(doc, 'reset_text_attributes', lambda *a: None, sigcheck=False): text_storage = doc.text_storage #text_storage.setDelegate_(doc) remove_layout = m.method(text_storage.removeLayoutManager_) if not (c.tv_is_none or c.ts_is_none): lm = editor.text_view.layoutManager() >> m.mock(ak.NSLayoutManager) remove_layout(lm) if c.main_is_none: editor.main_view = None else: editor.main_view = m.mock() teardown_main_view(editor.main_view) assert editor.on_dirty_status_changed in undo.callbacks.items with m: editor.close() if next(window.iter_editors_of_document(doc), None) is not None: assert window.is_dirty else: assert not window.is_dirty eq_(editor.command_view, None) eq_(editor.scroll_view, None) eq_(editor.text_view, None) eq_(editor.document, None) eq_(editor.proxy, None) assert editor.on_dirty_status_changed not in undo.callbacks.items if c.close_doc: eq_(doc.text_storage, None) #if not c.ts_is_none: #eq_(text_storage.delegate(), None) else: assert doc.text_storage is not None eq_(test_app(app).state, c.end)
def test(config, prompt=[], close=True): calls = [] def callback(): calls.append(True) with test_app(config) as app: window = app.windows[0] project = window.projects[0] for editor in project.editors: if "/dirty.save" in editor.file_path: test_app(app).set_content(editor) if "dirty" in editor.document.file_path: make_dirty(editor.document) project.interactive_close(callback) post_config = config.split() if prompt: post_config[0] += "*" eq_(test_app(app).state, "window project " + " ".join(post_config)) eq_(window.wc.prompts, prompt) eq_(calls, [close] if close else [])