def process_module(self, module_list): module_name = '' newClass = None for aline in module_list: if aline[0] == 'module': module_name = aline[1] self.modules[module_name] = list() elif aline[0] == 'class': if newClass is None: newClass = model.ClassNode(aline[1].strip()) else: self.modules[module_name].append(newClass) newClass = model.ClassNode(aline[1].strip()) elif aline[0] == 'attributes': loop_counter = 1 while loop_counter < len(aline): newClass.add_attribute(aline[loop_counter].strip(), False) loop_counter += 1 elif aline[0] == 'methods': loop_counter = 1 while loop_counter < len(aline): newClass.add_function(aline[loop_counter].strip(), 'params', False) loop_counter += 1 elif aline[0] == 'super_classes': pass self.modules[module_name].append(newClass) return self.modules
def load_data_to_module(self, module_list): # This is used to parse list and reconsruct the class structure # current version will only work with a single file. Extenstion should be easy # Module is loaded into dictionary which can then be used by by the uml output to # generat UML diagram # NEED TO DEAL WITH VISIBILITY PROPERTY module_name = '' modules = dict() newClass = None for aline in module_list: if aline[0] == 'module': # print(aline) module_name = aline[1] modules[module_name] = list() elif aline[0] == 'class': if newClass is None: newClass = model.ClassNode(aline[1].strip()) else: modules[module_name].append(newClass) newClass = model.ClassNode(aline[1].strip()) #print('class: {}'.format(aline[1])) elif aline[0] == 'attributes': #print('attributes: ') loop_counter = 1 while loop_counter < len(aline): newClass.add_attribute(aline[loop_counter].strip(), False) #print(" " + aline[loop_counter]) loop_counter += 1 elif aline[0] == 'methods': # print('methods:') loop_counter = 1 while loop_counter < len(aline): newClass.add_function(aline[loop_counter].strip(), 'params', False) #print(' ' + aline[loop_counter]) loop_counter += 1 elif aline[0] == 'super_classes': # print('super_classes:') pass #loop_counter = 1 # while loop_counter < len(aline): # newClass.add_super_class(aline[loop_counter].get_name.strip()) #print(' ' + aline[loop_counter]) # loop_counter += 1 modules[module_name].append(newClass) return modules
def test_create_class_with_name(self): """ Checks if class name is equal to one created Author: Braeden """ md = model.ClassNode("Class One", []) self.assertTrue(md.name == "Class One")
def test_create_class_with_super_classes(self): """ Checks if class with methods tests if correct as created are stored Author: Braeden """ md = model.ClassNode("Class One", []) md.add_super_class(()) md.add_super_class(()) self.assertTrue(len(md.super_classes) == 2)
def test_create_class_with_methods(self): """ Checks if class with methods tests if correct as created are stored Author: Braeden """ md = model.ClassNode("Class One", []) md.add_function("Function One", [], "+") md.add_function("Function Two", [], "+") self.assertTrue(len(md.functions) == 2)
def test_create_class_with_attributes(self): """ Checks if class with attributes tests if correct as created are stored Author: Braeden """ md = model.ClassNode("Class One", []) md.add_attribute("Attribute One", "+") md.add_attribute("Attribute Two", "+") self.assertTrue(len(md.attributes) == 2)
def load_data_to_module(self, module_list): """ This is used to parse list and reconsruct the class structure current version will only work with a single file. Extenstion should be easy Module is loaded into dictionary which can then be used by by the uml output to generate UML diagram """ module_name = '' modules = dict() newClass = None for aline in module_list: if aline[0] == 'module': module_name = aline[1] modules[module_name] = list() elif aline[0] == 'class': if newClass is None: newClass = model.ClassNode(aline[1].strip()) else: modules[module_name].append(newClass) newClass = model.ClassNode(aline[1].strip()) elif aline[0] == 'attributes': loop_counter = 1 while loop_counter < len(aline): newClass.add_attribute(aline[loop_counter].strip(), False) loop_counter += 1 elif aline[0] == 'methods': loop_counter = 1 while loop_counter < len(aline): newClass.add_function(aline[loop_counter].strip(), 'params', False) loop_counter += 1 elif aline[0] == 'super_classes': pass modules[module_name].append(newClass) return modules
def process_class(self, some_class): # Process the found class, and store in global modules # Find any functions with-in the class name = some_class.__name__ module_name = some_class.__module__ # create module for current file in global modules list if module_name not in self.modules: self.modules[module_name] = list() super_classes = [] super_classes_names = [] # Only creates class_nodes that have unique name, # stops duplicate class_nodes # Strips any random objects, only leaves proper class names for class_object in some_class.__bases__: if class_object.__name__ != 'object': if class_object.__name__ not in super_classes_names: super_classes.append(class_object) super_classes_names.append(class_object.__name__) # create class node and append to current module class_node = model.ClassNode(name, super_classes) self.modules[module_name].append(class_node) # create list of functions in class for (name, something) in inspect.getmembers(some_class): if inspect.ismethod(something) or inspect.isfunction(something): # get the class from the functions element function_class = something.__qualname__.split('.')[0] # only add function if the current class is the same as the # selected functions class if some_class.__name__ == function_class: # create list of attributes in class with constructor if something.__name__ == "__init__": attributes = something.__code__.co_names for attribute in attributes: self.process_attribute( attribute, class_node, self.get_visibility_of_string(attribute)) self.process_function( something, class_node, self.get_visibility_of_string(something.__name__))