diff --git a/requirements-test.txt b/requirements-test.txt index 55b033e..1d6ed5c 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1 +1,2 @@ -pytest \ No newline at end of file +pytest +pytest-mock \ No newline at end of file diff --git a/src/ustubby/__init__.py b/src/ustubby/__init__.py index c55169f..9f0656e 100644 --- a/src/ustubby/__init__.py +++ b/src/ustubby/__init__.py @@ -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])]) diff --git a/test/test_basic.py b/test/test_basic.py index 4299710..c6493ac 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -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 + +*/"""