Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from copy import deepcopy
import pydash as _
from .fixtures import parametrize
pydash_methods = _.filter_(dir(_), lambda m: callable(getattr(_, m, None)))
def test_chaining_methods():
chain = _.chain([])
for method in dir(_):
if not callable(method):
continue
chained = getattr(chain, method)
assert chained.method is getattr(_, method)
@parametrize('value,methods', [
([1, 2, 3, 4], [('without', (2, 3)),
('reject', (lambda x: x > 1,))])
:param main_market_filter: Main market to filter on (ex: BTC, ETH, USDT)
:type main_market_filter: str
:return: All Bittrex markets (with filter applied, if any)
:rtype: list
"""
markets = self.Bittrex.get_markets()
if not markets["success"]:
error_str = self.Messenger.print_error("market", [], True)
logger.error(error_str)
exit()
markets = markets["result"]
if main_market_filter is not None:
market_check = main_market_filter + "-"
markets = py_.filter_(markets, lambda market: market_check in market["MarketName"])
markets = py_.map_(markets, lambda market: market["MarketName"])
return markets
def check_all():
'''Check all spec files, all specs.'''
spec_files = ps.filter_(os.listdir(SPEC_DIR), lambda f: f.endswith('.json') and not f.startswith('_'))
for spec_file in spec_files:
spec_dict = util.read(f'{SPEC_DIR}/{spec_file}')
for spec_name, spec in spec_dict.items():
# fill-in info at runtime
spec['name'] = spec_name
spec = extend_meta_spec(spec)
try:
check(spec)
except Exception as e:
logger.exception(f'spec_file {spec_file} fails spec check')
raise e
logger.info(f'Checked all specs from: {ps.join(spec_files, ",")}')
return True
def get_fn_list(a_cls):
'''
Get the callable, non-private functions of a class
@returns {[*str]} A list of strings of fn names
'''
fn_list = ps.filter_(dir(a_cls), lambda fn: not fn.endswith('__') and callable(getattr(a_cls, fn)))
return fn_list
def check_all():
'''Check all spec files, all specs.'''
spec_files = ps.filter_(os.listdir(SPEC_DIR), lambda f: f.endswith('.json') and not f.startswith('_'))
for spec_file in spec_files:
spec_dict = util.read(f'{SPEC_DIR}/{spec_file}')
for spec_name, spec in spec_dict.items():
# fill-in info at runtime
spec['name'] = spec_name
spec = extend_meta_spec(spec)
try:
check(spec)
except Exception as e:
logger.exception(f'spec_file {spec_file} fails spec check')
raise e
logger.info(f'Checked all specs from: {ps.join(spec_files, ",")}')
return True
def get_non_zero_balances(self):
"""
Gets all non-zero user coin balances in the correct format
"""
balances_data = self.Bittrex.get_balances()
if not balances_data["success"]:
error_str = self.Messenger.print_error("balance")
logger.error(error_str)
return
non_zero_balances = py_.filter_(balances_data["result"], lambda balance_item: balance_item["Balance"] > 0)
return py_.map_(non_zero_balances, lambda balance: self.create_balance_object(balance))
def get_fn_list(a_cls):
'''
Get the callable, non-private functions of a class
@returns {[*str]} A list of strings of fn names
'''
fn_list = ps.filter_(dir(a_cls), lambda fn: not fn.endswith('__') and callable(getattr(a_cls, fn)))
return fn_list
Raises:
StateNotList: If state is not a list
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy('[{"a": 1}, {"b": 2}, {"a": 1, "b": 3}]').str_list_to_list().filter_list("b").o
[{"b": 2}, {"a": 1, "b": 3}]
"""
assert isinstance(self.state, list), StateNotList()
if regex:
pattern = by if isinstance(self.state[0], str) else by.encode()
self.state = [f for f in self.state if re.search(pattern, f)]
else:
self.state = pydash.filter_(self.state, by)
if len(self.state) == 1:
self.state = self.state[0]
return self