def test_add_text_inside_stack(): text = Text(id="txt1", value='Hello, "world!"') button = Button(text="Super button") stack = Stack(id="header", controls=[text, button]) assert stack.get_cmd_str() == [ Command(indent=0, name=None, values=["stack"], attrs={"id": ("header", True)}, lines=[], commands=[]), Command( indent=2, name=None, values=["text"], attrs={ "value": 'Hello, "world!"', "id": ("txt1", True) }, lines=[], commands=[], ), Command(indent=2, name=None, values=["button"], attrs={"text": "Super button"}, lines=[], commands=[]), ], "Test failed"
def test_nested_stacks_update(): stack = Stack(controls=[ Textbox(id="firstName"), Textbox(id="lastName"), Stack(horizontal=True, controls=[ Button(id="ok", text="OK"), Button(id="cancel", text="Cancel") ]) ]) # open page p = pglet.page(no_window=True) ctrls = p.add(stack) assert ['_1', 'firstName', 'lastName', '_2', 'ok', 'cancel'] == [ctrls[0].id, ctrls[1].id, ctrls[2].id, ctrls[3].id, ctrls[4].id, ctrls[5].id], "Test failed" # empty update assert stack.get_cmd_str(update=True) == "", "Test failed" # update stack element ctrls[0].horizontal=True assert stack.get_cmd_str(update=True) == '"_1" horizontal="true"', "Test failed" # update inner elements ctrls[1].value = "John" ctrls[2].value = "Smith" ctrls[4].primary = True #raise Exception(stack.get_cmd_str(update=True)) assert stack.get_cmd_str(update=True) == ( '"firstName" value="John"\n' '"lastName" value="Smith"\n' '"ok" primary="true"' ), "Test failed" # assert stack.get_cmd_str(update=True) == ( # 'stack\n' # ' textbox id="firstName"\n' # ' textbox id="lastName"\n' # ' stack horizontal="true"\n' # ' button id="ok" text="OK"\n' # ' button id="cancel" text="Cancel"' # ), "Test failed"
def test_stack_add(): s = Stack(controls=[ Textbox(id="firstName"), Textbox(id="lastName") ]) assert isinstance(s, pglet.Control) assert isinstance(s, pglet.Stack) #raise Exception(s.get_cmd_str()) assert s.get_cmd_str() == ( 'stack\n' ' textbox id="firstName"\n' ' textbox id="lastName"' ), "Test failed"
def test_nested_stacks_add(): s = Stack(controls=[ Textbox(id="firstName"), Textbox(id="lastName"), Stack(horizontal=True, controls=[ Button(id="ok", text="OK", primary=True), Button(id="cancel", text="Cancel") ]) ]) assert isinstance(s, pglet.Control) assert isinstance(s, pglet.Stack) #raise Exception(s.get_cmd_str()) assert s.get_cmd_str() == ( 'stack\n' ' textbox id="firstName"\n' ' textbox id="lastName"\n' ' stack horizontal="true"\n' ' button id="ok" primary="true" text="OK"\n' ' button id="cancel" text="Cancel"' ), "Test failed"
def test_nested_stacks_add(): s = Stack( controls=[ Textbox(id="firstName"), Textbox(id="lastName"), Stack( horizontal=True, controls=[ Button(id="ok", text="OK", primary=True), Button(id="cancel", text="Cancel"), ], ), ] ) assert isinstance(s, pglet.Control) assert isinstance(s, pglet.Stack) # raise Exception(s.get_cmd_str()) assert s.get_cmd_str() == [ Command(indent=0, name=None, values=["stack"], attrs={}, lines=[], commands=[]), Command(indent=2, name=None, values=["textbox"], attrs={"id": ("firstName", True)}, lines=[], commands=[]), Command(indent=2, name=None, values=["textbox"], attrs={"id": ("lastName", True)}, lines=[], commands=[]), Command(indent=2, name=None, values=["stack"], attrs={"horizontal": "true"}, lines=[], commands=[]), Command( indent=4, name=None, values=["button"], attrs={"primary": "true", "text": "OK", "id": ("ok", True)}, lines=[], commands=[], ), Command( indent=4, name=None, values=["button"], attrs={"text": "Cancel", "id": ("cancel", True)}, lines=[], commands=[], ), ], "Test failed"
def test_stack_add(): s = Stack( horizontal=True, vertical_fill=True, horizontal_align="center", vertical_align="baseline", gap="large", wrap=True, scroll_x=True, scroll_y=True, controls=[Textbox(id="firstName"), Textbox(id="lastName")], ) assert isinstance(s, pglet.Control) assert isinstance(s, pglet.Stack) # raise Exception(s.get_cmd_str()) assert s.get_cmd_str() == [ Command( indent=0, name=None, values=["stack"], attrs={ "gap": "large", "horizontal": "true", "horizontalalign": "center", "scrollx": "true", "scrolly": "true", "verticalalign": "baseline", "verticalfill": "true", "wrap": "true", }, lines=[], commands=[], ), Command(indent=2, name=None, values=["textbox"], attrs={"id": ("firstName", True)}, lines=[], commands=[]), Command(indent=2, name=None, values=["textbox"], attrs={"id": ("lastName", True)}, lines=[], commands=[]), ], "Test failed"