class GEDAComponentParsingTests(GEDATestCase): def test_parse_command(self): """ Test parsing commands from a stream. """ typ, params = self.geda_parser._parse_command(StringIO.StringIO('{')) self.assertEquals(typ, '{') self.assertEquals(params, {}) typ, params = self.geda_parser._parse_command( StringIO.StringIO('A 49 34 223 30 90') ) self.assertEquals(typ, 'A') self.assertEquals(params, { 'x': 49, 'y': 34, 'radius': 223, 'startangle': 30, 'sweepangle': 90, 'style_color': 3, 'style_width': 10, 'style_capstyle': 0, 'style_dashstyle': 0, 'style_dashlength': -1, 'style_dashspace': -1, }) expected_params = { 'x': 18600, 'y': 21500, 'selectable': 1, 'angle': 0, 'mirror': 0, 'basename': 'EMBEDDED555-1', } string = 'C 18600 21500 1 0 0 EMBEDDED555-1' typ, params = self.geda_parser._parse_command( StringIO.StringIO(string) ) self.assertEquals(typ, 'C') self.assertEquals(params, expected_params) def test_parse_component_data(self): """ Tests parsing component data from symbol files and embedded sections. """ self.geda_parser = GEDA([ './test/geda/simple_example/symbols', ]) # need to do this to force setup since parse_schematic isn't being run self.geda_parser.parse_setup() symbol = """v 20110115 2 H 3 0 0 0 -1 -1 1 -1 -1 -1 -1 -1 5 M 510,240 L 601,200 L 555,295 L 535,265 z H 3 0 0 0 -1 -1 0 2 20 100 -1 -1 6 M 100,100 L 500,100 C 700,100 800,300 800,400 C 800,500 700,700 500,700 L 100,700 z""" stream = StringIO.StringIO(symbol) component = self.geda_parser.parse_component_data(stream, { 'basename': 'test.sym', }) self.assertEquals(component.name, 'test') self.assertEquals(len(component.symbols), 1) self.assertEquals(len(component.symbols[0].bodies), 1) self.assertEquals(len(component.symbols[0].bodies[0].shapes), 9) def test_parsing_unknown_component(self): """ Test parsing unknown component """ self.geda_parser.design = upconvert.core.design.Design() stream = StringIO.StringIO('C 18600 21500 1 0 0 invalid.sym') component, instance = self.geda_parser._parse_component( stream, {'basename': 'invalid',}, ) self.assertEquals(component, None) self.assertEquals(instance, None)