How to use awe - 10 common examples

To help you get started, we’ve selected a few awe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dankilman / awe / tests / test_element.py View on Github external
page = Page()

    test_data = {'data_key': 'value1'}
    test_props = {'props_key': 'value2'}
    style = {'s1': 'v1'}
    test_id = 'test_id'

    class TestElement(view.Element):
        def _init(self):
            self.update_data(test_data)
            self.update_props(test_props)

    class TestElement2(view.Element):
        pass

    class TestElement4(view.Element):
        def _init(self, arg1, arg2):
            self.arg1 = arg1
            self.arg2 = arg2

    assert page.root is page
    assert page.root_id == 'root'
    assert page.index == 0
    assert page._version == 0

    test_element = page._new_child(TestElement, style=style)
    assert page._version == 2
    test_element2 = page._new_child(TestElement2)
    test_element3 = page._new_child(TestElement, id=test_id)
    test_element4 = test_element3._new_child(TestElement4, arg1='val1', arg2='val2')

    all_elements = [test_element, test_element2, test_element3, test_element4]
github dankilman / awe / tests / test_element.py View on Github external
def test_base():
    page = Page()

    test_data = {'data_key': 'value1'}
    test_props = {'props_key': 'value2'}
    style = {'s1': 'v1'}
    test_id = 'test_id'

    class TestElement(view.Element):
        def _init(self):
            self.update_data(test_data)
            self.update_props(test_props)

    class TestElement2(view.Element):
        pass

    class TestElement4(view.Element):
        def _init(self, arg1, arg2):
            self.arg1 = arg1
            self.arg2 = arg2

    assert page.root is page
    assert page.root_id == 'root'
    assert page.index == 0
    assert page._version == 0
github dankilman / awe / tests / view / test_custom.py View on Github external
def test_custom_element_custom_update_element_action(element_tester):
    custom_class = 'custom1'

    class TestElement(CustomElement):

        def _init(self, data):
            self.update_data(data)

        @classmethod
        def _js(cls):
            return '''
                Awe.registerUpdateElementAction('removeKeys', data => map => map.deleteAll(data));
                register((e) => (
                    <div>
                        {Object.values(e.data.map).map((v, i) =&gt; <div>{v}</div>)}
                    </div>
                ));
            '''

    element_data = {
github dankilman / awe / tests / test_element.py View on Github external
def test_update_props():
    page = Page()

    class TestElement(view.Element):
        pass

    element = page._new_child(TestElement)
    element.update_props({'key1': 'value1', 'key2': 'value2'})
    assert element.props == {'key1': 'value1', 'key2': 'value2', 'key': element.id}
    element.update_props({'key1': 'new_value1'})
    assert element.props == {'key1': 'new_value1', 'key2': 'value2', 'key': element.id}
    element.update_props({'key1': 'newer_value1', 'key3': 'value3'}, override=False)
    assert element.props == {'key1': 'new_value1', 'key2': 'value2', 'key': element.id, 'key3': 'value3'}
github dankilman / awe / tests / test_parser.py View on Github external
def test_chart():
    page = Page()
    c = page.new('Chart')
    assert isinstance(c, chart.Chart)
github dankilman / awe / tests / test_parser.py View on Github external
def test_parse_children():
    page = Page()
    result = page.new(['Divider', 'Text'])
    children = result.children
    assert len(children) == 2
    divider, text = children
    assert isinstance(divider, view.Divider)
    assert isinstance(text, view.Text)
github dankilman / awe / tests / test_element.py View on Github external
def test_element_builder():
    page = Page()
    builder = page.element_builder
    code_element1 = builder('code')
    assert code_element1.element_type == 'Raw'
    assert code_element1.data['tag'] == 'code'
    code_element2 = builder('code', props={'test_key': 'test_value'})
    assert code_element2.element_type == 'Raw'
    assert code_element2.data['tag'] == 'code'
    assert code_element2.props['test_key'] == 'test_value'
    text_element1 = builder.text('hello')
    assert text_element1.element_type == 'Text'
    assert text_element1.text == 'hello'
    text_element2 = builder.text('hello', props={'test_key2': 'test_value2'})
    assert text_element2.element_type == 'Text'
    assert text_element2.text == 'hello'
    assert text_element2.props['test_key2'] == 'test_value2'
github dankilman / awe / tests / test_parser.py View on Github external
def test_parse_raw_element_dict_text_value():
    page = Page()
    result = page.new('span: Hello There')
    assert len(result.children) == 1
    assert isinstance(result.children[0], view.Inline)
    assert result.children[0].text == 'Hello There'
github dankilman / awe / tests / view / test_page.py View on Github external
def wrapper(fn):
        page = Page(**page_kwargs)
        page.start(open_browser=False)

        @retry()
        def result():
            driver.get('http://localhost:{}'.format(page._port))
            fn()
        return result
    return wrapper
github dankilman / awe / tests / test_parser.py View on Github external
def test_is_parsable():
    assert parser.is_parsable('')
    assert parser.is_parsable({})
    assert parser.is_parsable([])

    assert not parser.is_parsable(None)
    assert not parser.is_parsable(view.Element)
    assert not parser.is_parsable(view.CustomElement)