Skip to content

Commit

Permalink
Merge pull request #59 from blueyed/click
Browse files Browse the repository at this point in the history
Click 7 compatibility
  • Loading branch information
blueyed authored Oct 11, 2018
2 parents 621ba8c + 3c138ab commit 0fc6e53
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
25 changes: 12 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ common: &common
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v1-deps-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}
- run: pip install --user tox
- run: PYTEST_ADDOPTS=-vv ~/.local/bin/tox
- run:
Expand All @@ -35,42 +32,43 @@ common: &common
fi
set +x
fi
- save_cache:
paths:
- .tox
- ~/.cache/pip
key: v1-deps-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}
jobs:
py37:
<<: *common
docker:
- image: circleci/python:3.7
environment:
TOXENV=py37-coverage
- TOXENV=py37-coverage
py36:
<<: *common
docker:
- image: circleci/python:3.6
environment:
TOXENV=py36-coverage
- TOXENV=py36-coverage
py35:
<<: *common
docker:
- image: circleci/python:3.5
environment:
TOXENV=py35-coverage
- TOXENV=py35-coverage
py34:
<<: *common
docker:
- image: circleci/python:3.4
environment:
TOXENV=py34-coverage
- TOXENV=py34-coverage
py27:
<<: *common
docker:
- image: circleci/python:2.7
environment:
TOXENV=py27-coverage
- TOXENV=py27-coverage
py37-click6:
<<: *common
docker:
- image: circleci/python:3.7
environment:
- TOXENV=py37-click6-coverage
checkqa:
<<: *common
docker:
Expand All @@ -83,6 +81,7 @@ workflows:
test:
jobs:
- py37
- py37-click6
- py36
- py35
- py34
Expand Down
2 changes: 1 addition & 1 deletion covimerage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main(ctx, verbose, quiet, loglevel, rcfile):
ctx.obj = {'rcfile': rcfile}


@main.command()
@main.command(name='write_coverage')
@click.argument('profile_file', type=click.File('r'), required=False, nargs=-1)
@click.option('--data-file', required=False, type=click.Path(dir_okay=False),
default=DEFAULT_COVERAGE_DATA_FILE,
Expand Down
23 changes: 17 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
import time

import click
import pytest

from covimerage import DEFAULT_COVERAGE_DATA_FILE, cli, get_version
Expand All @@ -32,8 +33,13 @@ def test_cli(runner, tmpdir):
assert os.path.exists(DEFAULT_COVERAGE_DATA_FILE)

result = runner.invoke(cli.main, ['write_coverage', '/does/not/exist'])
assert result.output.splitlines()[-1].startswith(
'Error: Invalid value for "profile_file": Could not open file:')
if click.__version__ < '7.0':
assert result.output.splitlines()[-1].startswith(
'Error: Invalid value for "profile_file": Could not open file:')
else:
assert result.output.splitlines()[-1].startswith(
'Error: Invalid value for "[PROFILE_FILE]...": Could not open file:')

assert result.exit_code == 2


Expand Down Expand Up @@ -296,7 +302,8 @@ def test_cli_call(capfd):
out, err = capfd.readouterr()
err_lines = err.splitlines()
assert err_lines[-1] == (
'Error: Invalid value for "profile_file": Could not open file: file not found: No such file or directory')
'Error: Invalid value for "%s": Could not open file: file not found: No such file or directory' % (
"profile_file" if click.__version__ < '7.0' else "[PROFILE_FILE]...",))
assert out == ''


Expand Down Expand Up @@ -474,7 +481,8 @@ def test_report_profile_or_data_file(runner, tmpdir):

result = runner.invoke(cli.main, ['report', '/does/not/exist'])
assert result.output.splitlines()[-1] == \
'Error: Invalid value for "profile_file": Could not open file: /does/not/exist: No such file or directory'
'Error: Invalid value for "%s": Could not open file: /does/not/exist: No such file or directory' % (
'profile_file' if click.__version__ < '7.0' else '[PROFILE_FILE]...',)
assert result.exit_code == 2

result = runner.invoke(cli.main, [
Expand Down Expand Up @@ -520,7 +528,8 @@ def test_report_source(runner, tmpdir, devnull):
result = runner.invoke(cli.main, ["report", "--source", ".", "/does/not/exist"])
assert (
result.output.splitlines()[-1]
== 'Error: Invalid value for "profile_file": Could not open file: /does/not/exist: No such file or directory'
== 'Error: Invalid value for "%s": Could not open file: /does/not/exist: No such file or directory' % (
'profile_file' if click.__version__ < '7.0' else '[PROFILE_FILE]...',)
)
assert result.exit_code == 2

Expand Down Expand Up @@ -766,5 +775,7 @@ def test_run_forwards_sighup(devnull):

def test_run_cmd_requires_args(runner):
result = runner.invoke(cli.run, [])
assert 'Error: Missing argument "args".' in result.output.splitlines()
assert 'Error: Missing argument "%s".' % (
'args' if click.__version__ < '7.0' else 'ARGS...',
) in result.output.splitlines()
assert result.exit_code == 2
21 changes: 15 additions & 6 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from imp import reload
import logging

import click
import pytest


Expand Down Expand Up @@ -29,12 +30,22 @@ def test_loglevel(mocker, runner, devnull):

m = mocker.patch.object(logger, 'setLevel')

def assert_output(result):
if click.__version__ < '7.0':
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
else:
assert result.output.splitlines() == [
'Usage: main report [OPTIONS] [PROFILE_FILE]...',
'Try "main report -h" for help.',
'',
'Error: no such option: --nonexistingoption']

for level in ['error', 'warning', 'info', 'debug']:
result = runner.invoke(cli.main, [
'--loglevel', level,
'report', '--nonexistingoption'])
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
assert_output(result)
assert result.exit_code == 2

level_name = level.upper()
Expand All @@ -45,8 +56,7 @@ def test_loglevel(mocker, runner, devnull):
result = runner.invoke(cli.main, [
'-l', 'warning', '-vvv',
'report', '--nonexistingoption'])
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
assert_output(result)
assert result.exit_code == 2
assert m.call_args_list == [mocker.call('WARNING')]

Expand All @@ -55,8 +65,7 @@ def test_loglevel(mocker, runner, devnull):
result = runner.invoke(cli.main, [
'-l', 'warning', '-qqq',
'report', '--nonexistingoption'])
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
assert_output(result)
assert result.exit_code == 2
assert m.call_args_list == [mocker.call('WARNING')]

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ setenv =
dev: TOX_EXTRAS=testing,dev
changedir =
integration: {envtmpdir}
deps =
click6: click<7

[testenv:checkqa]
extras = qa
Expand Down

0 comments on commit 0fc6e53

Please sign in to comment.