def _generate_test_case(self, object, module): class_name = name2testname(camelize(object.name)) method_descriptions = resolve_name_duplicates(sorted_test_method_descriptions(self._generate_test_method_descriptions(object, module))) # Don't generate empty test classes. if method_descriptions: body = self._generate_test_class_code(class_name, method_descriptions) return self._generate_test_class(class_name, method_descriptions, module, body)
def _generate_test_method_descriptions_for_function(self, function, module): if testable_calls(function.calls): log.debug("Detected %s in function %s." % \ (pluralize("testable call", len(testable_calls(function.calls))), function.name)) # We're calling the function, so we have to make sure it will # be imported in the test self.ensure_import((module.locator, function.name)) # We have at least one call registered, so use it. return self._method_descriptions_from_function(function) else: # No calls were traced, so we'll go for a single test stub. log.debug("Detected _no_ testable calls in function %s." % function.name) name = name2testname(underscore(function.name)) return [TestMethodDescription(name, generate_test_case(function, self.template))]
def _generate_test_method_description_for_method(self, method): test_name = name2testname(method.name) return TestMethodDescription(test_name, generate_test_case(method, self.template))