def test_statistics_creator_retrieve_class(self): """ Can class data be fetched from the database? Author: Jake """ classnode = ClassNode("TestName") classnode.add_attribute("AttributeOne", "+") classnode.add_function("FunctionOne", "AParameter", "+") statistics = StatisticsCreator("UnitTest") statistics.create_tables() statistics.insert_class(classnode) self.assertEqual(statistics.get_class_data()[0].class_name, 'TestName')
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 = 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__)) # Edited By Jake statistics = StatisticsCreator("statistics") statistics.insert_class(class_node)
def test_statistics_creator_insert_class(self): """ Can class data be inserted into the database? Author: Jake """ classnode = ClassNode("TestName") classnode.add_attribute("AttributeOne", "+") classnode.add_function("FunctionOne", "AParameter", "+") statistics = StatisticsCreator("UnitTest") statistics.create_tables() statistics.insert_class(classnode) result = statistics.db.query("""SELECT className FROM ClassData WHERE className='TestName'""") self.assertEqual(result.fetch()[0]['className'], "TestName")