Exemple #1
0
 def _get_scenario_info(self, query):
     try:
         scenario = scenario_base.Scenario.get_scenario_by_name(query)
         scenario_group_name = utils.get_method_class(scenario).get_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
Exemple #2
0
 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
Exemple #3
0
    def _get_scenario_info(self, query):
        try:
            scenario_inst = scenario.Scenario.get_scenario_by_name(query)
            scenario_gr_name = utils.get_method_class(scenario_inst).get_name()
            header = ("%(scenario_group)s.%(scenario_name)s "
                      "(benchmark scenario)" % {
                          "scenario_group": scenario_gr_name,
                          "scenario_name": scenario_inst.__name__
                      })
            info = self._make_header(header)
            info += "\n\n"
            doc = utils.parse_docstring(scenario_inst.__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"]:
                args = inspect.getargspec(scenario_inst)
                if args.defaults:
                    default_values = dict(
                        zip(args.args[-len(args.defaults):], args.defaults))
                else:
                    default_values = {}
                info += "Parameters:\n"
                for param in doc["params"]:
                    info += "    - %(name)s: %(doc)s" % param

                    name = param["name"]
                    if name in default_values:
                        if default_values[name] is not None:
                            info += " [Default: %s]" % default_values[name]
                        else:
                            info += " [optional]"
                    info += "\n"
            if doc["returns"]:
                info += "Returns: %s" % doc["returns"]
            return info
        except exceptions.NoSuchScenario:
            return None
Exemple #4
0
    def _get_scenario_info(self, query):
        try:
            scenario_inst = scenario.Scenario.get_scenario_by_name(query)
            scenario_gr_name = utils.get_method_class(scenario_inst).get_name()
            header = ("%(scenario_group)s.%(scenario_name)s "
                      "(benchmark scenario)" %
                      {"scenario_group": scenario_gr_name,
                       "scenario_name": scenario_inst.__name__})
            info = self._make_header(header)
            info += "\n\n"
            doc = utils.parse_docstring(scenario_inst.__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"]:
                args = inspect.getargspec(scenario_inst)
                if args.defaults:
                    default_values = dict(zip(args.args[-len(args.defaults):],
                                              args.defaults))
                else:
                    default_values = {}
                info += "Parameters:\n"
                for param in doc["params"]:
                    info += "    - %(name)s: %(doc)s" % param

                    name = param["name"]
                    if name in default_values:
                        if default_values[name] is not None:
                            info += " [Default: %s]" % default_values[name]
                        else:
                            info += " [optional]"
                    info += "\n"
            if doc["returns"]:
                info += "Returns: %s" % doc["returns"]
            return info
        except exceptions.NoSuchScenario:
            return None
Exemple #5
0
 def test_method_class_for_module_level_method(self):
     self.assertIsNone(utils.get_method_class(module_level_method))
Exemple #6
0
    def test_method_class_for_class_level_method(self):
        class A(object):
            def m(self):
                pass

        self.assertEqual(A, utils.get_method_class(A.m))
Exemple #7
0
 def test_method_class_for_module_level_method(self):
     self.assertIsNone(utils.get_method_class(module_level_method))
Exemple #8
0
 def test_method_class_for_class_level_method(self):
     class A:
         def m(self):
             pass
     self.assertEqual(A, utils.get_method_class(A.m))