Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help: support multiple examples #1403

Merged
merged 3 commits into from
Apr 20, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
test: Additional tests for module.example
Test the new `user_help` argument, making sure examples are included or
excluded properly based on its value.
  • Loading branch information
dgw committed Apr 17, 2019
commit 4358dc68974c21eeb4889188dd999d5b2e31d16a
78 changes: 78 additions & 0 deletions test/test_loader.py
Original file line number Diff line number Diff line change
@@ -326,6 +326,21 @@ def test_clean_callable_example(tmpconfig, func):
assert docs[1] == ['.test hello']


def test_clean_callable_example_not_set(tmpconfig, func):
module.commands('test')(func)

loader.clean_callable(func, tmpconfig)

assert hasattr(func, '_docs')
assert len(func._docs) == 1
assert 'test' in func._docs

docs = func._docs['test']
assert len(docs) == 2
assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
assert docs[1] == []


def test_clean_callable_example_multi_commands(tmpconfig, func):
module.commands('test')(func)
module.commands('unit')(func)
@@ -385,6 +400,53 @@ def test_clean_callable_example_first_only_multi_commands(tmpconfig, func):
assert test_docs[1] == ['.test hello']


def test_clean_callable_example_user_help(tmpconfig, func):
module.commands('test')(func)
module.example('.test hello', user_help=True)(func)

loader.clean_callable(func, tmpconfig)

assert len(func._docs) == 1
assert 'test' in func._docs

docs = func._docs['test']
assert len(docs) == 2
assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
assert docs[1] == ['.test hello']


def test_clean_callable_example_user_help_multi(tmpconfig, func):
module.commands('test')(func)
module.example('.test hello', user_help=True)(func)
module.example('.test bonjour', user_help=True)(func)

loader.clean_callable(func, tmpconfig)

assert len(func._docs) == 1
assert 'test' in func._docs

docs = func._docs['test']
assert len(docs) == 2
assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
assert docs[1] == ['.test hello', '.test bonjour']


def test_clean_callable_example_user_help_mixed(tmpconfig, func):
module.commands('test')(func)
module.example('.test hello')(func)
module.example('.test bonjour', user_help=True)(func)

loader.clean_callable(func, tmpconfig)

assert len(func._docs) == 1
assert 'test' in func._docs

docs = func._docs['test']
assert len(docs) == 2
assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
assert docs[1] == ['.test bonjour']


def test_clean_callable_example_default_prefix(tmpconfig, func):
module.commands('test')(func)
module.example('.test hello')(func)
@@ -416,6 +478,22 @@ def test_clean_callable_example_nickname(tmpconfig, func):
assert docs[1] == ['TestBot: hello']


def test_clean_callable_example_nickname_custom_prefix(tmpconfig, func):
module.commands('test')(func)
module.example('$nickname: hello')(func)

tmpconfig.core.help_prefix = '!'
loader.clean_callable(func, tmpconfig)

assert len(func._docs) == 1
assert 'test' in func._docs

docs = func._docs['test']
assert len(docs) == 2
assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
assert docs[1] == ['TestBot: hello']


def test_clean_callable_intents(tmpconfig, func):
setattr(func, 'intents', [r'abc'])
loader.clean_callable(func, tmpconfig)