Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
pytest
pytest-mock
12 changes: 11 additions & 1 deletion src/ustubby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,18 @@ def stub_function(f):
return "\n".join(expand_newlines(stub_ret))


def module_doc(mod):
s = """/*This file was auto-generated using uStubby.
https://github.com/pazzarpj/micropython-ustubby
"""
if mod.__doc__ is not None:
s += "\n" + mod.__doc__ + "\n"
s += "*/"
return s


def stub_module(mod):
stub_ret = [headers()]
stub_ret = [module_doc(mod), headers()]
classes = [o[1] for o in inspect.getmembers(mod) if inspect.isclass(o[1])]
functions = [o[1] for cls in classes for o in inspect.getmembers(cls) if inspect.isfunction(o[1])]
functions.extend([o[1] for o in inspect.getmembers(mod) if inspect.isfunction(o[1])])
Expand Down
22 changes: 22 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,25 @@ def MahonyAHRSupdate(gx: float, gy: float, gz: float, ax: float, ay: float, az:
call_lines = func.to_c().splitlines()
for index, line in enumerate(lines):
assert call_lines[index] == line

def test_module_comments_no_comment(mocker):
mocker.patch("ustubby.__doc__", None)
docs = ustubby.module_doc(ustubby)
assert docs == """/*This file was auto-generated using uStubby.
https://github.com/pazzarpj/micropython-ustubby
*/"""

def test_module_comments_with_comment(mocker):
mocker.patch("ustubby.__doc__", """Multi
line
comments
""")
docs = ustubby.module_doc(ustubby)
assert docs == """/*This file was auto-generated using uStubby.
https://github.com/pazzarpj/micropython-ustubby

Multi
line
comments

*/"""