Beispiel #1
0
 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)
Beispiel #2
0
 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 WindowController)
             <int> - Window index in ac.windows
     unordered - (optional, default 0) number of windows in
         ac.windows 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(WindowController)
             ed = m.mock(Window)
             print(ed, item)
             if item != 7:
                 (wc.window_ << ed).count(3)
                 unordered_eds.append(ed)
             else:
                 wc.window_ >> 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(Window))
     ac.windows = 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_windows())
     eq_(result, sorted_eds)