Changeset 11112:ce1574cdd4fd in orange


Ignore:
Timestamp:
10/11/12 20:12:58 (18 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed scheme annotation serialization, added tests.

Location:
Orange/OrangeCanvas/scheme
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/scheme/readwrite.py

    r11101 r11112  
    115115            rect = annot_el.attrib.get("rect", "(0, 0, 20, 20)") 
    116116            rect = literal_eval(rect) 
    117             annot = SchemeTextAnnotation(rect, annot_el.text) 
     117            annot = SchemeTextAnnotation(rect, annot_el.text or "") 
    118118        elif annot_el.tag == "arrow": 
    119119            start = annot_el.attrib.get("start", "(0, 0)") 
     
    261261    for annotation in scheme.annotations: 
    262262        annot_id = annotation_ids[annotation] 
    263         attrs = {"id": annot_id} 
     263        attrs = {"id": str(annot_id)} 
    264264        data = None 
    265265        if isinstance(annotation, SchemeTextAnnotation): 
  • Orange/OrangeCanvas/scheme/tests/test_readwrite.py

    r11101 r11112  
    44from ...registry import global_registry 
    55 
    6 from .. import Scheme, SchemeNode, SchemeLink 
     6from .. import Scheme, SchemeNode, SchemeLink, \ 
     7               SchemeArrowAnnotation, SchemeTextAnnotation 
     8 
    79from ..readwrite import scheme_to_ows_stream, parse_scheme 
    810 
     
    3335                                   bayes_node, "Data")) 
    3436 
     37        scheme.add_annotation(SchemeArrowAnnotation((0, 0), (10, 10))) 
     38        scheme.add_annotation(SchemeTextAnnotation((0, 100, 200, 200), "$$")) 
     39 
    3540        stream = StringIO() 
    3641        scheme_to_ows_stream(scheme, stream) 
     
    4247        self.assertTrue(len(scheme.nodes) == len(scheme_1.nodes)) 
    4348        self.assertTrue(len(scheme.links) == len(scheme_1.links)) 
     49        self.assertTrue(len(scheme.annotations) == len(scheme_1.annotations)) 
     50 
     51        for n1, n2 in zip(scheme.nodes, scheme_1.nodes): 
     52            self.assertEqual(n1.position, n2.position) 
     53            self.assertEqual(n1.title, n2.title) 
     54 
     55        for link1, link2 in zip(scheme.links, scheme_1.links): 
     56            self.assertEqual(link1.source_type(), link2.source_type()) 
     57            self.assertEqual(link1.sink_type(), link2.sink_type()) 
     58 
     59            self.assertEqual(link1.source_channel.name, 
     60                             link2.source_channel.name) 
     61 
     62            self.assertEqual(link1.sink_channel.name, 
     63                             link2.sink_channel.name) 
     64 
     65            self.assertEqual(link1.enabled, link2.enabled) 
     66 
     67        for annot1, annot2 in zip(scheme.annotations, scheme_1.annotations): 
     68            self.assertIs(type(annot1), type(annot2)) 
     69            if isinstance(annot1, SchemeTextAnnotation): 
     70                self.assertEqual(annot1.text, annot2.text) 
     71                self.assertEqual(annot1.rect, annot2.rect) 
     72            else: 
     73                self.assertEqual(annot1.start_pos, annot2.start_pos) 
     74                self.assertEqual(annot1.end_pos, annot2.end_pos) 
Note: See TracChangeset for help on using the changeset viewer.