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'})