Example #1
0
    def test_init(self):
        '''
        test that the init function in the DataContainer sets the right variables
        '''
        self.failUnlessRaises(TypeError, DataContainer)

        dc = DataContainer("foo.test")
        self.failIf(dc.istmp(),
                    "DataContainer( 'foo.test' ) should not be tmp data")
        self.failUnlessEqual(dc.nodenames, set(['localhost']))

        dc = DataContainer("foo.test", tmp=True)
        self.failUnless(dc.istmp(),
                        "DataContainer( 'foo.test' ) should not be tmp data")

        #        set_trace()
        dc = DataContainer(parameters=PSpace('adc'))
        self.failUnless(dc.istmp())
        self.failUnlessEqual(dc.nodenames, set())

        dc = DataContainer(parameters=PSpace('adc'),
                           tmp=False,
                           target_node='r')

        self.failIf(dc.istmp())
        self.failUnlessEqual(dc.target_node, 'r')
Example #2
0
    def test_get_params( self ):
        
        space = PSpace( 'adc' , n1=UnknownValue, n2=33 )
        
        restrictions = space._get_params(keep_unknown=False )
        self.failUnlessEqual( restrictions, dict(n2=33) )

        restrictions = space._get_params(keep_unknown=True )
        self.failUnlessEqual( restrictions, dict(n2=33, n1=UnknownValue ) )
Example #3
0
 def testpop( self ):
     
     space = PSpace( 'adc' , a=1 )
     
     a = space.pop('a')
     self.failUnlessEqual(a , 1 )
     
     self.failUnlessRaises(KeyError, space.pop , 'b' )
     
     if NI: raise NotImplementedError("test not implemented")
Example #4
0
 def testcopy_eq( self ):
     
     space = PSpace('adc', n1=10, n2=10, data_type='float' )
     
     space_copy = space.copy()
     
     self.failUnlessEqual( space, space_copy )
     # test eq
     self.failUnlessEqual( space.plugin, space_copy.plugin )
     self.failUnlessEqual( space['n1'], space_copy['n1'] )
     self.failUnlessEqual( space['n2'], space_copy['n2'] )
     self.failUnlessEqual( space['data_type'], space_copy['data_type'] )
     
     self.failIfEqual( id(space), id(space_copy) )
Example #5
0
    def testeqType(self):

        space1 = PSpace('adc', data_type='complex')
        space2 = space1.copy()
        space3 = space1.copy()

        cf.eqType(None, [space1, space2, space3])

        space3['data_type'] = 'float'

        self.failUnlessRaises(TypeError, cf.eqType, None,
                              [space1, space2, space3])

        space1 = PSpace('adc')
        self.failUnlessRaises(TypeError, cf.eqType, None, [space1])
Example #6
0
    def makeparams(self):
        """
        make the parameter object from the given data
        should be extended for each plug-in
        """
        par = PSpace(self.__class__, self.readattr())

        return par
Example #7
0
    def testmatch(self):

        space = PSpace('adc', n1=12)

        cf.match(space, 'n1')
        cf.match(space, n1=12)

        self.failUnlessRaises(TypeError, cf.match, space, 'n2')
        self.failUnlessRaises(TypeError, cf.match, space, n2=1)
Example #8
0
    def testintersection( self ):
        
        
        s1 = PSpace('adc', a=1)
        s2 = PSpace('adc', b=2)
        s3 = PSpace('adc', a=1, b=2)
        s4 = PSpace('adc', a=UnknownValue)

        self.failUnlessEqual( s1.intersection( s2 ), s3 )
        
#        self.failUnlessEqual( s1.intersection( s2, s3 ), s3 )
        
        self.failUnlessEqual( s3.intersection( s1 ), s3 )
        
        self.failUnlessEqual( s1.intersection( s4 ), s1 )
Example #9
0
    def testadd_node_name(self):
        dc = DataContainer(parameters=PSpace('adc'))

        self.failUnlessEqual(dc.nodenames, set())

        dc.add_node_name('node1')

        self.failUnlessEqual(dc.nodenames, set(['node1']))

        if NI: raise NotImplementedError("test not implemented")
Example #10
0
 def testequal_keys( self ):
     
     s1 = PSpace('adc', a=1)
     s3 = PSpace('adc', a=1, b=2)
     s4 = PSpace('adc', a=UnknownValue)
     
     self.failUnless( s1.equal_keys( s3, 'a') )
     self.failUnless( s1.equal_keys( s4, 'a', accept_unknown=True ) )
     self.failIf( s1.equal_keys( s4, 'a', accept_unknown=False ) )
