def __setattr__(self, name, val):
     if name == 'special':
         return
     elif name in self.__class__.__dict__:
         fp = self.__class__.__dict__[name]
         fp.__set__(self, val)
     else:
         helpers.gen_setter(self.__dict__, name, val)
 def __setattr__(self,name,val):
     if name is 'special':
         return
     elif name in self.__class__.__dict__:
         fp = self.__class__.__dict__[name]
         fp.__set__(self,val)
     else:
         helpers.gen_setter(self.__dict__,name,val)
    def test_split_file_name(self):
        fpath,nums,fext = helpers.parse_run_file_name('MER10100.nxs')

        self.assertEqual(fpath,'')
        self.assertEqual(nums,10100)
        self.assertEqual(fext,'.nxs')
        fpath,nums,fext = helpers.parse_run_file_name('c:/somepath/MER1011,MER10100.nxs')
        self.assertEqual(len(nums),2)
        self.assertEqual(nums[0],1011)
        self.assertEqual(nums[1],10100)
        self.assertEqual(fpath[0],'c:/somepath')
        self.assertEqual(fpath[1],'')

        fpath,nums,fext = helpers.parse_run_file_name('c:/somepath/MER1011:MER1014.nxs,1046')
        self.assertEqual(len(nums),5)
Example #4
0
    def test_split_file_name(self):
        fpath,nums,fext = helpers.parse_run_file_name('MER10100.nxs')

        self.assertEqual(fpath,'')
        self.assertEqual(nums,10100)
        self.assertEqual(fext,'.nxs')
        fpath,nums,fext = helpers.parse_run_file_name('c:/somepath/MER1011,MER10100.nxs')
        self.assertEqual(len(nums),2)
        self.assertEqual(nums[0],1011)
        self.assertEqual(nums[1],10100)
        self.assertEqual(fpath[0],'c:/somepath')
        self.assertEqual(fpath[1],'')

        fpath,nums,fext = helpers.parse_run_file_name('c:/somepath/MER1011:MER1014.nxs,1046')
        self.assertEqual(len(nums),5)
Example #5
0
 def __init__(self):
     object.__setattr__(self,'A',helpers.ComplexProperty(['B','C']))
     #kkdict['A']=
     kkdict = {}
     kkdict['B']=19
     kkdict['C']=1000
     self.__dict__.update(kkdict)
