Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_chaining_commit():
chain = _.chain([1, 2, 3, 4]).power(2).sum()
committed = chain.commit()
assert chain is not committed
assert chain.value() == committed.value()
def test_chaining_late_value_reuse():
square_sum = _.chain().power(2).sum()
assert square_sum([1, 2, 3, 4]) == 30
assert square_sum([2]) == 4
def test_chaining_plant():
value = [1, 2, 3, 4]
square_sum1 = _.chain(value).power(2).sum()
def root_value(wrapper):
if isinstance(wrapper._value, _.chaining.ChainWrapper):
return root_value(wrapper._value)
return wrapper._value
assert root_value(square_sum1._value) == value
test_value = [5, 6, 7, 8]
square_sum2 = square_sum1.plant(test_value)
assert root_value(square_sum1._value) == value
assert root_value(square_sum2._value) == test_value
assert square_sum1.value() == 30
assert square_sum2.value() == 174
def test_word_cycle(case, expected):
actual = (_.chain(case)
.camel_case()
.kebab_case()
.snake_case()
.start_case()
.camel_case()
.value())
assert actual == expected
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)
def test_chaining_invalid_method():
raised = False
try:
_.chain([]).foobar
except _.InvalidMethod:
raised = True
assert raised
def test_dash_instance_chaining():
value = [1, 2, 3, 4]
from__ = _._(value).without(2, 3).reject(lambda x: x > 1)
from_chain = _.chain(value).without(2, 3).reject(lambda x: x > 1)
assert from__.value() == from_chain.value()
Returns:
str: URL string.
Example:
>>> link = url('a', 'b', ['c', 'd'], '/', q='X', y='Z')
>>> path, params = link.split('?')
>>> path == 'a/b/c/d/'
True
>>> set(params.split('&')) == set(['q=X', 'y=Z'])
True
.. versionadded:: 2.2.0
"""
paths = pyd.chain(paths).flatten_deep().map(pyd.to_string).value()
paths_list = []
params_list = flatten_url_params(params)
for path in paths:
scheme, netloc, path, query, fragment = urlsplit(path)
query = parse_qsl(query)
params_list += query
paths_list.append(urlunsplit((scheme, netloc, path, '', fragment)))
path = delimitedpathjoin('/', *paths_list)
scheme, netloc, path, query, fragment = urlsplit(path)
query = urlencode(params_list)
return urlunsplit((scheme, netloc, path, query, fragment))
Args:
text (str): String to convert.
Returns:
str: String converted to human case.
Example:
>>> human_case('abc-def_hij lmn')
'Abc def hij lmn'
>>> human_case('user_id')
'User'
.. versionadded:: 3.0.0
"""
return (pyd.chain(text)
.snake_case()
.reg_exp_replace('_id$', '')
.replace('_', ' ')
.capitalize()