Python click.__version__() Examples

The following are 10 code examples of click.__version__(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module click , or try the search function .
Example #1
Source File: test_cli.py    From covimerage with MIT License 6 votes vote down vote up
def test_cli_write_coverage(runner, tmpdir):
    with tmpdir.as_cwd() as old_dir:
        with pytest.raises(SystemExit) as excinfo:
            cli.write_coverage([os.path.join(
                str(old_dir), 'tests/fixtures/conditional_function.profile')])
        assert excinfo.value.code == 0
        assert os.path.exists(DEFAULT_COVERAGE_DATA_FILE)

    result = runner.invoke(cli.main, ['write_coverage', '/does/not/exist'])
    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

    result = runner.invoke(cli.main, ['write_coverage'])
    if click.__version__ < '7.0':
        expected = 'Error: Missing argument "profile_file".'
    else:
        expected = 'Error: Missing argument "PROFILE_FILE...".'
    assert result.output.splitlines()[-1] == expected
    assert result.exit_code == 2 
Example #2
Source File: telemetry.py    From web2board with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        try:
            result = util.exec_command(["scons", "--version"])
            match = re.search(r"engine: v([\d\.]+)", result['out'])
            if match:
                dpdata.append("SCons/%s" % match.group(1))
        except:  # pylint: disable=W0702
            pass
        self['an'] = " ".join(dpdata) 
Example #3
Source File: test_cli.py    From covimerage with MIT License 5 votes vote down vote up
def test_cli_call(capfd):
    assert call(['covimerage', '--version']) == 0
    out, err = capfd.readouterr()
    assert out == get_version_message() + '\n'

    assert call(['covimerage', '--help']) == 0
    out, err = capfd.readouterr()
    assert out.startswith('Usage:')

    assert call(['covimerage', 'file not found']) == 2
    out, err = capfd.readouterr()
    err_lines = err.splitlines()
    assert err_lines[0] == 'Usage: covimerage [OPTIONS] COMMAND [ARGS]...'
    # click after 6.7 (9cfea14) includes: 'Try "covimerage --help" for help.'
    assert err_lines[-2:] == [
        '',
        'Error: No such command "file not found".']
    assert out == ''

    assert call(['covimerage', 'write_coverage', 'file not found']) == 2
    out, err = capfd.readouterr()
    err_lines = err.splitlines()
    assert err_lines[-1] == (
        '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 == '' 
Example #4
Source File: test_cli.py    From covimerage with MIT License 5 votes vote down vote up
def test_report_profile_or_data_file(runner, tmpdir):
    from covimerage.cli import DEFAULT_COVERAGE_DATA_FILE

    result = runner.invoke(cli.main, [
        'report', '--data-file', '/does/not/exist'])
    assert result.output.splitlines()[-1] == \
        'Error: Invalid value for "--data-file": Could not open file: /does/not/exist: No such file or directory'
    assert result.exit_code == 2

    result = runner.invoke(cli.main, [
        'report', '--data-file', os.devnull])
    cov_exc = 'CoverageException: Doesn\'t seem to be a coverage.py data file'
    assert result.output.splitlines()[-1] == \
        'Error: Coverage could not read data_file: /dev/null (%s)' % cov_exc
    assert result.exit_code == 1

    with tmpdir.as_cwd():
        result = runner.invoke(cli.main, ['report'])
    assert result.output.splitlines()[-1] == \
        'Error: Invalid value for "--data-file": Could not open file: %s: No such file or directory' % DEFAULT_COVERAGE_DATA_FILE
    assert result.exit_code == 2

    result = runner.invoke(cli.main, ['report', '/does/not/exist'])
    assert result.output.splitlines()[-1] == \
        '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, [
        '--rcfile', os.devnull,
        'report', 'tests/fixtures/merged_conditionals-0.profile'])
    assert result.output.splitlines() == [
        'Name                                        Stmts   Miss  Cover',
        '---------------------------------------------------------------',
        'tests/test_plugin/merged_conditionals.vim      19     12    37%']
    assert result.exit_code == 0 
Example #5
Source File: test_cli.py    From covimerage with MIT License 5 votes vote down vote up
def test_run_cmd_requires_args(runner):
    result = runner.invoke(cli.run, [])
    assert 'Error: Missing argument "%s".' % (
        'args' if click.__version__ < '7.0' else 'ARGS...',
    ) in result.output.splitlines()
    assert result.exit_code == 2 
