Add initial config dir test
							parent
							
								
									ce75bd8f6f
								
							
						
					
					
						commit
						d28a3dc461
					
				| 
						 | 
				
			
			@ -14,7 +14,7 @@ import pandas as pd
 | 
			
		|||
 | 
			
		||||
from .log import get_console_log, colorize_json, get_logger
 | 
			
		||||
from . import watchlists as wl
 | 
			
		||||
from .brokers import core
 | 
			
		||||
from .brokers import core, get_brokermod
 | 
			
		||||
 | 
			
		||||
log = get_logger('cli')
 | 
			
		||||
DEFAULT_BROKER = 'robinhood'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,10 @@
 | 
			
		|||
import os
 | 
			
		||||
import json
 | 
			
		||||
import ast
 | 
			
		||||
from collections import defaultdict
 | 
			
		||||
 | 
			
		||||
from .log import get_logger
 | 
			
		||||
 | 
			
		||||
log = get_logger(__name__)
 | 
			
		||||
 | 
			
		||||
def write_sorted_json(watchlist, path):
 | 
			
		||||
    for key in watchlist:
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +58,7 @@ def delete_group(name, watchlist, path):
 | 
			
		|||
 | 
			
		||||
def merge_watchlist(watchlist_to_merge, watchlist, path):
 | 
			
		||||
    merged_watchlist = defaultdict(list)
 | 
			
		||||
    watchlist_to_merge = ast.literal_eval(watchlist_to_merge)
 | 
			
		||||
    watchlist_to_merge = json.loads(watchlist_to_merge)
 | 
			
		||||
    for d in (watchlist, watchlist_to_merge):
 | 
			
		||||
        for key, value in d.items():
 | 
			
		||||
            merged_watchlist[key].extend(value)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,11 @@ CLI testing, dawg.
 | 
			
		|||
import json
 | 
			
		||||
import subprocess
 | 
			
		||||
import pytest
 | 
			
		||||
import tempfile
 | 
			
		||||
import os.path
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from piker.watchlists import make_config_dir
 | 
			
		||||
 | 
			
		||||
def run(cmd):
 | 
			
		||||
    """Run cmd and check for zero return code.
 | 
			
		||||
| 
						 | 
				
			
			@ -85,3 +89,18 @@ def test_api_method_not_found(nyse_tickers, capfd):
 | 
			
		|||
    out, err = capfd.readouterr()
 | 
			
		||||
    assert 'null' in out
 | 
			
		||||
    assert f'No api method `{bad_meth}` could be found?' in err
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_watchlists_config_dir_created(caplog):
 | 
			
		||||
    """Ensure that a config directory is created
 | 
			
		||||
    """
 | 
			
		||||
    #Create temporary directory
 | 
			
		||||
    config_dir = os.path.join(tempfile.gettempdir(), 'piker')
 | 
			
		||||
    with caplog.at_level(logging.DEBUG):
 | 
			
		||||
        make_config_dir(config_dir)
 | 
			
		||||
    assert len(caplog.records) == 1
 | 
			
		||||
    record = caplog.records[0]
 | 
			
		||||
    assert record.levelname == 'DEBUG'
 | 
			
		||||
    assert record.message == f"Creating config dir {config_dir}"
 | 
			
		||||
    assert os.path.isdir(config_dir)
 | 
			
		||||
    os.rmdir(config_dir)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue