def test_remove(): page = Page() t1 = page.new_text('t1') c1 = page.new_card() t2 = c1.new_text('t2') t3 = c1.new_text('t3') i1 = page.new_input(id='i1') i2_on_enter = lambda: None i2 = page.new_input(on_enter=i2_on_enter, id='i2') b1_fn = lambda: None b1 = page.new_button(b1_fn, id='b1') registry = page._registry assert not any(e._removed for e in [t1, c1, t2, t3, i1, i2, b1]) assert {c.id for c in page.children} == {t1.id, c1.id, i1.id, i2.id, b1.id} assert registry.elements == {t.id: t for t in [t1, c1, t2, t3, i1, i2, b1]} assert registry.functions == {'i2': i2_on_enter, 'b1': b1_fn} assert registry.variables == {'i1': i1._variable, 'i2': i2._variable} def entries(li): return [{'type': 'element', 'id': i, 'rootId': 'root'} for i in li] assert t1 in page.children assert not t1._removed ids = t1.remove() assert ids == entries([t1.id]) assert registry.elements == {t.id: t for t in [c1, t2, t3, i1, i2, b1]} assert t1 not in page.children assert t1._removed ids = c1.remove() assert set(e['id'] for e in ids) == {c1.id, t2.id, t3.id} assert c1 not in page.children assert c1._removed assert t2._removed assert t3._removed assert registry.elements == {t.id: t for t in [i1, i2, b1]} ids = page.remove(i1) assert ids == entries([i1.id]) + [{'type': 'variable', 'id': i1.id}] assert i1._removed assert i1 not in page.children assert registry.elements == {t.id: t for t in [i2, b1]} assert registry.variables == {'i2': i2._variable} ids = i2.remove() assert ids == entries([i2.id]) + [{'type': 'variable', 'id': i2.id}] assert i2._removed assert i2 not in page.children assert registry.elements == {t.id: t for t in [b1]} assert registry.variables == {} assert registry.functions == {'b1': b1_fn} ids = b1.remove() assert ids == entries([b1.id]) assert b1._removed assert not page.children assert not registry.elements assert not registry.variables assert not registry.functions
def main(): page = Page() b = page.new_button(do_stuff, id='button1') b.count = 0 page.new_input(id='input1') page.new_input(placeholder='Input 2, write anything!', on_enter=do_stuff, id='input2') page.start(block=True)
def test_variables(): page = Page() input1 = page.new_input(id='input1') page.start(open_browser=False) output = subprocess.check_output(['awe', '-l', 'ls-variables']) parsed_output = json.loads(output) assert parsed_output[input1.id] == { 'id': input1.id, 'value': '', 'version': 0 } output = subprocess.check_output( ['awe', '-l', 'get-variable', '-v', input1.id]) parsed_output = json.loads(output) assert parsed_output == {'id': input1.id, 'value': '', 'version': 0} subprocess.check_call( ['awe', 'new-variable', '-d', 'initial-value', '-v', 'variable1']) assert page._registry.variables['variable1'].get_variable() == { 'id': 'variable1', 'value': 'initial-value', 'version': 0 } subprocess.check_call( ['awe', 'update-variable', '-d', 'new-value', '-v', 'variable1']) assert page._registry.variables['variable1'].get_variable() == { 'id': 'variable1', 'value': 'new-value', 'version': 1 }
def main(): page = Page() page.new_input(id='query', on_enter=run_query) page.new_table(headers=['one', 'two', 'three'], id='table') page.start(block=True)