Example #6
0
    def testbuild_properties_dict(self):
        kkdict = {};
        kkdict['first']='kkk1:kkk2';
        kkdict['kkk1']=19;
        kkdict['kkk2']=1000;
        kkdict['other']='unrelated';
        kkdict['second']='ssss1:ssss2:third';
        kkdict['third']='Babara';

        subst = {};
        subst['ssss1']='kkk1';
        subst['ssss2']='other';

        subst_dict,descr = helpers.build_properties_dict(kkdict,subst)

        self.assertEqual(len(subst_dict),6);

        val = subst_dict['_first'];
        self.assertTrue(type(val) is helpers.ComplexProperty)

        #self.assertEqual(val[0],'kkk1');
        #self.assertEqual(val[1],'kkk2');

        val = subst_dict['other']
        self.assertFalse(type(val) is helpers.ComplexProperty)
        self.assertEqual(val,'unrelated');

        val = subst_dict['_second']

        self.assertTrue(type(val) is helpers.ComplexProperty)
    def testbuild_properties_dict(self):
        kkdict = {}
        kkdict['first']='kkk1:kkk2'
        kkdict['kkk1']=19
        kkdict['kkk2']=1000
        kkdict['other']='unrelated'
        kkdict['second']='ssss1:ssss2:third'
        kkdict['third']='Babara'

        subst = {}
        subst['ssss1']='kkk1'
        subst['ssss2']='other'

        subst_dict,descr = helpers.build_properties_dict(kkdict,subst)

        self.assertEqual(len(subst_dict),6)

        val = subst_dict['_first']
        self.assertTrue(type(val) is helpers.ComplexProperty)

        #self.assertEqual(val[0],'kkk1')
        #self.assertEqual(val[1],'kkk2')

        val = subst_dict['other']
        self.assertFalse(type(val) is helpers.ComplexProperty)
        self.assertEqual(val,'unrelated')

        val = subst_dict['_second']

        self.assertTrue(type(val) is helpers.ComplexProperty)
    def test_build_properties_dict_ksubst(self):
        kkdict = {};
        kkdict['first']='kkk1:kkk2';
        kkdict['kkk1']=19;
        kkdict['kkk2']=1000;
        kkdict['other']='unrelated';
        kkdict['second']='ssss1:ssss2:third';
        kkdict['third']='Babara';

        subst = {};
        subst['first']=1;
        subst['ssss1']='kkk1';
        subst['ssss2']='other';
        subst['third']=3;
        subst['second']=2;

        subst_dict,descr_dict = helpers.build_properties_dict(kkdict,subst)

        self.assertEqual(len(subst_dict),6);

        val = subst_dict['_1']
        self.assertTrue(type(val) is helpers.ComplexProperty)

        #self.assertEqual(val[0],'kkk1');
        #self.assertEqual(val[1],'kkk2');

        val = subst_dict['other']
        self.assertFalse(type(val) is helpers.ComplexProperty)
        self.assertEqual(val,'unrelated');

        val = subst_dict['_2']
        self.assertTrue(type(val) is helpers.ComplexProperty)
    def testbuild_properties_dict(self):
        kkdict = {}
        kkdict['first'] = 'kkk1:kkk2'
        kkdict['kkk1'] = 19
        kkdict['kkk2'] = 1000
        kkdict['other'] = 'unrelated'
        kkdict['second'] = 'ssss1:ssss2:third'
        kkdict['third'] = 'Babara'

        subst = {}
        subst['ssss1'] = 'kkk1'
        subst['ssss2'] = 'other'

        subst_dict, descr = helpers.build_properties_dict(kkdict, subst)

        self.assertEqual(len(subst_dict), 6)

        val = subst_dict['_first']
        self.assertEqual(type(val), helpers.ComplexProperty)

        # self.assertEqual(val[0],'kkk1')
        # self.assertEqual(val[1],'kkk2')

        val = subst_dict['other']
        self.assertNotEqual(type(val), helpers.ComplexProperty)
        self.assertEqual(val, 'unrelated')

        val = subst_dict['_second']

        self.assertEqual(type(val), helpers.ComplexProperty)
    def test_build_subst_dictionary(self):
        self.assertEqual(dict(), helpers.build_subst_dictionary(""))
        self.assertEqual(dict(), helpers.build_subst_dictionary())

        self.assertRaises(AttributeError, helpers.build_subst_dictionary, 10)
        self.assertRaises(AttributeError, helpers.build_subst_dictionary, "A=")
        self.assertRaises(AttributeError, helpers.build_subst_dictionary,
                          "B=C;A=")

        rez = dict()
        rez['A'] = 'B'
        self.assertEqual(rez, helpers.build_subst_dictionary(rez))

        myDict = helpers.build_subst_dictionary("A=B")
        self.assertEqual(myDict['B'], 'A')

        myDict = helpers.build_subst_dictionary("A=B;C=DD")
        self.assertEqual(myDict['B'], 'A')
        self.assertEqual(myDict['DD'], 'C')
        myDict = helpers.build_subst_dictionary("A=B=C=DD")
        self.assertEqual(myDict['B'], 'A')
        self.assertEqual(myDict['DD'], 'A')
        self.assertEqual(myDict['C'], 'A')

        myDict = helpers.build_subst_dictionary("A = B = C=DD")
        self.assertEqual(myDict['B'], 'A')
        self.assertEqual(myDict['DD'], 'A')
        self.assertEqual(myDict['C'], 'A')
    def test_build_subst_dictionary(self):
        self.assertEqual(dict(), helpers.build_subst_dictionary(""))
        self.assertEqual(dict(), helpers.build_subst_dictionary())

        self.assertRaises(AttributeError, helpers.build_subst_dictionary, 10)
        self.assertRaises(AttributeError, helpers.build_subst_dictionary, "A=")
        self.assertRaises(AttributeError, helpers.build_subst_dictionary, "B=C;A=")

        rez=dict()
        rez['A']='B'
        self.assertEqual(rez, helpers.build_subst_dictionary(rez))

        myDict = helpers.build_subst_dictionary("A=B")
        self.assertEqual(myDict['B'],'A')

        myDict = helpers.build_subst_dictionary("A=B;C=DD")
        self.assertEqual(myDict['B'],'A')
        self.assertEqual(myDict['DD'],'C')
        myDict = helpers.build_subst_dictionary("A=B=C=DD")
        self.assertEqual(myDict['B'],'A')
        self.assertEqual(myDict['DD'],'A')
        self.assertEqual(myDict['C'],'A')

        myDict = helpers.build_subst_dictionary("A = B = C=DD")
        self.assertEqual(myDict['B'],'A')
        self.assertEqual(myDict['DD'],'A')
        self.assertEqual(myDict['C'],'A')
    def test_get_default_idf_param_list(self):
        pInstr = self.getInstrument()

        param_list = helpers.get_default_idf_param_list(pInstr)
        self.assertTrue(isinstance(param_list, dict))
        # check couple of parameters which are certainly in IDF
        self.assertTrue('deltaE-mode' in param_list)
        self.assertTrue('normalise_method' in param_list)
        self.assertTrue('diag_samp_lo' in param_list)
    def test_get_default_idf_param_list(self):
        pInstr=self.getInstrument()

        param_list = helpers.get_default_idf_param_list(pInstr)
        self.assertTrue(isinstance(param_list,dict))
        # check couple of parameters which are certainly in IDF
        self.assertTrue('deltaE-mode' in param_list)
        self.assertTrue('normalise_method' in param_list)
        self.assertTrue('diag_samp_lo' in param_list)
            def __init__(self):
                kkdict = {}
                kkdict['_A'] = helpers.ComplexProperty(['B', 'C'])
                kkdict['B'] = 19
                kkdict['C'] = 1000
                class_decor = '_' + type(self).__name__

                kkdict[class_decor + '__special'] = 'D'
                self.__dict__.update(kkdict)
 def __getattribute__(self, name):
     if name[:2] == '__':
         attr = object.__getattribute__(self, name)
         return attr
     else:
         attr_dic = object.__getattribute__(self, '__dict__')
         if name == '__dict__':
             return attr_dic
         else:
             return helpers.gen_getter(attr_dic, name)
         pass
 def __getattribute__(self,name):
     if name[:2] == '__':
         attr = object.__getattribute__(self,name)
         return attr
     else:
         attr_dic = object.__getattribute__(self,'__dict__')
         if name is '__dict__':
             return attr_dic
         else:
             return helpers.gen_getter(attr_dic,name)
         pass
            def __init__(self):
                all_methods = dir(self)
                existing = []
                for meth in all_methods:
                    if meth[:1] != '_':
                        existing.append(meth)
                kkdict = {}
                kkdict['_A'] = helpers.ComplexProperty(['B', 'C'])
                kkdict['B'] = 19
                kkdict['C'] = 1000

                class_decor = '_' + type(self).__name__
                object.__setattr__(self, class_decor + '__exmeth', existing)

                self.__dict__.update(kkdict)
    def testbuild_properties_dict_pref(self):
        kkdict = {}
        kkdict['first']='kkk1:kkk2'
        kkdict['kkk1']=19
        kkdict['kkk2']=1000
        kkdict['other']='unrelated'
        kkdict['second']='ssss1:ssss2:third'
        kkdict['third']='Babara'
        kkdict['descr1']='ddd'
        kkdict['descr2']='kkk1:kkk2'
        kkdict['descr3']=10

        subst = {}
        subst['ssss1']='kkk1'
        subst['ssss2']='other'
        subst['descr2']='des222'


        prop_dict,desct = helpers.build_properties_dict(kkdict,subst,['descr1','des222','descr3'])
        self.assertEqual(len(desct),3)
        self.assertEqual(desct['descr3'],10)
        self.assertEqual(desct['descr1'],'ddd')
        self.assertTrue('des222' in desct.keys())


        self.assertEqual(len(prop_dict),6)

        val = prop_dict['_first']
        self.assertTrue(type(val) is helpers.ComplexProperty)

        #elf.assertEqual(val[0],'_kkk1')
        #self.assertEqual(val[1],'_kkk2')

        val = prop_dict['other']
        self.assertFalse(type(val) is helpers.ComplexProperty)
        self.assertEqual(val,'unrelated')

        val = prop_dict['_second']
        self.assertTrue(type(val) is helpers.ComplexProperty)

        #self.assertEqual(val[0],'_kkk1')
        #self.assertEqual(val[1],'_other')
        #self.assertEqual(val[2],'_third')


        val = prop_dict['third']
        self.assertFalse(type(val) is helpers.ComplexProperty)
        self.assertEqual(val,'Babara')
    def test_gen_setter(self):
        kkdict = {}
        kkdict['A'] = helpers.ComplexProperty(['B', 'C'])
        kkdict['B'] = 19
        kkdict['C'] = 1000

        helpers.gen_setter(kkdict, 'B', 0)
        self.assertEqual(kkdict['B'], 0)
        helpers.gen_setter(kkdict, 'C', 10)
        self.assertEqual(kkdict['C'], 10)

        self.assertRaises(KeyError, helpers.gen_setter, kkdict, 'A', 100)
        self.assertEqual(kkdict['B'], 0)

        helpers.gen_setter(kkdict, 'A', [1, 10])
        self.assertEqual(kkdict['B'], 1)
        self.assertEqual(kkdict['C'], 10)

        helpers.gen_setter(kkdict, 'A', (2, 20))
        self.assertEqual(kkdict['B'], 2)
        self.assertEqual(kkdict['C'], 20)