Example #6
Source File: test_patch.py    From git-pw with MIT License 5 votes vote down vote up
def test_update_with_invalid_state(
            self, mock_states, mock_show, mock_update):
        """Validate behavior with invalid state."""

        mock_states.return_value = ['foo']

        runner = CLIRunner()
        result = runner.invoke(patch.update_cmd, [
            '123', '--state', 'bar'])

        assert result.exit_code == 2, result
        if version.parse(click.__version__) >= version.Version('7.1'):
            assert "Invalid value for '--state'" in result.output, result
        else:
            assert 'Invalid value for "--state"' in result.output, result 
Example #7
Source File: __main__.py    From gd.py with MIT License 5 votes vote down vote up
def collect_versions() -> Generator[str, None, None]:
    yield f"- python {version_from_info(sys.version_info)}"
    yield f"- gd.py {version_from_info(gd.version_info)}"
    yield f"- aiohttp v{aiohttp.__version__}"
    yield f"- click v{click.__version__}"
    yield "- system {0.system} {0.release} {0.version}".format(platform.uname())


# run main 
Example #8
Source File: cmd_version.py    From python-alerta-client with Apache License 2.0 5 votes vote down vote up
def cli(ctx, obj):
    """Show Alerta server and client versions."""
    client = obj['client']
    click.echo('alerta {}'.format(client.mgmt_status()['version']))
    click.echo('alerta client {}'.format(client_version))
    click.echo('requests {}'.format(requests_version))
    click.echo('click {}'.format(click.__version__))
    ctx.exit() 
Example #9
Source File: core.py    From click-man with MIT License 5 votes vote down vote up
def write_man_pages(name, cli, parent_ctx=None, version=None, target_dir=None):
    """
    Generate man page files recursively
    for the given click cli function.

    :param str name: the cli name
    :param cli: the cli instance
    :param click.Context parent_ctx: the parent click context
    :param str target_dir: the directory where the generated
                           man pages are stored.
    """
    ctx = click.Context(cli, info_name=name, parent=parent_ctx)

    man_page = generate_man_page(ctx, version)
    path = '{0}.1'.format(ctx.command_path.replace(' ', '-'))
    if target_dir:
        path = os.path.join(target_dir, path)

    with open(path, 'w+') as f:
        f.write(man_page)

    commands = getattr(cli, 'commands', {})
    for name, command in commands.items():
        if LooseVersion(click.__version__) >= LooseVersion("7.0"):
            # Since Click 7.0, we have been able to mark commands as hidden
            if command.hidden:
                # Do not write a man page for a hidden command
                continue
        write_man_pages(name, command, parent_ctx=ctx, version=version, target_dir=target_dir) 
Example #10
Source File: test_cli.py    From covimerage with MIT License 4 votes vote down vote up
def test_report_source(runner, tmpdir, devnull):
    with tmpdir.as_cwd():
        result = runner.invoke(cli.main, ["report", "--source", ".", "/does/not/exist"])
        assert (
            result.output.splitlines()[-1]
            == '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

        fname = "foo/bar/test.vim"
        tmpdir.join(fname).ensure().write("echom 1")
        tmpdir.join("foo/bar/test2.vim").ensure().write("echom 2")
        result = runner.invoke(cli.main, ["report", "--source", ".", devnull.name])
        out = result.output.splitlines()
        assert any(l.startswith(fname) for l in out)  # pragma: no branch
        assert out[-1].startswith("TOTAL")
        assert out[-1].endswith(" 0%")
        assert result.exit_code == 0

        result = runner.invoke(cli.main, ["report", devnull.name, "--source", "."])
        out = result.output.splitlines()
        assert any(fname in l for l in out)  # pragma: no branch
        assert out[-1].startswith("TOTAL")
        assert out[-1].endswith(" 0%")
        assert result.exit_code == 0

        result = runner.invoke(cli.main, ["report", "--source", "."])
        out = result.output.splitlines()
        assert out[-1] == "Error: --source can only be used with PROFILE_FILE."
        assert result.exit_code == 2

    result = runner.invoke(
        cli.main,
        [
            "--rcfile",
            devnull.name,
            "report",
            "--source",
            "tests/test_plugin/merged_conditionals.vim",
            "tests/fixtures/merged_conditionals-0.profile",
        ],
    )
    assert (
        result.output.splitlines()
        == [
            "Name                                        Stmts   Miss  Cover",
            "---------------------------------------------------------------",
            "tests/test_plugin/merged_conditionals.vim      19     12    37%",
        ]
    )
    assert result.exit_code == 0