From 60b70854785a4490f9c1aad0367e9ac0cbdfa0b5 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Fri, 11 Sep 2020 14:08:56 +0300 Subject: [PATCH 1/2] Put Python module description to C code --- src/ustubby/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ustubby/__init__.py b/src/ustubby/__init__.py index c55169f..f774946 100644 --- a/src/ustubby/__init__.py +++ b/src/ustubby/__init__.py @@ -337,8 +337,16 @@ def stub_function(f): return "\n".join(expand_newlines(stub_ret)) +def module_doc(mod): + s = '''// This file was developed using uStubby. +// https://github.com/pazzarpj/micropython-ustubby +''' + if mod.__doc__ is not None: + s += '\n/*'+ mod.__doc__ + '*/\n' + 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])]) From c7c542ffde0c5be20418bae6a4825e5b8d8265b7 Mon Sep 17 00:00:00 2001 From: pazzarpj Date: Thu, 24 Sep 2020 22:57:12 +1000 Subject: [PATCH 2/2] feature/16 - Updated tests - Replace developed with auto-generated --- requirements-test.txt | 3 ++- src/ustubby/__init__.py | 10 ++++++---- test/test_basic.py | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) 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 f774946..9f0656e 100644 --- a/src/ustubby/__init__.py +++ b/src/ustubby/__init__.py @@ -338,13 +338,15 @@ def stub_function(f): def module_doc(mod): - s = '''// This file was developed using uStubby. -// https://github.com/pazzarpj/micropython-ustubby -''' + 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 += "\n" + mod.__doc__ + "\n" + s += "*/" return s + def stub_module(mod): stub_ret = [module_doc(mod), headers()] classes = [o[1] for o in inspect.getmembers(mod) if inspect.isclass(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 + +*/"""