def add_tests_to_project(self, project, modnames, force=False): for modname in modnames: try: module = project.find_module_by_full_path(modname) if not module.has_errors(): self._add_tests_for_module(module, project, force) except ModuleNotFound: log.warning("Failed to inspect module %s, skipping test generation." % modname)
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_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_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_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 inspect_code(project, path, code): try: tree = parse(code) except ParseError as e: log.warning("Inspection of module %s failed with error %s" % (path,e)) return project.create_module(path, errors=[e]) #try to skip visitor = descend(tree, ModuleVisitor) # We assume that all test classes in this module has dependencies on # all imports the module contains. for test_class in [o for o in visitor.objects if isinstance(o, TestClass)]: # We gathered all imports in a single list, but import lists of those # classes may diverge in time, so we don't want to share their # structure. test_class.imports = visitor.imports[:] return project.create_module(path, code=tree, objects=visitor.objects, imports=visitor.imports, main_snippet=visitor.main_snippet, last_import=visitor.last_import)
count = 0 for path in python_modules_below(project.get_points_of_entry_path()): poe = ensure_point_of_entry(project, path) if poe.is_out_of_sync(): count += 1 return count def inspect_project_statically(project): return add_and_update_modules(project) + \ add_and_update_points_of_entry(project) 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: log.warning("Point of entry exited with error: %s" % last_exception_as_string()) log.debug("Full traceback:\n" + last_traceback())
def inspect_code(project, path, code): try: tree = parse(code) except ParseError, e: log.warning("Inspection of module %s failed." % path) return project.create_module(path, errors=[e])
project.add_point_of_entry(poe) return project.get_point_of_entry(name) def add_and_update_points_of_entry(project): count = 0 for path in python_modules_below(project.get_points_of_entry_path()): poe = ensure_point_of_entry(project, path) if poe.is_out_of_sync(): count += 1 return count def inspect_project_statically(project): return add_and_update_modules(project) + \ add_and_update_points_of_entry(project) 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: log.warning("Point of entry exited with error: %s" % last_exception_as_string()) log.debug("Full traceback:\n" + last_traceback())