Пример #1
0
    def test_comp_context(self):
        Register.add(SubComponent)
        obj = MyComponent()
        obj.root = obj
        template = """<comp><li><a><SubComponent></SubComponent></a></li></comp>"""
        obj.instructions = self.tp.parse(template)

        obj.mount()
        comp_li = obj.children[0]
        comp_a = comp_li.children[0]
        comp_sub = comp_a.children[0]
        self.assertEqual(RefMap.get(comp_li.context['self']), comp_li)
        self.assertEqual(RefMap.get(comp_li.context['parent']), obj)
        self.assertEqual(RefMap.get(comp_li.context['root']), obj)

        self.assertEqual(comp_li.root, obj)
        self.assertEqual(comp_li.parent, obj)

        self.assertEqual(RefMap.get(comp_a.context['self']), comp_a)
        self.assertEqual(RefMap.get(comp_a.context['parent']), comp_li)
        self.assertEqual(RefMap.get(comp_a.context['root']), obj)

        self.assertEqual(comp_a.root, obj)
        self.assertEqual(comp_a.parent, comp_li)

        self.assertEqual(RefMap.get(comp_sub.context['parent']), comp_a)
        self.assertEqual(RefMap.get(comp_sub.context['root']), comp_sub)

        comp_sub2 = SubComponent()
        obj.add(comp_sub2)
        self.assertEqual(RefMap.get(comp_sub2.context['parent']), obj)
        self.assertEqual(RefMap.get(comp_sub2.context['root']), comp_sub2)
Пример #2
0
    def test_comp_context(self):
        Register.add(SubComponent)
        obj = MyComponent()
        obj.root = obj
        template = """<comp><li><a><SubComponent></SubComponent></a></li></comp>"""
        obj.instructions = self.tp.parse(template)

        obj.mount()
        comp_li = obj.children[0]
        comp_a = comp_li.children[0]
        comp_sub = comp_a.children[0]
        self.assertEqual(RefMap.get(comp_li.context["self"]), comp_li)
        self.assertEqual(RefMap.get(comp_li.context["parent"]), obj)
        self.assertEqual(RefMap.get(comp_li.context["root"]), obj)

        self.assertEqual(comp_li.root, obj)
        self.assertEqual(comp_li.parent, obj)

        self.assertEqual(RefMap.get(comp_a.context["self"]), comp_a)
        self.assertEqual(RefMap.get(comp_a.context["parent"]), comp_li)
        self.assertEqual(RefMap.get(comp_a.context["root"]), obj)

        self.assertEqual(comp_a.root, obj)
        self.assertEqual(comp_a.parent, comp_li)

        self.assertEqual(RefMap.get(comp_sub.context["parent"]), comp_a)
        self.assertEqual(RefMap.get(comp_sub.context["root"]), comp_sub)

        comp_sub2 = SubComponent()
        obj.add(comp_sub2)
        self.assertEqual(RefMap.get(comp_sub2.context["parent"]), obj)
        self.assertEqual(RefMap.get(comp_sub2.context["root"]), comp_sub2)
Пример #3
0
    def render_code(self):
        python_editor = self.get('e1')
        html_editor = self.get('e2')
        #Remove old component classes
        for comp_cls in Register.reg:
            if comp_cls not in (CodeMirror, ResultComponent, ComponentEditor):
                Register.remove(comp_cls)

        python_code = python_editor.get_code()
        try:
            eval(python_code)
        except Exception as e:
            print("Error evaluating code ", e)
        # Init comp classes again (User must have registered its comps in the code)
        initialize_comps_classes()

        # Add new html with components in it
        result_comp = self.get('result')
        result_comp.remove_all()
        result_comp.add_html(html_editor.get_code())
Пример #4
0
    def on_items(self, value, instance):
        comp2rm, values2add, current_items = [], list(self.items), []
        for c in self.children:
            if c.value in self.items:
                current_items.append(c.value)
                values2add.remove(c.value)
            else:
                comp2rm.append(c)

        #Remove
        for c in comp2rm:
            self.remove(c)

        # Add
        ishtml = self.itemtag.upper() in HTML_TAGS
        cls_comp = HTMLComp if ishtml else Register.get_component_class(
            self.itemtag)

        for c in list(self.children):
            added = []
            for v in values2add:
                if self.order[v] < self.order[c.value]:
                    newcomp = cls_comp(
                        tag=self.itemtag) if ishtml else cls_comp()
                    newcomp.value = v
                    newcomp.html = v
                    self.add(newcomp, before=c)
                    added.append(v)
                else:
                    break

            for a in added:
                values2add.remove(a)

        # Add remaining
        HTMLComp(tag='li')
        for v in values2add:
            try:
                newcomp = cls_comp(tag=self.itemtag,
                                   domnode=None) if ishtml else cls_comp()
                newcomp.value = v
                newcomp.html = v
            except:
                pass
            self.add(newcomp)
Пример #5
0
    def on_items(self, value, instance):
        comp2rm, values2add, current_items = [], list(self.items), []
        for c in self.children:
            if c.value in self.items:
              current_items.append(c.value)
              values2add.remove(c.value)
            else:
              comp2rm.append(c)

        #Remove
        for c in comp2rm:
            self.remove(c)

        # Add 
        ishtml = self.itemtag.upper() in HTML_TAGS
        cls_comp = HTMLComp if ishtml else Register.get_component_class(self.itemtag)

        for c in list(self.children):
            added = []
            for v in values2add:
                if self.order[v] < self.order[c.value]:
                    newcomp = cls_comp(tag=self.itemtag) if ishtml else cls_comp()
                    newcomp.value = v
                    newcomp.html = v
                    self.add(newcomp, before=c)
                    added.append(v)
                else:
                    break

            for a in added: 
                values2add.remove(a)

        # Add remaining
        HTMLComp(tag='li')
        for v in values2add:
            try:
                newcomp = cls_comp(tag=self.itemtag, domnode=None) if ishtml else cls_comp()
                newcomp.value = v
                newcomp.html = v
            except:
                pass
            self.add(newcomp)
