From 7aa99019cb91225c07a58d40aa0ca743fda2ddae Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 25 Apr 2018 09:10:57 -0400 Subject: [PATCH 1/2] Allow adding multiple tickers via CLI --- piker/cli.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/piker/cli.py b/piker/cli.py index c971ed3d..cb637f71 100644 --- a/piker/cli.py +++ b/piker/cli.py @@ -206,11 +206,12 @@ def load(ctx, data): @watchlists.command(help='add ticker to watchlist') @click.argument('name', nargs=1, required=True) -@click.argument('ticker_name', nargs=1, required=True) +@click.argument('ticker_names', nargs=-1, required=True) @click.pass_context -def add(ctx, name, ticker_name): - watchlist = wl.add_ticker(name, ticker_name, - ctx.obj['watchlist']) +def add(ctx, name, ticker_names): + for ticker in ticker_names: + watchlist = wl.add_ticker( + name, ticker, ctx.obj['watchlist']) wl.write_to_file(watchlist, ctx.obj['path']) From c8539b73733d6d80f5dac39121cdceaa52a65bb5 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 25 Apr 2018 09:11:21 -0400 Subject: [PATCH 2/2] Test adding multiple tickers on cli --- tests/test_cli.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 6ec88150..2273410a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -150,9 +150,15 @@ def test_dump_watchlists(capfd, piker_dir, ex_watchlists): assert out.strip() == expected_out -def test_ticker_added_to_watchlists(capfd, piker_dir, ex_watchlists): - ex_watchlists['pharma'].append('CRACK') - run(f"piker watchlists -d {piker_dir} add pharma CRACK") +@pytest.mark.parametrize( + 'tickers', [('CRACK',), ('CRACK', 'SUIT',)] +) +def test_ticker_added_to_watchlists(capfd, piker_dir, ex_watchlists, tickers): + """Verify that single or multi-ticker lists can be added. + """ + for ticker in tickers: + ex_watchlists['pharma'].append(ticker) + run(f"piker watchlists -d {piker_dir} add pharma {' '.join(tickers)}") out = wl.ensure_watchlists(piker_dir) assert out == ex_watchlists