def testSort(self): attr = { 'refdes': 'R10', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } comp = gs.SchematicComponent(**attr) self.bomComp.addComponent(comp) attr = { 'refdes': 'R4', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } comp = gs.SchematicComponent(**attr) self.bomComp.addComponent(comp) #print "Before sort: %s"%(self.bomComp.refdes) self.bomComp.sort() self.assertEqual(self.bomComp.refdes[0], 'R1', 'Wrong first refdes after sort') self.assertEqual(self.bomComp.refdes[1], 'R4', 'Wrong second refdes after sort') self.assertEqual(self.bomComp.refdes[2], 'R10', 'Wrong third refdes after sort')
def testComponentInit(self): attr = self.attr c = gs.SchematicComponent(**attr) for (attribute, value) in attr.items(): self.assertEqual( c.getAttribute(attribute), value, 'Component Attribute Init Fail: %s\nExpecting: %s' % (attribute, value))
def testEq(self): attr = { 'refdes': 'R10', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } comp = gs.SchematicComponent(**attr) result = (self.bomComp == comp) self.assertTrue(result, "Equal components not being recognized") attr = { 'refdes': 'R10', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '123234567A' } comp = gs.SchematicComponent(**attr) result = (self.bomComp == comp) self.assertFalse(result, "Unqual components not being recognized")
def _createDummyComponentList(self): ''' Create SchematicComponentList and populate with components ''' attr = { 'refdes': 'R1', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567' } c1 = gs.SchematicComponent(**attr) attr = { 'refdes': 'R3', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567' } c2 = gs.SchematicComponent(**attr) attr = { 'refdes': 'R2', 'value': '100k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } c3 = gs.SchematicComponent(**attr) attr = { 'refdes': 'C2', 'value': '10uF', 'device': 'CAPACITOR', 'vendor-number': '1234567B' } c4 = gs.SchematicComponent(**attr) attr = { 'refdes': 'C4', 'value': '1uF', 'device': 'CAPACITOR', 'vendor-number': '1234567C' } c5 = gs.SchematicComponent(**attr) attr = { 'refdes': 'C1', 'value': '1uF', 'device': 'CAPACITOR', 'vendor-number': '1234567B' } c6 = gs.SchematicComponent(**attr) attr = { 'refdes': 'L1', 'value': '22nH', 'device': 'INDUCTOR', 'vendor-number': '1234567D' } c7 = gs.SchematicComponent(**attr) cl = gs.SchematicComponentList() for component in [c1, c2, c3, c4, c5, c6, c7]: cl.append(component) return cl
def testAddComponent(self): attr = { 'refdes': 'R10', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } comp = gs.SchematicComponent(**attr) self.bomComp.addComponent(comp) self.assertEqual(self.bomComp.getQuantity(), 2, "Quantity attribute not being updated")
def setUp(self): attr = { 'refdes': 'R1', 'value': '50k', 'device': 'RESISTOR', 'symbol': 'test.sym' } c1 = gs.SchematicComponent(**attr) attr = { 'refdes': 'R3', 'value': '10k', 'device': 'RESISTOR', 'symbol': 'test.sym' } c2 = gs.SchematicComponent(**attr) attr = { 'refdes': 'R2', 'value': '100k', 'device': 'RESISTOR', 'symbol': 'test.sym' } c3 = gs.SchematicComponent(**attr) attr = { 'refdes': 'C2', 'value': '10uF', 'device': 'CAPACITOR', 'symbol': 'test.sym' } c4 = gs.SchematicComponent(**attr) attr = { 'refdes': 'C1', 'value': '100uF', 'device': 'CAPACITOR', 'symbol': 'test.sym' } c5 = gs.SchematicComponent(**attr) self.cl = gs.SchematicComponentList() for component in [c1, c2, c3, c4, c5]: self.cl.append(component)
def testInit(self): self.assertIsInstance(self.bomComp, gs.SchematicComponent, "Improper subclass of BomComponent") self.assertIsNotNone(self.bomComp.getAttribute('refdes'), 'Empty Refdes') self.assertIsNotNone(self.bomComp.getAttribute('vendor-number'), 'Empty vendor-number') attr = { 'refdes': 'R1', 'value': '10k', 'device': 'RESISTOR', 'vendor-number': '1234567A' } comp = gs.SchematicComponent(**attr) self.bomComp = bo.BOMComponent(comp) self.assertEqual(self.bomComp, comp, "Component in init argument not being processed")
def parse(self): skip_counter = 0 self.logger.info("skipping %i lines" % (self.skip_lines)) while skip_counter < self.skip_lines: skip_counter += 1 self.csvreader.next() if self.header: self.logger.info("Reading header") header = self.csvreader.next() #clean up header's in case of leading periods dummy_header = [] for attribute in header: dummy_header.append(attribute.strip('.')) header = dummy_header del dummy_header else: header = self.attributes print header attributeLength = len(header) for row in self.csvreader: #ignore rows beginning with a . if row[0][0] == '.': continue #check that the row length equals attributeLength if len(row) != attributeLength: self.logger.error("incorrect data length in row: %i" % (self.csvreader.line_num)) continue #print row dummy_attributes = [] for i in range(attributeLength): dummy_attributes.append((header[i], row[i])) comp = gschemSchematic.SchematicComponent(dummy_attributes) self.componentList.append(comp) del comp return self.componentList
def parse(self): ''' Parses schematic file. Returns a list of Schematic Components ''' f = open(self.file, 'r') file_data = f.read() f.close() #get components components = self.component_re.findall(file_data) if not components: raise SchematicParserError("Invalid regexp match") else: self.logger.debug("A total of %i components were found"%(len(components))) for component in components: header_data = component[0] attribute_data = component[1] symbol_file = header_data.split()[-1] #search for attributes attributes = self.attribute_re.findall(attribute_data) if not attributes: raise SchematicParserError("No attributes found for component: %s"%(symbol_file)) #Create dictionary for component creation attributes = dict(attributes) #add symbol file to attributes attributes['symbol'] = symbol_file comp = gs.SchematicComponent(**attributes) if not comp.getAttribute('device') or not comp.getAttribute('refdes'): self.logger.warning('Ignoring component: %s'%(comp.getAttribute('symbol'))) continue if (comp.getAttribute('device') in self.restrictedDevices): self.logger.warning( "Ignoring restricted device: %s"%(comp)) continue #rename refdes for slotting if comp.hasAttribute('num_slots') or comp.hasAttribute('slot'): refdes = comp.getAttribute('refdes')+"."+str(comp.getAttribute('slot')) comp.setAttribute('refdes', refdes) del refdes #Catch identical refdes components refdesMatches = self.componentList.find('refdes', comp.getAttribute('refdes')) if refdesMatches: self.logger.warning('%i identical refdes match(es) found! %s'%(len(refdesMatches), comp.getAttribute('refdes'))) if self.ignoreMultipleRefdes: self.logger.info('Ignoring component: %s'%(comp.getAttribute('refdes'))) continue #Identical refdes found, is num_slots defined #create components and attach to component list #dummy = SchematicComponent(attributes) self.componentList.append(comp) del comp #del dummy self.logger.info('Schematic parse returned %i valid components'%(len(self.componentList))) #Sort list self.componentList.sort() return self.componentList