Example #20
0
    def testbuild_properties_dict_pref(self):
        kkdict = {}
        kkdict['first']='kkk1:kkk2'
        kkdict['kkk1']=19
        kkdict['kkk2']=1000
        kkdict['other']='unrelated'
        kkdict['second']='ssss1:ssss2:third'
        kkdict['third']='Babara'
        kkdict['descr1']='ddd'
        kkdict['descr2']='kkk1:kkk2'
        kkdict['descr3']=10

        subst = {}
        subst['ssss1']='kkk1'
        subst['ssss2']='other'
        subst['descr2']='des222'


        prop_dict,desct = helpers.build_properties_dict(kkdict,subst,['descr1','des222','descr3'])
        self.assertEqual(len(desct),3)
        self.assertEqual(desct['descr3'],10)
        self.assertEqual(desct['descr1'],'ddd')
        self.assertTrue('des222' in desct.keys())


        self.assertEqual(len(prop_dict),6)

        val = prop_dict['_first']
        self.assertEqual(type(val), helpers.ComplexProperty)

        #elf.assertEqual(val[0],'_kkk1')
        #self.assertEqual(val[1],'_kkk2')

        val = prop_dict['other']
        self.assertNotEqual(type(val), helpers.ComplexProperty)
        self.assertEqual(val,'unrelated')

        val = prop_dict['_second']
        self.assertEqual(type(val), helpers.ComplexProperty)

        #self.assertEqual(val[0],'_kkk1')
        #self.assertEqual(val[1],'_other')
        #self.assertEqual(val[2],'_third')


        val = prop_dict['third']
        self.assertNotEqual(type(val), helpers.ComplexProperty)
        self.assertEqual(val,'Babara')
