def test_missing_p(self): """The component parser handles a connector missing a p element """ parser = ComponentParser(None) class FakeConn(object): """A fake connector""" def __init__(self, missing): self.missing = missing def find(self, path): """ Return None or a fixed element for the p element """ assert path == 'views/schematicView/p' if self.missing: return None else: return {'terminalId': 'tid'} def get(self, key): """ Return 'id' for the 'id' attribute """ assert key == 'id' return 'id' class FakeTree(object): """A fake tree """ def findall(self, path): """ Return two fake connectors, one missing a p element and one not """ assert path == 'connectors/connector' return [FakeConn(missing=True), FakeConn(missing=False)] terminals = parser.parse_terminals(FakeTree()) self.assertEqual(terminals, {'id': 'tid'})
def test_parse_circle(self): """ We parse svg circles correctly. """ parser = ComponentParser(None) elem = FakeElem('circle', cx='72', cy='144', r='216') shapes = parser.parse_shapes(elem) self.assertEqual(len(shapes), 1) self.assertEqual(shapes[0].type, 'circle') self.assertEqual(shapes[0].x, 90) self.assertEqual(shapes[0].y, -180) self.assertEqual(shapes[0].radius, 270)
def test_parse_rect(self): """ We parse svg rectangles correctly. """ parser = ComponentParser(None) elem = FakeElem('rect', x='0', y='720', width='72', height='144') shapes = parser.parse_shapes(elem) self.assertEqual(len(shapes), 1) self.assertEqual(shapes[0].type, 'rectangle') self.assertEqual(shapes[0].x, 0) self.assertEqual(shapes[0].y, -900) self.assertEqual(shapes[0].width, 90) self.assertEqual(shapes[0].height, 180)
def test_missing_p(self): """The component parser handles a connector missing a p element """ parser = ComponentParser(None) class FakeConn(object): """A fake connector""" def __init__(self, missing): self.missing = missing def find(self, path): """ Return None or a fixed element for the p element """ assert path == 'views/schematicView/p' if self.missing: return None else: return {'terminalId': 'tid'} def get(self, key): """ Return 'id' for the 'id' attribute """ assert key == 'id' return 'id' class FakeTree(object): """A fake tree """ def findall(self, path): """ Return two fake connectors, one missing a p element and one not """ assert path == 'connectors/connector' return [FakeConn(missing=True), FakeConn(missing=False)] terminals = parser.parse_terminals(FakeTree()) self.assertEqual(terminals, {'id':'tid'})