def testReaction(self): rxn = createReaction() dump_object = iodine.dumpNetwork(0) rxnDict = dump_object["reactions"] #print(rxnDict) self.assertEqual(1, len(rxnDict))
def testMultipleShapes(self): num_nodes = 100 for i in range(num_nodes): createNode("node" + str(i), shapei=i % 8) dump_object = iodine.dumpNetwork(0) nodeDict = dump_object["nodes"] shape_names = [shape.name for shape in iodine.shapeFactories] for i in range(num_nodes): shapeDict = nodeDict[i]["shape"] self.assertEqual(shape_names[i % 8], shapeDict["name"]) #check `text-only` shapes if shapeDict["name"] == "text-only": self.assertEqual(0, len(shapeDict["items"])) break shape_items = shapeDict["items"][0] if shapeDict["name"] == "rectangle": match_primitive(self, shape_items, "rectangle") elif shapeDict["name"] == "circle": match_primitive(self, shape_items, "circle") elif shapeDict["name"] == "text outside": #self.assertEqual("circle", shape_items[0]["name"]) match_primitive(self, shape_items, "circle") elif shapeDict["name"] == "demo combo": match_primitive(self, shape_items[0], "circle") match_primitive(self, shape_items[1], "circle") match_primitive(self, shape_items, "rectangle")
def testNode(self): node = createNode("node0") dump_object = iodine.dumpNetwork(0) self.assertEqual(0, len(dump_object["compartments"])) nodeDict = dump_object["nodes"] self.assertEqual(1, len(nodeDict)) nodeObj = nodeDict[0] self.assertEqual(-1, nodeObj["compi"]) self.assertIsInstance(nodeObj["floating"], bool) self.assertEqual(2, len(nodeObj["position"])) self.assertEqual(0.4, nodeObj["position"][1]) self.assertEqual(2, len(nodeObj["rectSize"]))
def testAlias(self): #since original node is at 0, alias is at 1 anode = createAlias("node0") dump_object = iodine.dumpNetwork(0) nodeDict = dump_object["nodes"] self.assertEqual(2, len(nodeDict)) anodeObj = nodeDict[1] self.assertIsInstance(anodeObj["nodeLocked"], bool) self.assertEqual(0, anodeObj["originalIdx"]) self.assertEqual(2, len(anodeObj["position"])) self.assertEqual(2, len(anodeObj["rectSize"]))
def testCompositeShape(self): #This test created specially for rectangle default shape node = createNode("node1") dump_object = iodine.dumpNetwork(0) nodeDict = dump_object["nodes"] shapeDict = nodeDict[0]["shape"] self.assertEqual("rectangle", shapeDict["name"]) shape_items = shapeDict["items"][0] match_rectangle_primitive(self, shape_item=shape_items)
def testNetwork(self): '''Load network, validate its state, dump it, and compare the dumped object with the object before it was deserialized''' dirname = os.path.dirname(__file__) pathname = os.path.join(dirname, 'test.json') with open(pathname, 'r') as file: original_obj = json.load(file) iodine.loadNetwork(original_obj) iodine.validateState() self.maxDiff = None dump_object = iodine.dumpNetwork(0) dumped_str = json.dumps(dump_object, indent=4, sort_keys=True) original_str = json.dumps(original_obj, indent=4, sort_keys=True) self.assertEqual(original_str, dumped_str)
def testMultipleNodes(self): #testing 100 nodes num_nodes = 100 for i in range(num_nodes): createNode("node" + str(i), shapei=i % 8) dump_object = iodine.dumpNetwork(0) nodeDict = dump_object["nodes"] self.assertEqual(num_nodes, len(nodeDict)) for i in range(num_nodes): nodeObj = nodeDict[i] self.assertEqual(-1, nodeObj["compi"]) self.assertIsInstance(nodeObj["floating"], bool) self.assertEqual(2, len(nodeObj["position"])) self.assertEqual(0.4, nodeObj["position"][1]) self.assertEqual(2, len(nodeObj["rectSize"]))
def testTextPrimitive(self): node = createNode("node1") dump_object = iodine.dumpNetwork(0) nodeDict = dump_object["nodes"] shapeDict = nodeDict[0]["shape"] text_items = shapeDict["text_item"] self.assertIsInstance(text_items[0]["alignment"], str) self.assertEqual("center", text_items[0]["alignment"]) self.assertEqual(4, len(text_items[0]["bg_color"])) self.assertEqual(3, len(text_items[0]["font_color"])) self.assertEqual("sans-serif", text_items[0]["font_family"]) self.assertIsInstance(text_items[0]["font_size"], int) self.assertEqual("normal", text_items[0]["font_style"]) self.assertEqual("normal", text_items[0]["font_weight"]) self.assertIsInstance(text_items[1]["rotation"], float) self.assertEqual(2, len(text_items[1]["scale"])) self.assertEqual(2, len(text_items[1]["translation"]))
def dump_network(self, neti: int): return iod.dumpNetwork(neti)