Beispiel #1
0
 def test(c):
     m = Mocker()
     fc = FindController.create()
     flog = m.replace("editxt.findpanel.log", passthrough=False)
     sender = m.mock()
     (sender.tag() << c.tag).count(1, 2)
     func = None
     for tag, meth in list(fc.action_registry.items()):
         if tag == c.tag:
             func = m.replace(meth, passthrough=False)
         else:
             fc.action_registry[tag] = m.mock(meth)
     if c.fail:
         flog.info(ANY, c.tag)
     else:
         func(sender)
     with m:
         fc.perform_action(sender)
Beispiel #2
0
 def test(c):
     m = Mocker()
     fc = FindController.create()
     fc.opts = opts = FindOptions()
     opts.find_text = c.astate.get("find_text", u"")
     nsud = m.replace(NSUserDefaults)
     nspb = m.replace(NSPasteboard)
     if "find_text" in c.astate:
         pboard = nspb.pasteboardWithName_(NSFindPboard)
         pboard.declareTypes_owner_([NSStringPboardType], None)
         pboard.setString_forType_(c.astate["find_text"], NSStringPboardType)
     zstate = {}
     for k, v in FindController.OPTIONS_DEFAULTS.iteritems():
         setattr(opts, k, c.astate.get(k, v))
         zstate[k] = c.zstate.get(k, v)
     defaults = nsud.standardUserDefaults() >> m.mock(NSUserDefaults)
     def do(state, key):
         eq_(state, zstate)
         return True
     expect(defaults.setObject_forKey_(ANY, const.FIND_PANEL_OPTIONS_KEY)).call(do)
     with m:
         fc.save_options()
Beispiel #3
0
 def test(c):
     m = Mocker()
     nsud = m.replace(NSUserDefaults, passthrough=False)
     nspb = m.replace(NSPasteboard, passthrough=False)
     defaults = nsud.standardUserDefaults() >> m.mock(NSUserDefaults)
     defaults.dictionaryForKey_(const.FIND_PANEL_OPTIONS_KEY) >> c.state
     pboard = nspb.pasteboardWithName_(NSFindPboard)
     pboard.availableTypeFromArray_([NSStringPboardType]) >> c.has_ftext
     if c.has_ftext:
         pboard.stringForType_(NSStringPboardType) >> c.ftext
     with m:
         fc = FindController.create() # calls load_options()
         opts = fc.opts
         if c.state is not None:
             for k, v in FindController.OPTIONS_DEFAULTS.iteritems():
                 eq_(getattr(opts, k), c.state.get(k, v), k)
         assert isinstance(opts.recent_finds, NSMutableArray)
         assert isinstance(opts.recent_replaces, NSMutableArray)
         if c.has_ftext:
             eq_(opts.find_text, c.ftext)
         else:
             eq_(opts.find_text, u"")