diff --git a/.gitignore b/.gitignore index 47c9018661ee..d872c09b46b9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ debug_coverage*/** analysis/** bin/** obj/** +.pytest_cache diff --git a/news/announce.py b/news/announce.py index af715d4c7e4e..895127b2d479 100644 --- a/news/announce.py +++ b/news/announce.py @@ -1,4 +1,8 @@ -"""Generate the changelog.""" +"""Generate the changelog. + +Usage: announce [--dry_run | --interim | --final] [] + +""" import enum import operator import os @@ -8,7 +12,7 @@ import sys import types -import click +import docopt FILENAME_RE = re.compile(r"(?P\d+)(?P-\S+)?\.md") @@ -117,15 +121,6 @@ class RunType(enum.Enum): final = 2 -@click.command() -@click.option('--dry-run', 'run_type', flag_value=RunType.dry_run, - help='validate input') -@click.option('--interim', 'run_type', flag_value=RunType.interim, default=True, - help='generate Markdown') -@click.option('--final', 'run_type', flag_value=RunType.final, - help='generate Markdown & `git rm` news files') -@click.argument('directory', default=pathlib.Path(__file__).parent, - type=click.Path(exists=True, file_okay=False)) def main(run_type, directory): directory = pathlib.Path(directory) data = gather(directory) @@ -137,4 +132,11 @@ def main(run_type, directory): if __name__ == '__main__': - main() + arguments = docopt.docopt(__doc__) + run_type = RunType.interim + for possible_run_type in RunType: + if arguments[f"--{possible_run_type.name}"]: + run_type = possible_run_type + break + directory = arguments[""] or pathlib.Path(__file__).parent + main(run_type, directory) diff --git a/news/requirements.txt b/news/requirements.txt index d47e9da45e5a..316eef65b021 100644 --- a/news/requirements.txt +++ b/news/requirements.txt @@ -1,2 +1,2 @@ -click~=6.7.0 +docopt==0.6.2 pytest~=3.4.1 diff --git a/news/test_announce.py b/news/test_announce.py index 6c9aa256bdc1..3270088b06b6 100644 --- a/news/test_announce.py +++ b/news/test_announce.py @@ -1,5 +1,6 @@ import pathlib +import docopt import pytest import announce as ann @@ -48,8 +49,7 @@ def test_sections_sorting(directory): def test_sections_naming(directory): (directory / 'Hello').mkdir() - with pytest.raises(ValueError): - list(ann.sections(directory)) + assert not ann.sections(directory) def test_gather(directory): @@ -79,8 +79,6 @@ def test_gather(directory): assert entries[1].description == 'Fix 2' - - def test_entry_markdown(): markdown = ann.entry_markdown(ann.NewsEntry(42, 'Hello, world!', None)) assert '42' in markdown @@ -126,3 +124,14 @@ def fake_git_rm(path): section, entries = results.pop() assert len(entries) == 1 assert rm_path == entries[0].path + + +def test_cli(): + for option in ("--"+opt for opt in ["dry_run", "interim", "final"]): + args = docopt.docopt(ann.__doc__, [option]) + assert args[option] + args = docopt.docopt(ann.__doc__, ["./news"]) + assert args[""] == "./news" + args = docopt.docopt(ann.__doc__, ["--dry_run", "./news"]) + assert args["--dry_run"] + assert args[""] == "./news"