def test_main_frame(): 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)] ui = MockUI() frame = WidgetBase(ui, urwid.SimpleFocusListWalker(body_widgets)) 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) widgets.remove(w) loop_skeleton(greater_f, less_f, widgets, lower_bound, upper_bound, list_count) def change_body(): def less_f(): body_widgets.insert(0, get_random_text_widget()) def greater_f(): body_widgets.remove(random.choice(body_widgets)) loop_skeleton(greater_f, less_f, body_widgets, lower_bound, upper_bound, list_count) nt = threading.Thread(target=add_and_remove_random, daemon=True) bt = threading.Thread(target=change_body, daemon=True) nt.start() bt.start() for x in range(50): frame.render((70, 70)) nt.join() bt.join()
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(MockUI(), 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)