public void testFunctionalityOfPythonRuleItem() { ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filename); testItem.pinInfo["myInputPin"].value.data = false; testItem.evaluate(); Assert.IsTrue((testItem.pinInfo["myOutputPin"].value.asBoolean()) == false); testItem.pinInfo["myInputPin"].value.data = true; testItem.evaluate(); Assert.IsTrue((testItem.pinInfo["myOutputPin"].value.asBoolean()) == true); }
public void testFunctionalityOfPythonRuleItemWithParameters() { ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameParameters); testItem.parameters["clampToZero"] = "NO U"; testItem.pinInfo["myInputPin"].value.data = true; testItem.evaluate(); Assert.IsTrue(testItem.pinInfo["myOutputPin"].value.asBoolean()); testItem.parameters["clampToZero"] = "yes"; testItem.evaluate(); Assert.IsFalse(testItem.pinInfo["myOutputPin"].value.asBoolean()); }
public void testLoadOfPythonRuleItem() { ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filename); Assert.AreEqual("test python rule item", testItem.ruleName()); Dictionary<String, pin> pins = testItem.getPinInfo(); Assert.IsTrue(testItem.getCategory() == ""); Assert.IsTrue(pins.Count == 2 ); Assert.IsTrue(pins.ContainsKey("myInputPin")); Assert.IsTrue(pins.ContainsKey("myOutputPin")); Assert.IsTrue(pins["myOutputPin"].direction == pinDirection.output); Assert.IsTrue(pins["myInputPin"].direction == pinDirection.input); }
public ruleItemBase addRuleItem(ruleItemInfo info) { // Make new ruleItem control of this RuleItem type. ruleItemBase newRuleItem; if (info.itemType == ruleItemType.RuleItem) { // .net ruleItems are loaded via reflection. We find the parameterless // constructor, and then call it. ConstructorInfo constr = info.ruleItemBaseType.GetConstructor(new Type[0]); newRuleItem = (ruleItemBase)constr.Invoke(new object[0] { }); } else if (info.itemType == ruleItemType.scriptFile) { // Script items are loaded by their own constructor, as we need information // at runtime. newRuleItem = new ruleItem_script(info.pythonFileName); } else // This should only happen if a ruleItem is loaded of an unsupported // type - ie, never. throw new Exception("Unrecognised file type"); // Initialise the Pins on the control. This will generate a new guid for each pin. // FIXME: It's kind of messy that we have to do this here. newRuleItem.initPins(); AddRuleItemToGlobalPool(newRuleItem); return newRuleItem; }
public void testLoadOfPythonRuleItemWithParameters() { ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameParameters); Assert.AreEqual(2, testItem.parameters.Count); Assert.AreEqual("first value", testItem.parameters["clampToZero"]); Assert.AreEqual("second value", testItem.parameters["IAmTheSecondOption"]); Assert.AreEqual(2, testItem.parameters.Count); Assert.AreEqual("first value", testItem.parameters["clampToZero"]); Assert.AreEqual("second value", testItem.parameters["IAmTheSecondOption"]); }
public void testLoadOfPythonRuleItemWithCategory() { ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameCategory); Assert.AreEqual("test python rule item", testItem.ruleName()); Assert.AreEqual("test category", testItem.getCategory()); }
private ruleItemBase makeRuleItem(ruleItemInfo info) { // Make new ruleItem control of this RuleItem type ruleItemBase newRuleItem; if (info.itemType == ruleItemType.RuleItem) { ConstructorInfo constr = info.ruleItemBaseType.GetConstructor(new Type[0]); newRuleItem = (ruleItemBase)constr.Invoke(new object[0] { }); } else if (info.itemType == ruleItemType.scriptFile) { newRuleItem = new ruleItem_script(info.pythonFileName); } else throw new Exception("eh? Unrecognised file type?"); return newRuleItem; }
private void populateToolboxFromPythonFile(string filename) { try { ruleItem_script jake = new ruleItem_script(filename); ruleItemInfo itemInfo = new ruleItemInfo { itemType = ruleItemType.scriptFile, pythonFileName = filename, pythonCategory = jake.getCategory() }; this.addRuleItemObjectToToolbox(jake, itemInfo); } catch (Exception e) { // unable to load this file! MessageBox.Show("Unable to load file '" + filename +"', exception message: '" + e.Message + "'"); } }