Example #21
0
    def test_gen_setter(self):
        kkdict = {};
        kkdict['A']=helpers.ComplexProperty(['B','C']);
        kkdict['B']=19;
        kkdict['C']=1000;
   

        helpers.gen_setter(kkdict,'B',0)
        self.assertEqual(kkdict['B'],0);
        helpers.gen_setter(kkdict,'C',10)
        self.assertEqual(kkdict['C'],10);

        self.assertRaises(KeyError,helpers.gen_setter,kkdict,'A',100)
        self.assertEqual(kkdict['B'],0);

        helpers.gen_setter(kkdict,'A',[1,10])
        self.assertEqual(kkdict['B'],1);
        self.assertEqual(kkdict['C'],10);
    def test_gen_setter(self):
        kkdict = {}
        kkdict['A']=helpers.ComplexProperty(['B','C'])
        kkdict['B']=19
        kkdict['C']=1000


        helpers.gen_setter(kkdict,'B',0)
        self.assertEqual(kkdict['B'],0)
        helpers.gen_setter(kkdict,'C',10)
        self.assertEqual(kkdict['C'],10)

        self.assertRaises(KeyError,helpers.gen_setter,kkdict,'A',100)
        self.assertEqual(kkdict['B'],0)

        helpers.gen_setter(kkdict,'A',[1,10])
        self.assertEqual(kkdict['B'],1)
        self.assertEqual(kkdict['C'],10)

        helpers.gen_setter(kkdict,'A',(2,20))
        self.assertEqual(kkdict['B'],2)
        self.assertEqual(kkdict['C'],20)