Example #11
0
    def testis_sub_superspace( self ):
        
        sub = PSpace( 'adc' , a=1, b=2 )
        supr = PSpace( 'adc' , a=1 )
        
        self.failUnless( supr.is_superspace( sub ) )
        self.failUnless( sub.is_subspace( supr ) )

        self.failIf( sub.is_superspace( supr ) )
        self.failIf( supr.is_subspace( sub ) )
        
        self.failUnless( sub in supr )
        self.failIf( supr in sub )
Example #12
0
 def testhas_unknown( self ):
     
     space = PSpace( 'adc' , n1=UnknownValue )
     space2 = PSpace( 'adc' , n1=22 )
     
     self.failUnless( space.has_unknown() )
     self.failIf( space2.has_unknown() )
Example #13
0
    def test_space_helper( self ):
        
        s1 = PSpace( 'adc' , n1=UnknownValue, n2=33, n3=33 )
        s2 = PSpace( 'adc' , n1=11, n2=22 , d1=0 )
        
        self.failUnlessRaises( Exception,  s1._space_helper, s2 , error=True )
        
        inter_space, dspace_s1, dspace_s2 = s1._space_helper( s2 , error=False )
        
        self.failUnlessEqual( inter_space.params, dict(n1=11) )
        self.failUnlessEqual( dspace_s1.params, dict(n3=33) ) 
        self.failUnlessEqual( dspace_s2.params, dict(d1=0) )

        s1 = PSpace( 'adc' , n1=11, n2=22, n3=33 )
        s2 = PSpace( 'adc' , n1=11, n2=22 , d1=0 )
        
        
        inter_space, dspace_s1, dspace_s2 = s1._space_helper( s2 , error=False )
        
        self.failUnlessEqual( inter_space.params, dict(n1=11,n2=22) )
        self.failUnlessEqual( dspace_s1.params, dict(n3=33) ) 
        self.failUnlessEqual( dspace_s2.params, dict(d1=0) )
Example #14
0
    def testeqShape(self):

        space1 = PSpace('adc', n1=12, n2=12)
        space2 = space1.copy()
        space3 = space1.copy()

        cf.eqShape(None, [space1, space2, space3])

        del space3['n2']

        self.failUnlessRaises(TypeError, cf.eqType, None,
                              [space1, space2, space3])

        space1 = PSpace('adc', n1=12, n2=1)
        space2 = space1.copy()

        del space2['n2']

        cf.eqShape(None, [space1, space2])
Example #15
0
 def coalesce(self):
     slist = self.ravel().tolist()
     return PSpace.union(*slist)
Example #16
0
    def test_shape( self ):
        'test shape getters and setters'
        
        space = PSpace('adc', n1=10, n2=10 )
        
        self.failUnlessEqual(space.shape, [10,10])

        space = PSpace('adc', n1=10, n2=10 ,n3=1)
        
        self.failUnlessEqual(space.shape, [10,10])
        
        self.failUnlessEqual( space.size, 100 )
        self.failUnlessEqual( len(space), 100 )
        
        space.shape = [20,20]
        
        self.failUnlessEqual( space.shape , [20,20] )
        
        self.failUnlessEqual( space['n1'] , 20 )
        self.failUnlessEqual( space['n2'] , 20 )
        self.failIf( space.has_key('n3') )
        
        space = PSpace('adc' )
        self.failUnlessEqual( space.shape , () )

        space = PSpace('adc' ,n1=0 )
        self.failUnlessRaises(TypeError, getattr, space, 'shape')

        space = PSpace('adc' , n1=UnknownValue )
        
        self.failUnlessEqual( space.shape , [UnknownValue] )
        
        self.failUnlessEqual( space.size, None )
Example #17
0
    def testunion( self ):
        
        s1 = PSpace('adc', a=1)
        s2 = PSpace('adc', b=2)
        s3 = PSpace('adc', a=1, b=2)
        s4 = PSpace('adc', a=UnknownValue)

        self.failUnlessEqual( s1.union( s2 ), PSpace('adc') )
        
        self.failUnlessEqual( s1.union( s2, s3 ), PSpace('adc') )
        
        self.failUnlessEqual( s1.union( s3 ), s1 )
        
        self.failUnlessEqual( s1.union( s4 ), s1 )
Example #18
0
 def testhas_key( self ):
     
     space = PSpace( 'adc' , data_type='complex' )
     
     self.failUnless( space.has_key( 'data_type' ) )
     self.failIf( space.has_key( 'does not have this key' ) )