def test_lookup_missing(self): """ Test looking up a part that is missing """ name = 'nosuchpart' libs = ['nosuchlib', 'jensen', '1wire'] found = lookup_part(name, libs) self.assertEqual(found, None)
def parse(self, filename, library_filename=None): """ Parse a kicad file into a design """ design = Design() segments = set() # each wire segment junctions = set() # wire junction point (connects all wires under it) if library_filename is None: library_filename = splitext(filename)[0] + '-cache.lib' if exists(library_filename): for cpt in parse_library(library_filename): design.add_component(cpt.name, cpt) f = open(filename) libs = [] line = f.readline().strip() # parse the library references while line != "$EndDescr": if line.startswith('LIBS:'): libs.extend(line.split(':', 1)[1].split(',')) line = f.readline().strip() # Now parse wires and components, ignore connections, we get # connectivity from wire segments line = f.readline() while line: prefix = line.split()[0] if line.startswith('Wire Wire Line'): self.parse_wire(f, segments) elif prefix == "Connection": # Store these to apply later self.parse_connection(line, junctions) elif prefix == "Text": design.design_attributes.add_annotation( self.parse_text(f, line)) elif prefix == "$Comp": # Component Instance inst = self.parse_component_instance(f) design.add_component_instance(inst) if inst.library_id not in design.components.components: cpt = lookup_part(inst.library_id, libs) if cpt is not None: design.components.add_component(cpt.name, cpt) line = f.readline() f.close() segments = self.divide(segments, junctions) design.nets = self.calc_nets(segments) self.calc_connected_components(design) return design
def test_lookup_present(self): """ Test looking up a part that is present """ name = 'DS18B20Z' libs = ['jensen', '1wire'] found = lookup_part(name, libs) self.assertTrue(isinstance(found, Component)) self.assertEqual(found.name, name)