diff options
Diffstat (limited to 'mmi2grpc/_description.py')
-rw-r--r-- | mmi2grpc/_description.py | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/mmi2grpc/_description.py b/mmi2grpc/_description.py deleted file mode 100644 index c292720..0000000 --- a/mmi2grpc/_description.py +++ /dev/null @@ -1,60 +0,0 @@ -import functools -import unittest -import textwrap - -COMMENT_WIDTH = 80 - 8 # 80 cols - 8 indentation space - - -def assert_description(f): - @functools.wraps(f) - def wrapper(*args, **kwargs): - description = textwrap.fill( - kwargs["description"], COMMENT_WIDTH, replace_whitespace=False) - docstring = textwrap.dedent(f.__doc__ or "") - - if docstring.strip() != description.strip(): - print(f'Expected description of {f.__name__}:') - print(description) - - # Generate AssertionError - test = unittest.TestCase() - test.maxDiff = None - test.assertMultiLineEqual( - docstring.strip(), - description.strip(), - f'description does not match with function docstring of {f.__name__}') - - return f(*args, **kwargs) - return wrapper - - -def format_function(id, description): - wrapped = textwrap.fill( - description, COMMENT_WIDTH, replace_whitespace=False) - return ( - f'@assert_description\n' - f'def {id}(self, **kwargs):\n' - f' """\n' - f'{textwrap.indent(wrapped, " ")}\n' - f' """\n' - f'\n' - f' return "OK"\n' - ) - - -def format_proxy(profile, id, description): - return ( - f'from ._description import assert_description\n' - f'from ._proxy import ProfileProxy\n' - f'\n' - f'from pandora.{profile.lower()}_grpc import {profile}\n' - f'\n' - f'\n' - f'class {profile}Proxy(ProfileProxy):\n' - f'\n' - f' def __init__(self, channel):\n' - f' super().__init__()\n' - f' self.{profile.lower()} = {profile}(channel)\n' - f'\n' - f'{textwrap.indent(format_function(id, description), " ")}' - ) |