Ignore:
Timestamp:
03/11/13 16:28:15 (13 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

When possible, node properties are now saved as python literal strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/scheme/tests/test_readwrite.py

    r11112 r11391  
    77               SchemeArrowAnnotation, SchemeTextAnnotation 
    88 
     9from .. import readwrite 
    910from ..readwrite import scheme_to_ows_stream, parse_scheme 
    1011 
     
    7374                self.assertEqual(annot1.start_pos, annot2.start_pos) 
    7475                self.assertEqual(annot1.end_pos, annot2.end_pos) 
     76 
     77    def test_safe_evals(self): 
     78        s = readwrite.string_eval(r"'\x00\xff'") 
     79        self.assertEquals(s, chr(0) + chr(255)) 
     80 
     81        with self.assertRaises(ValueError): 
     82            readwrite.string_eval("[1, 2]") 
     83 
     84        t = readwrite.tuple_eval("(1, 2.0, 'a')") 
     85        self.assertEqual(t, (1, 2.0, 'a')) 
     86 
     87        with self.assertRaises(ValueError): 
     88            readwrite.tuple_eval("u'string'") 
     89 
     90        with self.assertRaises(ValueError): 
     91            readwrite.tuple_eval("(1, [1, [2, ]])") 
     92 
     93        self.assertIs(readwrite.terminal_eval("True"), True) 
     94        self.assertIs(readwrite.terminal_eval("False"), False) 
     95        self.assertIs(readwrite.terminal_eval("None"), None) 
     96 
     97        self.assertEqual(readwrite.terminal_eval("42"), 42) 
     98        self.assertEqual(readwrite.terminal_eval("'42'"), '42') 
     99 
     100    def test_literal_dump(self): 
     101        struct = {1: [{(1, 2): ""}], 
     102                  True: 1.0, 
     103                  None: None} 
     104 
     105        s = readwrite.literal_dumps(struct) 
     106        self.assertEqual(readwrite.literal_loads(s), struct) 
     107 
     108        with self.assertRaises(ValueError): 
     109            recur = [1] 
     110            recur.append(recur) 
     111            readwrite.literal_dumps(recur) 
     112 
     113        with self.assertRaises(TypeError): 
     114            readwrite.literal_dumps(self) 
Note: See TracChangeset for help on using the changeset viewer.