Skip to content

Commit

Permalink
Autodoc fixes and tweaks (#128)
Browse files Browse the repository at this point in the history
* autodoc fixes and tweaks

* black

* update release notes
  • Loading branch information
benbovy committed Apr 12, 2020
1 parent 9cf90a3 commit f0e1e1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
1 change: 1 addition & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Bug fixes
~~~~~~~~~

- Fix running batches of simulations using ``dask.distributed`` (:issue:`124`).
- Fix rendering of auto-generated docstrings of process classes (:issue:`128`).

v0.4.0 (7 April 2020)
---------------------
Expand Down
4 changes: 2 additions & 2 deletions xsimlab/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def var_details(var, max_line_length=70):


def add_attribute_section(process, placeholder="{{attributes}}"):
data_type = "object" # placeholder until issue #34 is solved
data_type = ":class:`attr.Attribute`"

fmt_vars = []

Expand All @@ -124,7 +124,7 @@ def add_attribute_section(process, placeholder="{{attributes}}"):
if placeholder in current_doc:
new_doc = current_doc.replace(placeholder, fmt_section[4:])
else:
new_doc = f"{current_doc}\n{fmt_section}\n"
new_doc = f"{current_doc.rstrip()}\n\n{fmt_section}\n"

return new_doc

Expand Down
53 changes: 25 additions & 28 deletions xsimlab/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,33 @@ def test_var_details(example_process_obj):
assert "- dims : (('x',),)" in var_details_str


def test_add_attribute_section():
"""For testing, autodoc is set to False to avoid redundancy"""
@xs.process(autodoc=False)
class WithoutPlaceHolder:
"""My process"""

var1 = xs.variable(dims="x", description="a variable")
var2 = xs.variable()


@xs.process(autodoc=False)
class WithPlaceholder:
"""My process
@xs.process(autodoc=False)
class Dummy:
"""This is a Dummy class
to test `add_attribute_section()`
"""

var1 = xs.variable(dims="x", description="a variable")
var2 = xs.variable()

@xs.process(autodoc=False)
class Dummy_placeholder:
"""This is a Dummy class
to test `add_attribute_section()`
{{attributes}}
"""
var1 = xs.variable(dims="x", description="a variable")
var2 = xs.variable()
"""

var1 = xs.variable(dims="x", description="a variable")
var2 = xs.variable()


def test_add_attribute_section():
# For testing, autodoc is set to False to avoid redundancy
expected = """My process
expected = """This is a Dummy class
to test `add_attribute_section()`
Attributes
----------
var1 : object
var1 : :class:`attr.Attribute`
A variable
- type : variable
Expand All @@ -82,7 +80,7 @@ class Dummy_placeholder:
- attrs : {}
- encoding : {}
var2 : object
var2 : :class:`attr.Attribute`
(no description given)
- type : variable
Expand All @@ -92,11 +90,10 @@ class Dummy_placeholder:
- static : False
- attrs : {}
- encoding : {}
"""

"""

assert add_attribute_section(Dummy) == expected
assert add_attribute_section(Dummy_placeholder) == expected
assert add_attribute_section(WithoutPlaceHolder).strip() == expected.strip()
assert add_attribute_section(WithPlaceholder).strip() == expected.strip()


def test_process_repr(
Expand Down

0 comments on commit f0e1e1a

Please sign in to comment.