Example #1
0
 def test_union_func_not_ok(self):
     a_lot_of_type= convert_tree( 
         dict( 
             a = "lkjlkjl",
             b = dict( 
                 e = set( [ 1 , 2 , 3 ] ),
                 f = lambda x ,y : 2 * y,
             
             ),
             p = dict(a  = "saint" )
         )
     )
     another_lot = convert_tree( 
         dict( a = "lkjlkjl",
             b = dict( 
                 e = set( [ 1 , 2 , 3 ] ),
                 f = lambda x ,y : 2 * y,
                 g = dict(),
             ),
             pp = dict(a  = "serre" )
         ),
     )
     cl = Exception('CollisionError','')
     
     self.assertRaises(
     Exception,
     a_lot_of_type.union, another_lot
     )
Example #2
0
    def test_union_ok( self):
        a_lot_of_type= convert_tree( 
            dict( 
                a = "lkjlkjl",
                b = dict( 
                    e = set( [ 1 , 2 , 3 ] ),
                    f = 123.123123123,
                
                ),
                p = dict(a  = "saint" )
            )
        )
        another_lot = convert_tree( 
            dict( a = "lkjlkjl",
                b = dict( 
                    h = "f**k",
                    i = dict( a = 1 ),
                    e = set( [ 1 , 2 , 3, 5 ] ),
                    f = 123.123123123,
                    g = dict(),
                ),
                pp = dict(a  = "serre" )
            ),
        )
        un= a_lot_of_type.union(another_lot)
        expected = convert_tree( {
    'a' : 'lkjlkjl',
    'p' : {
        'a' : 'saint',
    },
    'pp' : {
        'a' : 'serre',
    },
    'b' : {
        'i' : {
            'a' : 1,
        },
        'e' : set([1, 2, 3, 5]),
        'g' : {
        },
        'f' : 123.123123123,
    },
})

        self.assertEqual( 
            un,
            expected) 
Example #3
0
    def test_bug_convert_empty_mapping( self ):
        """bug #8 : empty mapping intialisation dont work"""
        bug = convert_tree( dict( a = {} ) )
        expected  = VectorDict(None, {'a': {}})
        
        self.assertEqual( 
            expected,
            bug

        )
Example #4
0
 def setUp(self):
     self.easy = VectorDict( int, dict( x=1, y=1, z=0 ) )
     self.easy_too = VectorDict( int, dict( x=0,y=-2,o=0, ynot = self.easy ))
     self.a_tree = dict( 
         a = 1, 
         b = dict( 
             c = 3.0, 
             d = dict( e = True)
         ), 
         point = self.easy 
     )
     self.cplx = convert_tree( self.a_tree )
        dst = VectorDict(VectorDict, {})
        for coord, funct in self.iteritems():
            if not is_leaf(funct):
                real_func = lambda v: funct(v)
            else:
                real_func = funct

            dst.build_path(*(list(coord.dst) + [real_func(src.at(coord.src))]))
        return dst


if "__main__" == __name__:
    from VectorDict import convert_tree
    from Operation import identity, mul, cast

    a = convert_tree({"a": {"b": 1, "c": 2}, "b": 0})
    a.pprint()
    print a.at(["a", "c"])
    m = SparseMatrix(
        (tuple(["a", "b"]), tuple(["mul", "neg2"]), mul(-2)),
        (tuple(["a", "c"]), tuple(["mul", "misplaced"]), cast(float)),
        (tuple(["b"]), tuple(["a"]), lambda x: -4),
        (tuple(["a"]), tuple(["a_dict"]), identity),
    )
    m.pprint()
    print "**************"
    print m(a)
    m(a).pprint()
    print "iiiiiiiiiiiiiiiiiiiiiiiiiiiii"
    w = SparseMatrix()
    w[Coordinates(src=tuple([]), dst=tuple(["a_copy"]))] = identity
Example #6
0
 def test_convert(self):
     self.assertEqual( convert_tree( { 'a' : { 'b' : 1 } } ) ,
         VectorDict( VectorDict, 
             { 'a' : VectorDict( VectorDict, dict( b = 1 ) ) }
         )
     )