def find(self, query): """Search for an entity that matches the query and print info about it. :param query: search query. """ scenario_group = searchutils.find_benchmark_scenario_group(query) if scenario_group: print("%s (benchmark scenario group).\n" % scenario_group.__name__) # TODO(msdubov): Provide all scenario classes with docstrings. doc = utils.format_docstring(scenario_group.__doc__) print(doc) return scenario = searchutils.find_benchmark_scenario(query) if scenario: print("%(scenario_group)s.%(scenario_name)s " "(benchmark scenario).\n" % {"scenario_group": utils.get_method_class(scenario).__name__, "scenario_name": scenario.__name__}) doc = utils.parse_docstring(scenario.__doc__) print(doc["short_description"] + "\n") if doc["long_description"]: print(doc["long_description"] + "\n") if doc["params"]: print("Parameters:") for param in doc["params"]: print(" - %(name)s: %(doc)s" % param) if doc["returns"]: print("Returns: %s" % doc["returns"]) return print("Failed to find any docs for query: '%s'" % query) return 1
def _get_scenario_info(self, query): try: scenario = scenario_base.Scenario.get_scenario_by_name(query) scenario_group_name = utils.get_method_class(scenario).__name__ header = ("%(scenario_group)s.%(scenario_name)s " "(benchmark scenario)" % {"scenario_group": scenario_group_name, "scenario_name": scenario.__name__}) info = self._make_header(header) info += "\n\n" doc = utils.parse_docstring(scenario.__doc__) if not doc["short_description"]: return None info += doc["short_description"] + "\n\n" if doc["long_description"]: info += doc["long_description"] + "\n\n" if doc["params"]: info += "Parameters:\n" for param in doc["params"]: info += " - %(name)s: %(doc)s" % param + "\n" if doc["returns"]: info += "Returns: %s" % doc["returns"] return info except exceptions.NoSuchScenario: return None
def _get_scenario_info(self, query): try: scenario = scenario_base.Scenario.get_scenario_by_name(query) scenario_group_name = utils.get_method_class(scenario).__name__ info = ("%(scenario_group)s.%(scenario_name)s " "(benchmark scenario).\n\n" % { "scenario_group": scenario_group_name, "scenario_name": scenario.__name__ }) doc = utils.parse_docstring(scenario.__doc__) if not doc["short_description"]: return None info += doc["short_description"] + "\n\n" if doc["long_description"]: info += doc["long_description"] + "\n\n" if doc["params"]: info += "Parameters:\n" for param in doc["params"]: info += " - %(name)s: %(doc)s" % param + "\n" if doc["returns"]: info += "Returns: %s" % doc["returns"] return info except exceptions.NoSuchScenario: return None
def test_method_class_for_module_level_method(self): self.assertIsNone(utils.get_method_class(module_level_method))
def test_method_class_for_class_level_method(self): class A: def m(self): pass self.assertEqual(utils.get_method_class(A.m), A)