def test_get_method_nodes(self, custom_python_code): import imp custom_dir = os.path.join(TEST_DATA_DIR, 'custom_data') fname = os.path.join(custom_dir, 'python_file_for_input.py') mod = imp.load_source("python_file_for_input", fname) ast_node = ast.parse(custom_python_code) class_finder = ClassFinder() class_finder.visit(ast_node) class_nodes = class_finder.class_nodes_dict for class_name in class_nodes.keys(): class_node = class_nodes[class_name] ast_wrapper = AstClassWrapper(class_node) no_of_methods = mod.get_number_of_methods(class_name) assert len(ast_wrapper.get_method_nodes()) == no_of_methods
def test_ssm_metric(self, cls_gen): metric = StructuralSimilarityBetweenMethods() for simple_cls in cls_gen.generate(1000, 10, 10): cls_source = simple_cls.get_source_code() logging.info("TestMetrics::" + \ "test_ssm_metric:simple_cls.source_code:\n" + \ cls_source) ast_wrapper = AstClassWrapper(simple_cls.get_ast_node()) custom_ssm = simple_cls.get_ssm_matrix() matrix_to_test = self.build_test_matrix(metric, ast_wrapper) logging.info("TestMetrics::" + \ "test_ssm_metric:custom_ssm:\n" + \ print_matrix_with_fabulousness(custom_ssm)) logging.info("TestMetrics::" + \ "test_ssm_metric:matrix_to_test:\n" + \ print_matrix_with_fabulousness(matrix_to_test)) for method_node in ast_wrapper.get_method_nodes(): logging.info(metric.find_instance_variables(method_node, ast_wrapper)) assert custom_ssm == matrix_to_test