Skip to content

Commit

Permalink
add unit tests to test current output of indented docsrings for googl…
Browse files Browse the repository at this point in the history
…e, pydocmd and sphinx processors (see #259)
  • Loading branch information
NiklasRosenstein committed Apr 25, 2022
1 parent 16b3345 commit b15127e
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ tag-format = "v{version}"
dev-extras = []

[tool.slap.test]
pytest = "pytest test/ --cov=./src/pydoc_markdown --cov-report html:htmlcov"
pytest = "pytest test/ --cov=./src/pydoc_markdown --cov-report html:htmlcov -vv"
mypy = "mypy src/ --check-untyped-defs --namespace-packages --exclude src/pydoc_markdown/novella"
isort = "isort src test --check-only"
black = "black src test --check"
Expand Down
8 changes: 5 additions & 3 deletions test/renderers/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
from pydoc_markdown.contrib.processors.filter import FilterProcessor
from pydoc_markdown.contrib.processors.smart import SmartProcessor
from pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer
from pydoc_markdown.interfaces import Context
from pydoc_markdown.interfaces import Context, Processor

from ..utils import Case, assert_text_equals, get_testcases_for, load_testcase
from ..utils import assert_text_equals, get_testcases_for, load_testcase


@dataclasses.dataclass
class MarkdownTestConfig:
renderer: MarkdownRenderer = dataclasses.field(default_factory=MarkdownRenderer)
filter: FilterProcessor = dataclasses.field(default_factory=FilterProcessor)
parser: ParserOptions = dataclasses.field(default_factory=ParserOptions)
processor: Processor = dataclasses.field(default_factory=SmartProcessor)

def init(self, context: Context) -> None:
self.renderer.init(context)
self.filter.init(context)
self.processor.init(context)


def load_string_as_module(
Expand Down Expand Up @@ -73,6 +75,6 @@ def test_markdown_renderer(filename: str) -> None:
config.init(Context("."))
modules = [load_string_as_module(case.filename, case.code, options=config.parser)]
config.filter.process(modules, None)
SmartProcessor().process(modules, None)
config.processor.process(modules, None)
result = config.renderer.render_to_string(modules)
assert_text_equals(result, case.output)
59 changes: 59 additions & 0 deletions test/testcases/renderers/markdown/indented_docstring_google.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
----
renderer:
insert_header_anchors: false
render_module_header: false
processor:
type: google
----
def a(v: int) -> None:
""" This is a docstring.

Args:
v: The value.
Return:
None

Example:

>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```
"""
----
#### a

```python
def a(v: int) -> None
```

This is a docstring.

**Arguments**:

- `v` - The value.

**Returns**:

None


**Example**:


>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```
44 changes: 44 additions & 0 deletions test/testcases/renderers/markdown/indented_docstring_pydocmd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
----
renderer:
insert_header_anchors: false
render_module_header: false
processor:
type: pydocmd
----
def a():
""" This is a docstring.

Example:

>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```
"""
----
#### a

```python
def a()
```

This is a docstring.

Example:

>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```
54 changes: 54 additions & 0 deletions test/testcases/renderers/markdown/indented_docstring_sphinx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
----
renderer:
insert_header_anchors: false
render_module_header: false
processor:
type: sphinx
----
def a(v: int) -> None:
""" This is a docstring.

:param v: The value.
:return: None

Example:

>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```
"""
----
#### a

```python
def a(v: int) -> None
```

This is a docstring.

**Arguments**:

- `v`: The value.

**Returns**:

None
Example:

>>> import os
>>> os.getenv('PYTHON')
'python'

Or check out this code:

```py
def foo():
print("Hello, World!")
```

0 comments on commit b15127e

Please sign in to comment.