def inspect_project(project): remove_deleted_modules(project) remove_deleted_points_of_entry(project) updates = inspect_project_statically(project) # If nothing new was discovered statically and there are no new points of # entry, don't run dynamic inspection. if updates: inspect_project_dynamically(project) else: log.info("No changes discovered in the source code, skipping dynamic inspection.")
def inspect_project_dynamically(project): if project.points_of_entry and hasattr(generator_has_ended, 'unreliable'): log.warning("Pure Python implementation of util.generator_has_ended is " "not reliable on Python 2.4 and lower. Please compile the " "_util module or use Python 2.5 or higher.") for poe in project.points_of_entry.values(): try: log.info("Inspecting point of entry %s." % poe.name) dynamic.inspect_point_of_entry(poe) except SyntaxError, err: log.warning("Point of entry contains a syntax error: %s" % err) except:
def inspect_project(project): remove_deleted_modules(project) remove_deleted_points_of_entry(project) updates = inspect_project_statically(project) # If nothing new was discovered statically and there are no new points of # entry, don't run dynamic inspection. if updates: inspect_project_dynamically(project) else: log.info( "No changes discovered in the source code, skipping dynamic inspection." )
def inspect_project_dynamically(project): if project.points_of_entry and hasattr(generator_has_ended, 'unreliable'): log.warning( "Pure Python implementation of util.generator_has_ended is " "not reliable on Python 2.4 and lower. Please compile the " "_util module or use Python 2.5 or higher.") for poe in project.points_of_entry.values(): try: log.info("Inspecting point of entry %s." % poe.name) dynamic.inspect_point_of_entry(poe) except SyntaxError, err: log.warning("Point of entry contains a syntax error: %s" % err) except:
def add_and_update_modules(project): count = 0 for modpath in python_modules_below(project.path): try: module = project.find_module_by_full_path(modpath) if module.is_up_to_date(): log.debug("%s hasn't changed since last inspection, skipping." % module.subpath) continue except ModuleNotFound: pass log.info("Inspecting module %s." % project._extract_subpath(modpath)) static.inspect_module(project, modpath) count += 1 return count
def add_test_case_to_project(project, test_class, main_snippet=None, force=False): existing_test_class = find_test_class_by_name(project, test_class.name) try: if not existing_test_class: module = find_module_for_test_class(project, test_class) log.info("Adding generated %s to %s." % (test_class.name, module.subpath)) ensure_imports(module, test_class.imports) add_test_case(module, test_class) ensure_main_snippet(module, main_snippet, force) else: ensure_imports(existing_test_class, test_class.imports) merge_test_classes(existing_test_class, test_class, force) ensure_main_snippet(existing_test_class.parent, main_snippet, force) except CodeTreeNotFound, ex: log.warning("Not adding %s to %s, because of a failed inspection." %\ (test_class.name, ex.module_subpath))
def add_and_update_modules(project): count = 0 for modpath in python_modules_below(project.path): try: module = project.find_module_by_full_path(modpath) if module.is_up_to_date(): log.debug( "%s hasn't changed since last inspection, skipping." % module.subpath) continue except ModuleNotFound: pass log.info("Inspecting module %s." % project._extract_subpath(modpath)) static.inspect_module(project, modpath) count += 1 return count
def add_test_case_to_project(project, test_class, main_snippet=None, force=False): existing_test_class = find_test_class_by_name(project, test_class.name) try: if not existing_test_class: module = find_module_for_test_class(project, test_class) log.info("Adding generated %s to %s." % (test_class.name, module.subpath)) ensure_imports(module, test_class.imports) add_test_case(module, test_class) ensure_main_snippet(module, main_snippet, force) else: ensure_imports(existing_test_class, test_class.imports) merge_test_classes(existing_test_class, test_class, force) ensure_main_snippet(existing_test_class.parent, main_snippet, force) except CodeTreeNotFound as ex: log.warning("Not adding %s to %s, because of a failed inspection." %\ (test_class.name, ex.module_subpath))
def merge_test_classes(test_class, other_test_class, force): """Merge other_test_case into test_case. """ for method in other_test_class.test_cases: existing_test_method = test_class.find_method_by_name(method.name) if not existing_test_method: log.info("Adding generated %s to %s in %s." % \ (method.name, test_class.name, test_class.parent.subpath)) add_test_case(test_class, method) elif force: log.info("Replacing %s.%s from %s with generated version." % \ (test_class.name, existing_test_method.name, test_class.parent.subpath)) replace_test_case(test_class, existing_test_method, method) else: log.info("Test case %s.%s already exists in %s, skipping." % \ (test_class.name, existing_test_method.name, test_class.parent.subpath))
def _add_tests_for_module(self, module, project, force): log.info("Generating tests for module %s." % module.subpath) for test_case in self._generate_test_cases(module): add_test_case_to_project(project, test_case, self.main_snippet, force)
def test_info_message_in_normal_mode(self): log.info("Log this") assert_equal_strings("INFO: Log this\n", self.captured.getvalue())
def test_info_message_in_debug_mode(self): log.info("Log that") assert_matches(r"\d+\.\d+ .*test_logger:\d+ INFO: Log that\n", self._get_log_output())