def test_get_port_inner_pin(self): port = sdn.Port() pin = port.create_pin() search = next(sdn.get_ports(pin)) self.assertEqual(port, search) port.remove_pin(pin) search = next(sdn.get_ports(pin), None) self.assertIsNone(search)
def test_get_port_instance_and_outer_pin(self): definition = sdn.Definition() port = definition.create_port() pin = port.create_pin() instance = sdn.Instance() instance.reference = definition search = next(sdn.get_ports(instance)) self.assertIs(port, search) outer_pin = instance.pins[pin] search = next(sdn.get_ports(outer_pin)) self.assertIs(port, search)
def test_unique(self): netlist = sdn.Netlist() library = netlist.create_library() definition = library.create_definition() port = definition.create_port() pin = port.create_pin() cable = definition.create_cable() wire = cable.create_wire() wire.connect_pin(pin) instance = sdn.Instance() instance.reference = definition search = list(sdn.get_ports([netlist, cable])) self.assertIs(port, search[0]) search = list(sdn.get_ports(cable)) self.assertIs(port, search[0])
def test_collection(self): definition = sdn.Definition() port = definition.create_port() port.name = "MY_PORT" instance = sdn.Instance() instance.name = "MY_INST" ports = list(sdn.get_ports([definition, instance])) self.assertEqual(len(ports), 1)
def test_get_ports_href_cable(self): netlist = sdn.Netlist() library = netlist.create_library() definition = library.create_definition() port = definition.create_port() pin = port.create_pin() cable = definition.create_cable() wire = cable.create_wire() wire.connect_pin(pin) instance = sdn.Instance() instance.reference = definition netlist.top_instance = instance href = next(sdn.get_hcables(cable)) search = next(sdn.get_ports(href)) self.assertIs(port, search)
def compare_definition(self, definition_orig, definition_composer, check_identifier=True): if check_identifier: assert self.get_identifier(definition_orig) == self.get_identifier(definition_composer), \ "Definitions do not have the same identifier" assert self.get_original_identifier(definition_orig) == self.get_original_identifier(definition_composer), \ "Definitions do not have the same original identifier" assert len(definition_orig.ports) == len(definition_composer.ports), \ "Definitions do not have the same number of ports" # for orig_port, composer_port in zip(definition_orig.ports, definition_composer.ports): # self.compare_ports(orig_port, composer_port) # do a smarter compare for orig_port in definition_orig.ports: if orig_port.name == None: #ports with no name are not compared print("WARNING: ports with name == None exist and are not compared") continue else: patterns = orig_port.name composer_port = next(sdn.get_ports(definition_composer, patterns)) self.compare_ports(orig_port, composer_port) assert len(definition_orig.cables) == len(definition_composer.cables), \ "Definitions do not have the same number of cables" for orig_cable in definition_orig.cables: if orig_cable.name == None: #ports with no name are not compared print("WARNING: cables with name == None exist and are not compared") continue else: patterns = orig_cable.name composer_cable = next(sdn.get_cables(definition_composer, patterns)) self.compare_cables(orig_cable, composer_cable) assert len(definition_orig.children) == len(definition_composer.children), \ "Definitions do not have the same number of instances" # for orig_instance, composer_cable in zip(definition_orig.children, definition_composer.children): # self.compare_instances(orig_instance, composer_cable) for orig_instance in definition_orig.children: if orig_instance.name == None: #ports with no name are not compared print("WARNING: children with name == None exist and are not compared") continue else: if orig_instance.name.startswith("SDN_Assignment_"): #skip assignment statements for now continue else: patterns = orig_instance.name try: composer_instance = next(sdn.get_instances(definition_composer, patterns)) except Exception: import pdb; pdb.set_trace() self.compare_instances(orig_instance, composer_instance) #compare assignemnt statements pattern = "SDN_Assignment_*" composer_generator = sdn.get_instances(definition_composer, pattern) orig_generator = sdn.get_instances(definition_orig, pattern) #i just need to make sure that they both contain the same number of each width assignment composer_dict = dict() orig_dict = dict() ci = next(composer_generator, None) while ci is not None: num = ci.name.split("_")[3] if num in composer_dict: composer_dict[num] += 1 else: composer_dict[num] = 1 ci = next(composer_generator, None) oi = next(orig_generator, None) while oi is not None: num = oi.name.split("_")[3] if num in orig_dict: orig_dict[num] +=1 else: orig_dict[num] = 1 oi = next(orig_generator, None) for k in composer_dict.keys(): assert k in orig_dict and orig_dict[k] == composer_dict[k], "there are a different number of "+ str(k) + " width assignment"
def test_get_port_reflection(self): port = sdn.Port() port.name = "MY_PORT" search = next(sdn.get_ports(port, "MY_PORT")) self.assertEqual(port, search)