def test_bound_builtin_functions(self): import IronPythonTest d = {} func = d.setdefault args = EventArgs() ev = IronPythonTest.Events() ev.InstanceOther += func ev.CallOtherInstance('abc', args) self.assertEqual(d, {'abc': args}) ev.InstanceOther -= func ev.CallOtherInstance('def', args) self.assertEqual(d, {'abc': args}) d.clear() ev.InstanceOther += IronPythonTest.OtherEvent(func) ev.CallOtherInstance('abc', args) self.assertEqual(d, {'abc': args}) ev.InstanceOther -= IronPythonTest.OtherEvent(func) ev.CallOtherInstance('def', args) self.assertEqual(d, {'abc': args})
def run_muf_script(menu_location, timeit=True): """Opens a vnauncert or vnauncert_archive and runs it as is.""" start = datetime.datetime.utcnow() sys.path.append(SCRIPTABLE_MUF_LOCATION) clr.AddReference("VNAUncertainty") import VNAUncertainty from System import EventArgs, Object event = EventArgs() vna = VNAUncertainty.VNAUncertainty() vna.OnLoad(event) vna.myOpenMenu(menu_location) vna.OnLocationChanged(event) vna.RunCalibration(0) vna.Close() if timeit: stop = datetime.datetime.utcnow() runtime = stop - start print(("VNAUncertainty finished running at {0}".format(stop))) print( ("The script took {0} seconds to run".format(runtime.seconds)))
def test_delegate_combinations(self): """test various combinations of delegates...""" import IronPythonTest global glblSelf, glblArgs, handlerCalled dlgTst = IronPythonTest.DelegateTest() def Handler(slf, args): global glblSelf, glblArgs, handlerCalled self.assertEqual(slf, glblSelf) self.assertEqual(args, glblArgs) handlerCalled = True # check the methods w/ object sender, EventArgs sigs first... glblSelf = 0 for x in [(IronPythonTest.DelegateTest.StaticEvent, IronPythonTest.DelegateTest.FireStatic), (dlgTst.Event, dlgTst.FireInstance), (IronPythonTest.DelegateTest.StaticGenericEvent, IronPythonTest.DelegateTest.FireGenericStatic), (dlgTst.GenericEvent, dlgTst.FireGeneric)]: event, fire = x[0], x[1] event += Handler glblSelf = glblSelf + 1 glblArgs = EventArgs() handlerCalled = False fire(glblSelf, glblArgs) self.assertEqual(handlerCalled, True) event -= Handler def ParamsHandler(slf, args): global glblSelf, glblArgs, handlerCalled self.assertEqual(slf, glblSelf) self.assertEqual(tuple(args), tuple(range(glblArgs))) handlerCalled = True for x in [(IronPythonTest.DelegateTest.StaticParamsEvent, IronPythonTest.DelegateTest.FireParamsStatic), (dlgTst.ParamsEvent, dlgTst.FireParams)]: event, fire = x[0], x[1] event += ParamsHandler glblSelf = glblSelf + 1 for x in range(6): handlerCalled = False glblArgs = x fire(glblSelf, *tuple(range(x))) self.assertEqual(handlerCalled, True) event -= ParamsHandler def BigParamsHandler(slf, a, b, c, d, args): global glblSelf, glblArgs, handlerCalled self.assertEqual(slf, glblSelf) self.assertEqual(tuple(args), tuple(range(glblArgs))) self.assertEqual(a, 1) self.assertEqual(b, 2) self.assertEqual(c, 3) self.assertEqual(d, 4) handlerCalled = True for x in [(IronPythonTest.DelegateTest.StaticBigParamsEvent, IronPythonTest.DelegateTest.FireBigParamsStatic), (dlgTst.BigParamsEvent, dlgTst.FireBigParams)]: event, fire = x[0], x[1] event += BigParamsHandler glblSelf = glblSelf + 1 for x in range(6): handlerCalled = False glblArgs = x fire(glblSelf, 1, 2, 3, 4, *tuple(range(x))) self.assertEqual(handlerCalled, True) event -= BigParamsHandler # out param def OutHandler(sender, ret): global glblSelf, handlerCalled self.assertEqual(sender, glblSelf) handlerCalled = True ret.Value = 23 for x in [(IronPythonTest.DelegateTest.StaticOutEvent, IronPythonTest.DelegateTest.FireOutStatic), (dlgTst.OutEvent, dlgTst.FireOut)]: event, fire = x[0], x[1] event += OutHandler glblSelf = glblSelf + 1 handlerCalled = False self.assertEqual(fire(glblSelf), 23) self.assertEqual(handlerCalled, True) event -= OutHandler # ref param def RefHandler(sender, refArg): global glblSelf, handlerCalled self.assertEqual(sender, glblSelf) self.assertEqual(refArg.Value, 42) handlerCalled = True refArg.Value = 23 for x in [(IronPythonTest.DelegateTest.StaticRefEvent, IronPythonTest.DelegateTest.FireRefStatic), (dlgTst.RefEvent, dlgTst.FireRef)]: event, fire = x[0], x[1] event += RefHandler glblSelf = glblSelf + 1 handlerCalled = False self.assertEqual(fire(glblSelf, 42), 23) self.assertEqual(handlerCalled, True) event -= RefHandler # out w/ return type def OutHandler(sender, ret): global glblSelf, handlerCalled self.assertEqual(sender, glblSelf) handlerCalled = True ret.Value = 42 return "23" for x in [(IronPythonTest.DelegateTest.StaticOutReturnEvent, IronPythonTest.DelegateTest.FireOutReturnStatic), (dlgTst.OutReturnEvent, dlgTst.FireOutReturn)]: event, fire = x[0], x[1] event += OutHandler glblSelf = glblSelf + 1 handlerCalled = False self.assertEqual(fire(glblSelf), ("23", 42)) self.assertEqual(handlerCalled, True) event -= OutHandler # ref w/ a return type def RefHandler(sender, refArg): global glblSelf, handlerCalled self.assertEqual(sender, glblSelf) self.assertEqual(refArg.Value, 42) handlerCalled = True refArg.Value = 42 return 23 for x in [(IronPythonTest.DelegateTest.StaticRefReturnEvent, IronPythonTest.DelegateTest.FireRefReturnStatic), (dlgTst.RefReturnEvent, dlgTst.FireRefReturn)]: event, fire = x[0], x[1] event += RefHandler glblSelf = glblSelf + 1 handlerCalled = False self.assertEqual(fire(glblSelf, 42), (23, 42)) self.assertEqual(handlerCalled, True) event -= RefHandler
# check the methods w/ object sender, EventArgs sigs first... glblSelf = 0 for x in [(IronPythonTest.DelegateTest.StaticEvent, IronPythonTest.DelegateTest.FireStatic), (dlgTst.Event, dlgTst.FireInstance), (IronPythonTest.DelegateTest.StaticGenericEvent, IronPythonTest.DelegateTest.FireGenericStatic), (dlgTst.GenericEvent, dlgTst.FireGeneric)]: event, fire = x[0], x[1] event += Handler glblSelf = glblSelf + 1 glblArgs = EventArgs() handlerCalled = False fire(glblSelf, glblArgs) AreEqual(handlerCalled, True) event -= Handler def ParamsHandler(self, args): global glblSelf, glblArgs, handlerCalled AreEqual(self, glblSelf) AreEqual(tuple(args), tuple(range(glblArgs))) handlerCalled = True
def Hint(form): comboBoxType = form.Controls[0].Controls[0].Controls[0].Controls[3] comboBoxType.SelectedIndexChanged += showHint evarg = EventArgs() showHint(comboBoxType, evarg)