Example #23
0
    def test_gen_getter(self):
        kkdict = {}
        kkdict['first']='kkk1:kkk2'
        kkdict['kkk1']=19
        kkdict['kkk2']=1000
        kkdict['other']='unrelated'
        kkdict['second']='ssss1:ssss2:third'
        kkdict['third']='Babara'

        subst = {}
        subst['ssss1']='kkk1'
        subst['ssss2']='other'

        subst_dict,descr = helpers.build_properties_dict(kkdict,subst)
        self.assertEqual(helpers.gen_getter(subst_dict,'kkk1'),19)
        self.assertEqual(helpers.gen_getter(subst_dict,'kkk2'),1000)
        self.assertEqual(helpers.gen_getter(subst_dict,'first'),(19,1000))
        self.assertEqual(helpers.gen_getter(subst_dict,'other'),'unrelated')
        self.assertEqual(helpers.gen_getter(subst_dict,'second'),[19,'unrelated','Babara'])
        self.assertEqual(helpers.gen_getter(subst_dict,'third'),'Babara')
    def test_gen_getter(self):
        kkdict = {}
        kkdict['first']='kkk1:kkk2'
        kkdict['kkk1']=19
        kkdict['kkk2']=1000
        kkdict['other']='unrelated'
        kkdict['second']='ssss1:ssss2:third'
        kkdict['third']='Babara'

        subst = {}
        subst['ssss1']='kkk1'
        subst['ssss2']='other'

        subst_dict,descr = helpers.build_properties_dict(kkdict,subst)
        self.assertEqual(helpers.gen_getter(subst_dict,'kkk1'),19)
        self.assertEqual(helpers.gen_getter(subst_dict,'kkk2'),1000)
        self.assertEqual(helpers.gen_getter(subst_dict,'first'),(19,1000))
        self.assertEqual(helpers.gen_getter(subst_dict,'other'),'unrelated')
        self.assertEqual(helpers.gen_getter(subst_dict,'second'),[19,'unrelated','Babara'])
        self.assertEqual(helpers.gen_getter(subst_dict,'third'),'Babara')
 def __getattr__(self, name):
     return helpers.gen_getter(self.__dict__, name)
    def __get__(self,instance,type=None):
        if instance is None:
           return self

        return prop_helpers.gen_getter(instance.__dict__,'use_hard_mask_only')
 def __getattr__(self,name):
     return helpers.gen_getter(self.__dict__,name)
 def __setattr__(self,name,val):
     if  name in self.__exmeth:
         object.__setattr__(self,name,val)
     else:
         helpers.gen_setter(self.__dict__,name,val)
 def __getattr__(self, name):
     if name == 'special':
         return self.__special
     else:
         tDict = object.__getattribute__(self, '__dict__')
         return helpers.gen_getter(tDict, name)
 def __getattr__(self,name):
     if name is 'special':
         return self.__special
     else:
         tDict = object.__getattribute__(self,'__dict__')
         return helpers.gen_getter(tDict,name)
 def __setattr__(self, name, val):
     if name in self.__exmeth:
         object.__setattr__(self, name, val)
     else:
         helpers.gen_setter(self.__dict__, name, val)