def test_parse_doc(): doc = parse_doc(tg_mean.__doc__) assert doc["title"] == "Mean of daily average temperature." assert ( doc["abstract"] == "Resample the original daily mean temperature series by taking the mean over each period." ) assert ( doc["parameters"]["tas"]["description"] == "Mean daily temperature [℃] or [K]" ) assert ( doc["parameters"]["freq"]["description"] == 'Resampling frequency; Defaults to "YS" (yearly).' ) assert doc["notes"].startswith("Let") assert "math::" in doc["notes"] assert "references" not in doc assert doc["long_name"] == "The mean daily temperature at the given time frequency" doc = parse_doc(xclim.indices.saturation_vapor_pressure.__doc__) assert ( doc["parameters"]["ice_thresh"]["description"] == "Threshold temperature under which to switch to equations in reference to ice instead of water. If None (default) everything is computed with reference to water." ) assert "Goff, J. A., and S. Gratch (1946)" in doc["references"]
def __init__(self, **kwds): # Set instance attributes. for key, val in kwds.items(): setattr(self, key, val) # Verify that the identifier is a proper slug if not re.match(r"^[-\w]+$", self.identifier): warnings.warn( "The identifier contains non-alphanumeric characters. It could make life " "difficult for downstream software reusing this class.", UserWarning, ) # Default value for `var_name` is the `identifier`. if self.var_name == "": self.var_name = self.identifier # Extract information from the `compute` function. # The signature self._sig = signature(self.compute) # The input parameter names self._parameters = tuple(self._sig.parameters.keys()) # self._input_params = [p for p in self._sig.parameters.values() if p.default is p.empty] # self._nvar = len(self._input_params) # Copy the docstring and signature self.__call__ = wraps(self.compute)(self.__call__.__func__) if self.doc_template is not None: self.__call__.__doc__ = self.doc_template.format(i=self) # Fill in missing metadata from the doc meta = parse_doc(self.compute.__doc__) for key in ["abstract", "title", "notes", "references"]: setattr(self, key, getattr(self, key) or meta.get(key, ""))
def test_parse_doc(): parse_doc(tg_mean.__doc__)