def create_child(self, name=None, properties=None, reference=None): """Create an instance to add to the definition, add it, and return the instance. This functions calls the add_child funciton. parameters ---------- name - (str) the name of this instance properties - (dict) the dictionary which holds the properties Example ------- To create a child: >>> definition = sdn.Definition() >>> child_instance = definition.create_child() >>> child_instance.name = "child_instance" >>> child_instance.reference = reference_definition To create a child with optional parameters >>> child_instance = definition.create_child(name="child_instance", reference=reference_definition) The reference of the instance is the definition that initialized this instance. """ instance = Instance(name, properties) instance.reference = reference self.add_child(instance) return instance
def test_properties_init_shortcut(self): d = Definition('d_name', {'key1': 1, 'key2': 'value2'}) self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error') l = Library('l_name', {'key1': 'value1', 'key2': 'value2'}) self.assertEqual(l['key1'], 'value1', 'Library properties init shorcut error') n = Netlist('n_name', {'key1': 'value1', 'key2': 63}) self.assertEqual(n['key2'], 63, 'Netlist properties init shorcut error') i = Instance('i_name', {'key1': 'value1', 'key2': 'value2'}) self.assertEqual(i['key1'], 'value1', 'Instance properties init shorcut error') c = Cable('c_name', {'key1': 'value1', 'key2': 'value2'}) self.assertEqual(c['key2'], 'value2', 'Cable properties init shorcut error') p = Port('p_name', {'key1': 'value1', 'key2': 'value2'}) self.assertEqual(p['key1'], 'value1', 'Port properties init shorcut error')
def create_child(self): """ create an instance to add to the definition, add it, and return the instance. """ instance = Instance() self.add_child(instance) return instance
def top_instance(self, instance): """Sets the top instance of the design. The instance must not be null and should probably come from this netlist Parameters ---------- instance - (Instance or Definition) the instance to set as the top instance. If a definition is passed into the funciton, creates a new instance with that definition and set it as the top instance. """ assert instance is None or isinstance(instance, Instance) or isinstance( instance, Definition), "Must specify an instance" global_callback._call_netlist_top_instance(self, instance) # TODO: should We have a DRC that makes sure the instance is of a definition contained in netlist? I think no # but I am open to hear other points of veiw. if isinstance(instance, Definition): top = Instance() top.reference = instance self.top_instance = top else: self._top_instance = instance
def test_name_init_shortcut(self): d = Definition('d_name') self.assertEqual(d.name, 'd_name', 'Definition name init shorcut error') l = Library('l_name') self.assertEqual(l.name, 'l_name', 'Library name init shorcut error') n = Netlist('n_name') self.assertEqual(n.name, 'n_name', 'Netlist name init shorcut error') i = Instance('i_name') self.assertEqual(i.name, 'i_name', 'Instance name init shorcut error') c = Cable('c_name') self.assertEqual(c.name, 'c_name', 'Cable name init shorcut error') p = Port('p_name') self.assertEqual(p.name, 'p_name', 'Port name init shorcut error')
def test_if_leaf_shortcut(self): instance = Instance() definition = Definition() instance.reference = definition self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error') definition.create_cable() instance.reference = definition self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error')
def test_hRef_shortcut(self): item = Instance("myCable") def2 = Definition("Hello") item.reference = def2 hr = HRef(item) self.assertEqual(hr.item.name, item.name, 'Href item shorcut error')