def resolve(self): circular_refs = self.__find_circular_refs() if circular_refs: message = "circular references: " + ", ".join(circular_refs) uml_object = self.__uml_objects[circular_refs[0]] logging.getLogger("compiler").error(message, object=uml_object) return for uml_object in self.__uml_objects.values(): self.__resolve_object(uml_object)
def test_has(self): instance = logging.getLogger("test") instance.warning("ops") instance.critical("ooops") self.assertTrue(instance.has("CRITICAL")) self.assertTrue(instance.has("CRITICAL WARNING")) self.assertFalse(instance.has("ERROR"))
def parse(self, code_objects): self.__uml_object = None self.__last_type = None self.__objects = {} for code_object in code_objects: if code_object.position < 0: if not code_object.is_empty(): message = "object definition without header" logging.getLogger("compiler").warning(message) continue self.__code_object = code_object self.__lexer["definition"].parseString(str(code_object)) return self.__objects
def __resolve_object(self, uml_object): if uml_object.type != None: return if uml_object.parent == None: uml_object.type = uml_object.name else: if uml_object.parent in self.__uml_objects: parent = self.__uml_objects[uml_object.parent] else: logger = logging.getLogger("compiler") message = "non-existing object referenced: " + uml_object.parent logger.error(message, object=uml_object) return self.__resolve_object(parent) uml_object.type = parent.type properties = parent.properties.copy() properties.update(uml_object.properties) uml_object.properties = properties required = parent.required.copy() required.update(uml_object.required) uml_object.required = required allowed = parent.allowed.copy() allowed.update(uml_object.allowed) uml_object.allowed = allowed
def generate(self): logger = logging.getLogger("compiler") logger.flush() self.compiler.clear() self.window.scene.clear() self.diagram = Diagram() code = Code(str(self.window.qsci.text())) uml_objects = self.compiler.compile(code) self.set_msg_view(logger) if logger.has("ERROR CRITICAL"): return for uml_object in uml_objects.values(): self.diagram.add(uml_object) # nodes must be updated before layouting for node in self.diagram.nodes.values(): node.update() # needed to layout and draw edges self.diagram.set_anchors() LayoutFactory.get(str(self.active_layout_action.text())).apply(self.diagram) self.__update()
def test_get_events(self): instance = logging.getLogger("test") instance.warning("ops") instance.critical("ooops") result = instance.get_events("CRITICAL WARNING INFO") self.assertEquals(2,len(result)) result = instance.get_events("CRITICAL") self.assertEquals(1,len(result))
def main(argv): logger = logging.getLogger('compiler') try: opts, args = getopt.getopt(sys.argv[1:], "hi:o:l:m:s:", ["help", "input=", "output=", "layout=", "margin=", "scale="]) except getopt.GetoptError, err: print str(err) print usage() return 1
def setUp(self): self.uml_object = UMLObject(name="association") self.uml_object.required = {"source-object": "OBJECT"} self.uml_object.allowed = { "arrow": "STRING", "direction": ["none", "source", "target", "both"], "source-role": "STRING", "source-count": "MULTIPLICITY"} self.uml_objects = { "association": self.uml_object, "Student": UMLObject(name="Student")} self.logger = logging.getLogger("compiler") self.logger.flush()
def __log_error(self, message): logger = logging.getLogger("compiler") logger.error(message, object=self.__uml_object)
def test_critical(self): instance = logging.getLogger("test") instance.critical("ops") value = str(instance.events.pop()) self.assertNotEquals(value.find("CRITICAL"), -1)
def __handle_error(self, token): line = token["error"].get("line") message = "unrecognised syntax: " + line logging.getLogger("compiler").warning(message, object=self.__uml_object)
def setUp(self): self.instance = Compiler() self.logger = logging.getLogger("compiler") self.logger.flush()
def test_is_empty(self): instance = logging.getLogger("test") self.assertTrue(instance.is_empty())
def test_isnt_empty(self): instance = logging.getLogger("test") instance.error("ops") self.assertFalse(instance.is_empty())
def test_flush(self): instance = logging.getLogger("test") instance.error("ops") instance.flush() self.assertTrue(instance.is_empty())
def test_info(self): instance = logging.getLogger("test") instance.info("ops") value = str(instance.events.pop()) self.assertNotEquals(value.find("INFO"), -1)
def setUp(self): logging.getLogger("test").flush()
def test_warning(self): instance = logging.getLogger("test") instance.warning("ops") value = str(instance.events.pop()) self.assertNotEquals(value.find("WARNING"), -1)
def test_error(self): instance = logging.getLogger("test") instance.error("ops") value = str(instance.events.pop()) self.assertNotEquals(value.find("ERROR"), -1)