def test_set_current_editor(): ac = Application() m = Mocker() editor = m.mock(Editor) ac.find_window_with_editor = m.method(ac.find_window_with_editor) ed = ac.find_window_with_editor(editor) >> m.mock(Window) ed.current_editor = editor with m: ac.set_current_editor(editor)
def test(config): """Test argument structure: [ # collection of window controllers [ # window controller / collection of projects ["doc1", "doc2", "doc3", ...], # project / collection of editors ... ] ... ] """ result = None ac = Application() m = Mocker() editor = m.mock(Editor) # this is the editor we're looking for document = m.mock(TextDocument) (editor.document << document).count(0, None) ac.iter_windows = m.method(ac.iter_windows) eds = ac.iter_windows() >> [] for ed_projects in config: ed = m.mock(Window) eds.append(ed) projects = [] ed.projects >> projects found = False for project_editors in ed_projects: project = m.mock(Project) projects.append(project) editors = [] if not found: project.editors >> editors for doc_name in project_editors: if doc_name == DOC: editors.append(editor) result = ed found = True else: editors.append(m.mock(Editor)) with m: ed = ac.find_window_with_editor(editor) eq_(ed, result)