Change watchlist write function name

kivy_mainline_and_py3.8
Tyler Goodlet 2018-04-06 15:07:47 -04:00
parent 7e92df4352
commit 6b72d04427
4 changed files with 10 additions and 10 deletions

View File

@ -159,7 +159,7 @@ def show(ctx, name):
@click.pass_context @click.pass_context
def load(ctx, data): def load(ctx, data):
try: try:
wl.write_sorted_json(json.loads(data), ctx.obj['path']) wl.write_to_file(json.loads(data), ctx.obj['path'])
except (json.JSONDecodeError, IndexError): except (json.JSONDecodeError, IndexError):
click.echo('You have passed an invalid text respresentation of a ' click.echo('You have passed an invalid text respresentation of a '
'JSON object. Try again.') 'JSON object. Try again.')
@ -172,7 +172,7 @@ def load(ctx, data):
def add(ctx, name, ticker_name): def add(ctx, name, ticker_name):
watchlist = wl.add_ticker(name, ticker_name, watchlist = wl.add_ticker(name, ticker_name,
ctx.obj['watchlist']) ctx.obj['watchlist'])
wl.write_sorted_json(watchlist, ctx.obj['path']) wl.write_to_file(watchlist, ctx.obj['path'])
@watchlists.command(help='remove ticker from watchlist') @watchlists.command(help='remove ticker from watchlist')
@ -181,7 +181,7 @@ def add(ctx, name, ticker_name):
@click.pass_context @click.pass_context
def remove(ctx, name, ticker_name): def remove(ctx, name, ticker_name):
watchlist = wl.remove_ticker(name, ticker_name, ctx.obj['watchlist']) watchlist = wl.remove_ticker(name, ticker_name, ctx.obj['watchlist'])
wl.write_sorted_json(watchlist, ctx.obj['path']) wl.write_to_file(watchlist, ctx.obj['path'])
@watchlists.command(help='delete watchlist group') @watchlists.command(help='delete watchlist group')
@ -189,7 +189,7 @@ def remove(ctx, name, ticker_name):
@click.pass_context @click.pass_context
def delete(ctx, name): def delete(ctx, name):
watchlist = wl.delete_group(name, ctx.obj['watchlist']) watchlist = wl.delete_group(name, ctx.obj['watchlist'])
wl.write_sorted_json(watchlist, ctx.obj['path']) wl.write_to_file(watchlist, ctx.obj['path'])
@watchlists.command(help='merge a watchlist from another user') @watchlists.command(help='merge a watchlist from another user')
@ -198,7 +198,7 @@ def delete(ctx, name):
def merge(ctx, watchlist_to_merge): def merge(ctx, watchlist_to_merge):
merged_watchlist = wl.merge_watchlist(json.loads(watchlist_to_merge), merged_watchlist = wl.merge_watchlist(json.loads(watchlist_to_merge),
ctx.obj['watchlist']) ctx.obj['watchlist'])
wl.write_sorted_json(merged_watchlist, ctx.obj['path']) wl.write_to_file(merged_watchlist, ctx.obj['path'])
@watchlists.command(help='dump text respresentation of a watchlist to console') @watchlists.command(help='dump text respresentation of a watchlist to console')

View File

@ -11,7 +11,7 @@ _builtins = {
} }
def write_sorted_json(watchlist, path): def write_to_file(watchlist, path):
for key in watchlist: for key in watchlist:
watchlist[key] = sorted(list(set(watchlist[key]))) watchlist[key] = sorted(list(set(watchlist[key])))
with open(path, 'w') as f: with open(path, 'w') as f:

View File

@ -112,7 +112,7 @@ def piker_dir(temp_dir):
'pharma': ['ATE.VN'], 'pharma': ['ATE.VN'],
'indexes': ['SPY', 'DAX', 'QQQ', 'DIA'], 'indexes': ['SPY', 'DAX', 'QQQ', 'DIA'],
} }
wl.write_sorted_json(watchlist, json_file_path) wl.write_to_file(watchlist, json_file_path)
yield json_file_path yield json_file_path
@ -201,7 +201,7 @@ def test_watchlists_are_merged(capfd, piker_dir):
'pharma': ['ATE.VN', 'MALI', 'PERCOCET'], 'pharma': ['ATE.VN', 'MALI', 'PERCOCET'],
'drugs': ['CRACK'] 'drugs': ['CRACK']
} }
wl.write_sorted_json(orig_watchlist, piker_dir) wl.write_to_file(orig_watchlist, piker_dir)
run(f"piker watchlists -d {piker_dir} merge", list_to_merge) run(f"piker watchlists -d {piker_dir} merge", list_to_merge)
out = wl.ensure_watchlists(piker_dir) out = wl.ensure_watchlists(piker_dir)
assert out == expected_out assert out == expected_out

View File

@ -30,7 +30,7 @@ def test_watchlist_is_sorted_no_dups_and_saved_to_file(piker_dir):
wl_temp = {'test': ['TEST.CN', 'AAA'], 'AA': ['TEST.CN', 'TEST.CN'], wl_temp = {'test': ['TEST.CN', 'AAA'], 'AA': ['TEST.CN', 'TEST.CN'],
'AA': ['TEST.CN']} 'AA': ['TEST.CN']}
wl_sort = {'AA': ['TEST.CN'], 'test': ['AAA', 'TEST.CN']} wl_sort = {'AA': ['TEST.CN'], 'test': ['AAA', 'TEST.CN']}
wl.write_sorted_json(wl_temp, piker_dir) wl.write_to_file(wl_temp, piker_dir)
temp_sorted = wl.ensure_watchlists(piker_dir) temp_sorted = wl.ensure_watchlists(piker_dir)
assert temp_sorted == wl_sort assert temp_sorted == wl_sort
@ -60,7 +60,7 @@ def test_watchlist_is_read_from_file(piker_dir):
wl_temp = wl.ensure_watchlists(piker_dir) wl_temp = wl.ensure_watchlists(piker_dir)
assert wl_temp == {} assert wl_temp == {}
wl_temp2 = {"AA": ["TEST.CN"]} wl_temp2 = {"AA": ["TEST.CN"]}
wl.write_sorted_json(wl_temp2, piker_dir) wl.write_to_file(wl_temp2, piker_dir)
assert wl_temp2 == wl.ensure_watchlists(piker_dir) assert wl_temp2 == wl.ensure_watchlists(piker_dir)