Пример #6
0
        #self.cm = cm.fromTextArea(self.get('txt').elem, {"value": self.value, "lineNumbers": False, "mode": self.mode})
        self.refresh()

    def refresh(self):
        window.requestAnimationFrame(self._refresh)

    def _refresh(self, ev):
        self.cm.refresh()

    def get_code(self):
        return self.cm.getValue()


class ResultComponent(Component):
    tag = "ResultComponent"
    template = "<ResultComponent></ResultComponent>"
    style = """
             :host {
                display: block;
                background-color:  #fff;;
                border: 10px solid #444;
                padding: 15px;
                min-height: 700px;
            }
            """


Register.add(CodeMirror)
Register.add(ResultComponent)
Register.add(ComponentEditor)
Пример #7
0

class MyComponent(Component):
    template = "<MyComponent></MyComponent>"
    tag = 'MyComponent'
    a = Property(0)
    b = Property(2)


class SubComponent(Component):
    template = "<SubComponent></SubComponent>"
    tag = 'SubComponent'
    a = Property(0)
    b = Property(2)


Register.add(SubComponent)
Register.add(MyComponent)

BrowserDOMRender.direct = True
TESTS = (TestProperties, TestComponent)
report_html = ''
document['status'].html = "Testing..."
for t in TESTS:
    document['status'].html = "Processing %s" % (t.__name__)
    tester = t()
    report = tester.run()
    report_html += "<br/> <h2>%s</h2>" % (t.__name__) + report.format_html()
document['status'].html = "Testing done"
document['report'].html = report_html
Пример #8
0
                    self.add(newcomp, before=c)
                    added.append(v)
                else:
                    break

            for a in added:
                values2add.remove(a)

        # Add remaining
        HTMLComp(tag='li')
        for v in values2add:
            try:
                newcomp = cls_comp(tag=self.itemtag,
                                   domnode=None) if ishtml else cls_comp()
                newcomp.value = v
                newcomp.html = v
            except:
                pass
            self.add(newcomp)


class ListItem(Component):
    template = "<ListItem>{self.text}</ListItem>"
    rendertag = "li"  # Use <li> instead of <ListItem> to render
    text = Property('')
    value = Property('')


Register.add(FilteredList)
Register.add(ListItem)
Пример #9
0
def test_repr_correct_format():
    r1 = Register("R1", bits=[True, False, False, True])
    assert(str(r1) == "R1 => 1,0,0,1")
Пример #10
0
def test_bitwise_xor_should_work():
    r1 = Register("R1", bits=[True, False, True, False])
    r2 = Register("R2", bits=[True, True, False, False])
    r3 = r1 ^ r2
    assert(r3.bits == [False, True, True, False])
Пример #11
0
def test_init_should_raise_error_if_size_greater_than_max_size():
    pytest.raises(AssertionError, lambda: Register("R1", size=MAX_BITS_SIZE + 1))
Пример #12
0
def test_init_should_raise_error_if_size_less_than_1():
    pytest.raises(AssertionError, lambda: Register("R1", size=0))
Пример #13
0
def test_init_set_bits():
    r = Register("R1", bits=[True, False, False])
    assert(r.bits == [True, False, False])
Пример #14
0
def test_init_default_32_bits_long():
    r = Register("R1")
    assert(r.size == 32)
Пример #15
0
def test_init_size_property_from_passed_value():
    r = Register("R1", size=7)
    assert(r.size == 7)
Пример #16
0
                    newcomp.value = v
                    newcomp.html = v
                    self.add(newcomp, before=c)
                    added.append(v)
                else:
                    break

            for a in added: 
                values2add.remove(a)

        # Add remaining
        HTMLComp(tag='li')
        for v in values2add:
            try:
                newcomp = cls_comp(tag=self.itemtag, domnode=None) if ishtml else cls_comp()
                newcomp.value = v
                newcomp.html = v
            except:
                pass
            self.add(newcomp)


class ListItem(Component):
    template = "<ListItem>{self.text}</ListItem>"
    rendertag = "li" # Use <li> instead of <ListItem> to render
    text = Property('')
    value = Property('')
  
Register.add(FilteredList)
Register.add(ListItem)
Пример #17
0
def test_init_name_attribute_from_passed_value():
    r = Register("R1")
    assert(r.name == "R1")
Пример #18
0
class MyComponent(Component):
    template = "<MyComponent></MyComponent>"
    tag = "MyComponent"
    a = Property(0)
    b = Property(2)


class SubComponent(Component):
    template = "<SubComponent></SubComponent>"
    tag = "SubComponent"
    a = Property(0)
    b = Property(2)


Register.add(SubComponent)
Register.add(MyComponent)


BrowserDOMRender.direct = True
TESTS = (TestProperties, TestComponent)
report_html = ""
document["status"].html = "Testing..."
for t in TESTS:
    document["status"].html = "Processing %s" % (t.__name__)
    tester = t()
    report = tester.run()
    report_html += "<br/> <h2>%s</h2>" % (t.__name__) + report.format_html()
document["status"].html = "Testing done"
document["report"].html = report_html