Example #1
0
def test_watchlist_is_read_from_file(piker_dir):
    """Ensure json info is read from file or an empty dict is generated
    and that text respresentation of a watchlist is saved to file.
    """
    wl_temp = wl.ensure_watchlists(piker_dir)
    assert wl_temp == {}
    wl_temp2 = {"AA": ["TEST.CN"]}
    wl.write_to_file(wl_temp2, piker_dir)
    assert wl_temp2 == wl.ensure_watchlists(piker_dir)
Example #2
0
def test_ticker_removed_from_watchlists(capfd, piker_dir, ex_watchlists):
    expected_out = ex_watchlists.copy()
    expected_out['dad'].remove('SPY')
    run(f"piker watchlists -d {piker_dir} remove dad SPY")
    out = wl.ensure_watchlists(piker_dir)
    assert out == expected_out

    # removing a non-entry should be a no-op
    run(f"piker watchlists -d {piker_dir} remove dad SPY")
    out = wl.ensure_watchlists(piker_dir)
Example #3
0
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
Example #4
0
def test_watchlists_loaded(capfd, piker_dir):
    expected_out = {
        'dad': ['CIM', 'DOL.TO', 'GM', 'SHOP.TO', 'SPY', 'TSLA'],
        'pharma': ['ATE.VN'],
    }
    expected_out_text = json.dumps(expected_out)
    run(f"piker watchlists -d {piker_dir} load", expected_out_text)
    out = wl.ensure_watchlists(piker_dir)
    assert out == expected_out
Example #5
0
def test_watchlist_is_sorted_no_dups_and_saved_to_file(piker_dir):
    wl_temp = {
        'test': ['TEST.CN', 'AAA'],
        'AA': ['TEST.CN', 'TEST.CN'],
        'AA': ['TEST.CN']
    }
    wl_sort = {'AA': ['TEST.CN'], 'test': ['AAA', 'TEST.CN']}
    wl.write_to_file(wl_temp, piker_dir)
    temp_sorted = wl.ensure_watchlists(piker_dir)
    assert temp_sorted == wl_sort
Example #6
0
def test_watchlists_are_merged(capfd, piker_dir):
    orig_watchlist = {
        'dad': ['CIM', 'DOL.TO', 'GM', 'SHOP.TO', 'SPY', 'TSLA'],
        'indexes': ['DAX', 'DIA', 'QQQ', 'SPY'],
        'pharma': ['ATE.VN'],
    }
    list_to_merge = json.dumps({
        'drugs': ['CRACK'],
        'pharma': ['ATE.VN', 'MALI', 'PERCOCET']
    })
    expected_out = {
        'dad': ['CIM', 'DOL.TO', 'GM', 'SHOP.TO', 'SPY', 'TSLA'],
        'indexes': ['DAX', 'DIA', 'QQQ', 'SPY'],
        'pharma': ['ATE.VN', 'MALI', 'PERCOCET'],
        'drugs': ['CRACK']
    }
    wl.write_to_file(orig_watchlist, piker_dir)
    run(f"piker watchlists -d {piker_dir} merge", list_to_merge)
    out = wl.ensure_watchlists(piker_dir)
    assert out == expected_out
Example #7
0
def test_group_deleted_from_watchlists(capfd, piker_dir, ex_watchlists):
    expected_out = ex_watchlists.copy()
    expected_out.pop('pharma')
    run(f"piker watchlists -d {piker_dir} delete pharma")
    out = wl.ensure_watchlists(piker_dir)
    assert out == expected_out