def test_one_long_line(): """Test a line that needs to be wrapped.""" msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." assert format_message(msg) == os.linesep.join([ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do", "eiusmod tempor incididunt ut labore et dolore magna aliqua.", ])
def test_one_long_line(): """Test a line that needs to be wrapped.""" msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." assert format_message(msg) == os.linesep.join( [ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do", "eiusmod tempor incididunt ut labore et dolore magna aliqua.", ] )
def test_multiple_paragraphs(): assert format_message(LOREM_IPSUM) == os.linesep.join([ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do", "eiusmod tempor incididunt ut labore et dolore magna aliqua.", "", "Pharetra pharetra massa massa ultricies mi quis hendrerit.", "", "Dictumst vestibulum rhoncus est pellentesque. Sed viverra tellus in", "hac habitasse platea dictumst vestibulum rhoncus.", ])
def test_multiple_paragraphs(): assert format_message(LOREM_IPSUM) == os.linesep.join( [ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do", "eiusmod tempor incididunt ut labore et dolore magna aliqua.", "", "Pharetra pharetra massa massa ultricies mi quis hendrerit.", "", "Dictumst vestibulum rhoncus est pellentesque. Sed viverra tellus in", "hac habitasse platea dictumst vestibulum rhoncus.", ] )
def bmi_docstring( plugin, author=None, version=None, license=None, # pylint: disable=redefined-builtin doi=None, url=None, parameters=None, summary=None, cite_as=None, email=None, ): """Build the docstring for a BMI model. Parameters ---------- name : str Name of a BMI component. author : str, optional Name of author or authors. version : str, optional Version string for the component. license : str, optional Name of the license of the component. doi : str, optional A DOI for the component. url : str, optional URL of the component's location on the internet. parameters : iterable, optional List of input parameters for the component. Each parameter object must have attributes for name, type, value, units, and desc. cite_as : iterable of str, optional List of citations for this component. email : str, optional Contact email address. Returns ------- str The docstring. Examples -------- >>> from pymt.framework.bmi_docstring import bmi_docstring >>> print(bmi_docstring('Model', author='Walt Disney')) #doctest: +ELLIPSIS Basic Model Interface for Model. ... """ author = author or [] cite_as = cite_as or [] try: meta = PluginMetadata(plugin) except MetadataNotFoundError: if isinstance(plugin, six.string_types): info = dict( authors=author, version=version, license=license, doi=doi, url=url, summary=summary, cite_as=cite_as, ) defaults = {} name = plugin else: raise else: info = meta.info defaults = meta.parameters name = meta.name for param_name, param in defaults.items(): param["name"] = param_name defaults = defaults.values() author = author or info["authors"] email = email or "-" version = version or info["version"] license = license or info["license"] doi = doi or info["doi"] url = url or info["url"] summary = summary or info["summary"] cite_as = cite_as or info["cite_as"] parameters = parameters or defaults if isinstance(author, six.string_types): author = [author] if isinstance(cite_as, six.string_types): cite_as = [cite_as] summary = format_message(summary) env = jinja2.Environment( # nosec loader=jinja2.DictLoader({"docstring": _DOCSTRING})) return env.get_template("docstring").render( desc=summary, name=name, parameters=parameters, author=author, version=version, license=license, doi=doi, url=url, cite_as=cite_as, )
def test_multiline(): msg = """lorem ipsum """ assert format_message(msg) == 'lorem ipsum'
def test_leading_whitespace(): """Test a single line message.""" assert format_message(' lorem ipsum') == 'lorem ipsum'
def test_one_line(): """Test a single line message.""" assert format_message('lorem ipsum') == 'lorem ipsum'
def test_empty_message(): """Test formatting an empty string.""" assert format_message('') == ''
def test_multiline(): msg = """lorem ipsum """ assert_equal(format_message(msg), 'lorem ipsum')
def test_one_line(): """Test a single line message.""" assert_equal(format_message('lorem ipsum'), 'lorem ipsum')
def test_empty_message(): """Test formatting an empty string.""" assert_equal(format_message(''), '')
def bmi_docstring( plugin, author=None, version=None, license=None, # pylint: disable=redefined-builtin doi=None, url=None, parameters=None, summary=None, cite_as=None, email=None, ): """Build the docstring for a BMI model. Parameters ---------- name : str Name of a BMI component. author : str, optional Name of author or authors. version : str, optional Version string for the component. license : str, optional Name of the license of the component. doi : str, optional A DOI for the component. url : str, optional URL of the component's location on the internet. parameters : iterable, optional List of input parameters for the component. Each parameter object must have attributes for name, type, value, units, and desc. cite_as : iterable of str, optional List of citations for this component. email : str, optional Contact email address. Returns ------- str The docstring. Examples -------- >>> from pymt.framework.bmi_docstring import bmi_docstring >>> print(bmi_docstring('Model', author='Walt Disney')) #doctest: +ELLIPSIS Basic Model Interface for Model. ... """ author = author or [] cite_as = cite_as or [] try: meta = PluginMetadata(plugin) except MetadataNotFoundError: if isinstance(plugin, six.string_types): info = dict( authors=author, version=version, license=license, doi=doi, url=url, summary=summary, cite_as=cite_as, ) defaults = {} name = plugin else: raise else: info = meta.info defaults = meta.parameters name = meta.name for param_name, param in defaults.items(): param["name"] = param_name defaults = defaults.values() author = author or info["authors"] email = email or "-" version = version or info["version"] license = license or info["license"] doi = doi or info["doi"] url = url or info["url"] summary = summary or info["summary"] cite_as = cite_as or info["cite_as"] parameters = parameters or defaults if isinstance(author, six.string_types): author = [author] if isinstance(cite_as, six.string_types): cite_as = [cite_as] summary = format_message(summary) env = jinja2.Environment( # nosec loader=jinja2.DictLoader({"docstring": _DOCSTRING}) ) return env.get_template("docstring").render( desc=summary, name=name, parameters=parameters, author=author, version=version, license=license, doi=doi, url=url, cite_as=cite_as, )