def piker_dir(temp_dir, ex_watchlists): wl.make_config_dir(temp_dir) json_file_path = os.path.join(temp_dir, 'watchlists.json') # push test watchlists to file without built-ins to_write = ex_watchlists.copy() wl.write_to_file(to_write, json_file_path) yield json_file_path
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)
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
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