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_assemble_rows_long_text():
rows = [[get_random_text_widget(10),
get_random_text_widget(300)] for _ in range(5)]
assembled_rows = assemble_rows(rows, ignore_columns=[1])
lb = WidgetBase(SimpleListWalker(assembled_rows))
canvas = lb.render((80, 20), focus=False)
text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()]
logging.info("%r", text)
assert len(text) == 20
first_col, second_col = text[0].split(b" ", 1)
assert first_col == rows[0][0].text.encode("utf-8")
assert rows[0][1].text.encode("utf-8").startswith(second_col)
def test_assemble_rows_long_text():
rows = [[get_random_text_widget(10),
get_random_text_widget(300)] for _ in range(5)]
assembled_rows = assemble_rows(rows, ignore_columns=[1])
lb = WidgetBase(SimpleListWalker(assembled_rows))
canvas = lb.render((80, 20), focus=False)
text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()]
logging.info("%r", text)
assert len(text) == 20
first_col, second_col = text[0].split(b" ", 1)
assert first_col == rows[0][0].text.encode("utf-8")
assert rows[0][1].text.encode("utf-8").startswith(second_col)
@log_traceback
def f():
pass
caplog.set_level(logging.DEBUG)
def test_short_id():
mock()
b = DockerBackend()
operation = DockerContainer({"Status": "Up", "Id": "voodoo"}, b).top()
top_response = operation.response
pt = ProcessList(top_response)
# 24502
# \ 24542
# \ 23743
# \ 18725
# \ 18733
# \ 18743
# \ 23819
root_process = pt.get_root_process()
assert root_process.pid == "24502"
assert pt.get_parent_process(root_process) is None
p_24542 = pt.get_first_child_process(root_process)
def test_repeater():
def g(l, item=1):
l.append(1)
return l[item]
assert repeater(g, args=([], )) == 1
with pytest.raises(Exception):
repeater(f, args=([], ), kwargs={"item": 10}) == 1
def test_repeater():
def g(l, item=1):
l.append(1)
return l[item]
assert repeater(g, args=([], )) == 1
with pytest.raises(Exception):
repeater(f, args=([], ), kwargs={"item": 10}) == 1
lower_bound = 5
upper_bound = 10
list_count = 50
def loop_skeleton(greater_f, less_f, l, l_b, u_b, l_c):
# we could do while True, but then we need to clean the threads
for _ in range(100):
if len(l) > l_c:
for _ in range(random.randint(l_b, u_b)):
greater_f()
else:
for _ in range(random.randint(l_b, u_b)):
less_f()
body_widgets = [get_random_text_widget() for _ in range(100)]
body = WidgetBase(urwid.SimpleFocusListWalker(body_widgets))
frame = UI(MockUI(), body)
def add_and_remove_random():
widgets = []
def less_f():
if random.randint(1, 2) % 2:
w = get_random_text_widget()
frame.notify_widget(w)
widgets.append(w)
else:
widgets.append(frame.notify_message(get_random_text()))
def greater_f():
w = random.choice(widgets)
frame.remove_widget(w)
description = "test desc"
options_definitions = [
Option("test-opt", "test-opt desc", aliases=["x"])
]
aliases = ["mango"]
def run(self):
return 42
@register_command
class MyCommand2(Command):
name = "test2"
description = "test desc 2"
options_definitions = [
Option("test-opt", "test-opt desc", aliases=["x"]),
Option("test-opt2", "test-opt2 desc", default="banana"),
]
arguments_definitions = [
Argument("test-arg", "test-arg desc")
]
def run(self):
return 43
def test_command_class():
c = Command()
assert c.arguments is None
c.process_args([])
assert c.arguments is not None
with pytest.raises(AttributeError):
options_definitions = [
Option("test-opt", "test-opt desc", aliases=["x"])
]
aliases = ["mango"]
def run(self):
return 42
@register_command
class MyCommand2(Command):
name = "test2"
description = "test desc 2"
options_definitions = [
Option("test-opt", "test-opt desc", aliases=["x"]),
Option("test-opt2", "test-opt2 desc", default="banana"),
]
arguments_definitions = [
Argument("test-arg", "test-arg desc")
]
def run(self):
return 43
def test_command_class():
c = Command()
assert c.arguments is None
c.process_args([])
assert c.arguments is not None
with pytest.raises(AttributeError):
print(c.arguments.not_there)
def get_detailed_container_row(docker_container):
row = []
container_id = SelectableText(docker_container.short_id)
row.append(container_id)
commands = docker_container.command.split("\n")
command_str = commands[0]
if len(commands) > 0:
command_str += "..."
command = SelectableText(command_str, get_map(defult="main_list_ddg"))
row.append(command)
image = SelectableText(docker_container.image_name())
row.append(image)
row.append(ContainerStatusWidget(docker_container))
name = SelectableText(docker_container.short_name)
row.append(name)
return row