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

Add tests for the CLI #21

Merged
merged 3 commits into from Aug 17, 2018
Merged

Conversation

jeremycline
Copy link
Member

Also fix a small bug from exception changes in config.py

@codecov-io
Copy link

codecov-io commented Aug 3, 2018

Codecov Report

Merging #21 into master will increase coverage by 5.62%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
+ Coverage   82.52%   88.14%   +5.62%     
==========================================
  Files          10       10              
  Lines         744      751       +7     
  Branches      104      105       +1     
==========================================
+ Hits          614      662      +48     
+ Misses        108       61      -47     
- Partials       22       28       +6
Impacted Files Coverage Δ
fedora_messaging/config.py 100% <100%> (+1.44%) ⬆️
fedora_messaging/exceptions.py 100% <100%> (ø) ⬆️
fedora_messaging/cli.py 66.17% <100%> (+66.17%) ⬆️
fedora_messaging/api.py 73.91% <0%> (-4.35%) ⬇️
fedora_messaging/_session.py 80.54% <0%> (-0.46%) ⬇️
fedora_messaging/message.py 94.89% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a99a24...3bbb12c. Read the comment docs.

@@ -87,7 +90,7 @@ def cli(conf):
@click.option('--exchange', help=_exchange_help)
@click.option('--amqp-url', help=_amqp_url_help)
def consume(amqp_url, exchange, queue_name, routing_key, callback, app_name):

"""Consume messages from an AMQP queue using a Python callback."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to also document the params and their types, but this is still an improvement over what was there before so feel free to defer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check, but I believe click uses this docblock for user help, and it also renders the options help, so unfortunately it looks weird when you add the standard docblocks. I think I can add type hints to the click options, though.

_log.error('Failed to parse {}: {}'.format(config_path, str(e)))
raise exceptions.ConfigurationException(e)
msg = 'Failed to parse {}: error at line {}, column {}'.format(
config_path, e.line, e.col)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@@ -8,6 +8,12 @@ class BaseException(Exception):
class ConfigurationException(BaseException):
"""Raised when there's an invalid configuration setting"""

def __init__(self, message):
self.message = message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to document the type of message.

@@ -0,0 +1 @@
publish_exchange = I forgot quotes here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, GitHub does not like this.

import unittest

from click.testing import CliRunner
import mock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python 3 mock is a built-in, and we're almost Python3-y.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me sad every time 😿

"""Assert a bad configuration file is reported."""
runner = CliRunner()
result = runner.invoke(cli.cli, ['--conf=' + BAD_CONF, 'consume'])
self.assertEqual(2, result.exit_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to check that the error message contains some expected text.

"""Assert a missing configuration file is reported."""
runner = CliRunner()
result = runner.invoke(cli.cli, ['--conf=thispathdoesnotexist', 'consume'])
self.assertEqual(2, result.exit_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here.

If a configuration file is explicitly specified, report an error if the
file doesn't exist. Additionally, handle a configuration exception
during configuration loading.

Signed-off-by: Jeremy Cline <jcline@redhat.com>
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Signed-off-by: Jeremy Cline <jcline@redhat.com>
@jeremycline jeremycline merged commit a2783c8 into fedora-infra:master Aug 17, 2018
@jeremycline jeremycline deleted the cli-tests branch August 17, 2018 11:03
@bowlofeggs
Copy link
Contributor

bowlofeggs commented Aug 17, 2018 via email

@jeremycline
Copy link
Member Author

Ah, neato.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants