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_render_members_config_raw(completer):
completer.completers["members"].words = []
config.raw = True
config.withscores = True
rendered = renders.render_members([b"duck", b"667", b"camel", b"708"], completer)
assert rendered == b"duck\n667\ncamel\n708"
assert completer.completers["member"].words == ["camel", "duck"]
def test_command_entry_tty(is_tty, raw_arg_is_raw, final_config_is_raw):
# is tty + raw -> raw
with patch("sys.stdout.isatty") as patch_tty:
from iredis.config import config
patch_tty.return_value = is_tty
if raw_arg_is_raw is None:
call = ["iredis"]
elif raw_arg_is_raw is True:
call = ["iredis", "--raw"]
elif raw_arg_is_raw is False:
call = ["iredis", "--no-raw"]
else:
raise Exception()
gather_args.main(call, standalone_mode=False)
assert config.raw == final_config_is_raw
def test_render_members(completer):
completer.completers["members"].words = []
config.raw = False
config.withscores = True
rendered = renders.render_members([b"duck", b"667", b"camel", b"708"], completer)
assert rendered == FormattedText(
[
("", "1)"),
("", " "),
("class:integer", "667 "),
("class:member", '"duck"'),
("", "\n"),
("", "2)"),
("", " "),
("class:integer", "708 "),
("class:member", '"camel"'),
]
)
def write_result(text):
"""
:param text: is_raw: bytes, not raw: FormattedText
:is_raw: bool
"""
if config.raw:
sys.stdout.buffer.write(text)
sys.stdout.write("\n")
else:
print_formatted_text(text, end="", style=STYLE)
print_formatted_text()
- iredis -h 127.0.0.1 -p 6379 -a
Type "help" in interactive mode for information on available commands
and settings.
"""
logger.info(
f"[start args] host={h}, port={p}, db={n}, raw={raw}, cmd={cmd}, decode={decode}."
)
# figout raw output or formatted output
if ctx.get_parameter_source("raw") == click.ParameterSource.COMMANDLINE:
config.raw = raw
else:
if sys.stdout.isatty():
config.raw = False
else:
config.raw = True
# set config decode
config.decode = decode
config.newbie_mode = newbie
return ctx
- iredis
- iredis -h 127.0.0.1 -p 6379
- iredis -h 127.0.0.1 -p 6379 -a
Type "help" in interactive mode for information on available commands
and settings.
"""
logger.info(
f"[start args] host={h}, port={p}, db={n}, raw={raw}, cmd={cmd}, decode={decode}."
)
# figout raw output or formatted output
if ctx.get_parameter_source("raw") == click.ParameterSource.COMMANDLINE:
config.raw = raw
else:
if sys.stdout.isatty():
config.raw = False
else:
config.raw = True
# set config decode
config.decode = decode
config.newbie_mode = newbie
return ctx
\b
Examples:
- iredis
- iredis -h 127.0.0.1 -p 6379
- iredis -h 127.0.0.1 -p 6379 -a
Type "help" in interactive mode for information on available commands
and settings.
"""
logger.info(
f"[start args] host={h}, port={p}, db={n}, raw={raw}, cmd={cmd}, decode={decode}."
)
# figout raw output or formatted output
if ctx.get_parameter_source("raw") == click.ParameterSource.COMMANDLINE:
config.raw = raw
else:
if sys.stdout.isatty():
config.raw = False
else:
config.raw = True
# set config decode
config.decode = decode
config.newbie_mode = newbie
return ctx
def _render_scan(render_response, response, completer):
cursor, responses = response
if config.raw:
return b"\n".join([cursor, render_response(responses, completer)])
rendered = [
("class:type", "(cursor) "),
("class:integer", cursor.decode()),
("", "\n"),
]
rendered_keys = render_response(responses, completer)
return FormattedText(rendered + rendered_keys)