def test(config): """Test argument structure: [ # collection of window controllers [ # window controller / collection of projects ["doc1", "doc2", "doc3", ...], # project / collection of documents ... ] ... ] """ result = None ac = Application() m = Mocker() dv = m.mock(TextDocumentView) # this is the view we're looking for document = m.mock(TextDocument) (dv.document << document).count(0, None) ac.iter_editors = m.method(ac.iter_editors) eds = ac.iter_editors() >> [] for ed_projects in config: ed = m.mock(Editor) eds.append(ed) projects = [] ed.projects >> projects found = False for project_documents in ed_projects: project = m.mock(Project) projects.append(project) documents = [] if not found: project.documents() >> documents for doc_name in project_documents: if doc_name == DOC: documents.append(dv) result = ed found = True else: documents.append(m.mock(TextDocumentView)) with m: ed = ac.find_editor_with_document_view(dv) eq_(ed, result)
def test(config): """Test argument structure: [ # collection of window controllers [ # window controller / collection of projects ["doc1", "doc2", "doc3", ...], # project / collection of documents ... ] ... ] """ result = None ac = Application() m = Mocker() dv = m.mock(TextDocumentView) # this is the view we're looking for document = m.mock(TextDocument) (dv.document << document).count(0, None) ac.iter_editors = m.method(ac.iter_editors) eds = ac.iter_editors() >> [] for ed_projects in config: ed = m.mock(Editor) eds.append(ed) projects = [] ed.projects >> projects found = False for project_documents in ed_projects: project = m.mock(Project) projects.append(project) documents = [] if not found: project.documents() >> documents for doc_name in project_documents: if doc_name == DOC: documents.append(dv) result = ed found = True else: documents.append(m.mock(TextDocumentView)) with m: ed = ac.find_editor_with_document_view(dv) eq_(ed, result)
def test(config, unordered=0): """ config - represents a list of window controllers in on-screen z-order with the front-most window controller first. Key: None - generic NSWindowController (not EditorWindowController) <int> - Editor index in ac.editors unordered - (optional, default 0) number of editors in ac.editors that are not in the on-screen z-order window list. """ ac = Application() m = Mocker() app_class = m.replace(ak, 'NSApp') app = app_class() eds = {} unordered_eds = [] z_windows = [] for item in config: if item is None: wc = m.mock(ak.NSWindowController) else: wc = m.mock(EditorWindowController) ed = m.mock(Editor) print(ed, item) if item != 7: (wc.editor << ed).count(3) unordered_eds.append(ed) else: wc.editor >> ed eds[item] = ed win = m.mock(ak.NSWindow) win.windowController() >> wc z_windows.append(win) for x in range(unordered): unordered_eds.append(m.mock(Editor)) ac.editors = unordered_eds # + [v for k, v in sorted(eds.items())] app.orderedWindows() >> z_windows sorted_eds = [eds[i] for i in config if i not in (None, 7)] sorted_eds.extend(ed for ed in unordered_eds if ed not in sorted_eds) with m: result = list(ac.iter_editors()) eq_(result, sorted_eds)
def test(config, unordered=0): """ config - represents a list of window controllers in on-screen z-order with the front-most window controller first. Key: None - generic NSWindowController (not EditorWindowController) <int> - Editor index in ac.editors unordered - (optional, default 0) number of editors in ac.editors that are not in the on-screen z-order window list. """ ac = Application() m = Mocker() app_class = m.replace(ak, 'NSApp') app = app_class() eds = {} unordered_eds = [] z_windows = [] for item in config: if item is None: wc = m.mock(ak.NSWindowController) else: wc = m.mock(EditorWindowController) ed = m.mock(Editor) print(ed, item) if item != 7: (wc.editor << ed).count(3) unordered_eds.append(ed) else: wc.editor >> ed eds[item] = ed win = m.mock(ak.NSWindow) win.windowController() >> wc z_windows.append(win) for x in range(unordered): unordered_eds.append(m.mock(Editor)) ac.editors = unordered_eds # + [v for k, v in sorted(eds.items())] app.orderedWindows() >> z_windows sorted_eds = [eds[i] for i in config if i not in (None, 7)] sorted_eds.extend(ed for ed in unordered_eds if ed not in sorted_eds) with m: result = list(ac.iter_editors()) eq_(result, sorted_eds)