Beispiel #1
0
 def test_beamtime_roundtrip(self):
     # This includes checking that a new uid is only generated once
     # and persists thereafter.
     bt = Beamtime('Simon', '123', [], wavelength=0.1828)
     reloaded_bt = Beamtime.from_yaml(bt.to_yaml())
     os.remove(bt.filepath)
     self.assertEqual(reloaded_bt, bt)
Beispiel #2
0
 def test_chaining(self):
     """All contents of Beamtime and Experiment should propagate into Sample."""
     bt = Beamtime('Simon', 123, [], wavelength=0.1828, custom1='A')
     sa_dict = {'sample_name': 'Ni', 'sample_composition': {'Ni': 1}}
     sa = Sample(bt, sa_dict, custom3='C')
     for k, v in bt.items():
         sa[k] == bt[k]
Beispiel #3
0
 def test_chaining(self):
     """All contents of Beamtime and Experiment should propagate into Sample."""
     bt = Beamtime('Simon', 123, [], wavelength=0.1828, custom1='A')
     sa_dict = {'sample_name': 'Ni', 'sample_composition': {'Ni': 1}}
     sa = Sample(bt, sa_dict, custom3='C')
     for k, v in bt.items():
         sa[k] == bt[k]
Beispiel #4
0
 def test_beamtime_roundtrip(self):
     # This includes checking that a new uid is only generated once
     # and persists thereafter.
     bt = Beamtime("Simon", "123", [], wavelength=0.1828)
     reloaded_bt = Beamtime.from_yaml(bt.to_yaml())
     os.remove(bt.filepath)
     self.assertEqual(reloaded_bt, bt)
Beispiel #5
0
 def test_set_wavelength(self):
     wavelength = .18448
     self.bt = Beamtime('test', 123)
     self.assertEqual(self.bt.md['bt_wavelength'], None)
     self.bt.set_wavelength(wavelength)
     self.assertEqual(self.bt.md['bt_wavelength'], wavelength)
     self.assertEqual(self.bt.name, 'bt')
     self.assertEqual(self.bt.md['bt_piLast'], 'test')
Beispiel #6
0
 def test_chaining(self):
     """All contents of Beamtime and Experiment should propagate into
     Sample."""
     bt = Beamtime("Simon", 123, [], wavelength=0.1828, custom1="A")
     sa_dict = {"sample_name": "Ni", "sample_composition": {"Ni": 1}}
     sa = Sample(bt, sa_dict, custom3="C")
     for k, v in bt.items():
         assert sa[k] == bt[k]
Beispiel #7
0
 def test_get_obj_uid(self):
     name = 'bt'
     otype = 'bt'
     bt = Beamtime('me',123,321,[])
     uid1 = bt._get_obj_uid('bt','bt')
     self.assertNotEqual(uid1,'')
     bt = Beamtime('you',123,321,[])
     uid2 = bt._get_obj_uid('bt','bt')
     self.assertEqual(uid1,uid2)
Beispiel #8
0
    def test_load_beamtime(self):
        bt = Beamtime('Simon', 123, [], wavelength=0.1828, custom1='A')
        sa_dict = {'sample_name': 'Ni', 'sample_composition': {'Ni': 1}}
        sa = Sample(bt, sa_dict, custom3='C')

        bt2 = load_beamtime()
        self.assertEqual(bt2, bt)
        self.assertEqual(bt2.samples[0], sa)
Beispiel #9
0
 def test_sample_roundtrip(self):
     sa_dict = {'sample_name': 'Ni', 'sample_composition': {'Ni': 1}}
     bt = Beamtime('Simon', '123', [], wavelength=0.1828)
     sam = Sample(bt, sa_dict)
     reloaded_sam = Sample.from_yaml(sam.to_yaml())
     os.remove(bt.filepath)
     os.remove(sam.filepath)
     self.assertEqual(reloaded_sam, sam)
Beispiel #10
0
 def test_set_wavelength(self):
     wavelength = .18448
     self.bt = Beamtime('test',123)
     self.assertEqual(self.bt.md['bt_wavelength'],None)
     self.bt.set_wavelength(wavelength)
     self.assertEqual(self.bt.md['bt_wavelength'],wavelength)
     self.assertEqual(self.bt.name,'bt')
     self.assertEqual(self.bt.md['bt_piLast'],'test')
Beispiel #11
0
 def test_sample_roundtrip(self):
     sa_dict = {"sample_name": "Ni", "sample_composition": {"Ni": 1}}
     bt = Beamtime("Simon", "123", [], wavelength=0.1828)
     sam = Sample(bt, sa_dict)
     reloaded_sam = Sample.from_yaml(sam.to_yaml())
     os.remove(bt.filepath)
     os.remove(sam.filepath)
     self.assertEqual(reloaded_sam, sam)
Beispiel #12
0
    def test_load_beamtime(self):
        bt = Beamtime("Simon", 123, [], wavelength=0.1828, custom1="A")
        sa_dict = {"sample_name": "Ni", "sample_composition": {"Ni": 1}}
        sa = Sample(bt, sa_dict, custom3="C")

        bt2 = load_beamtime()
        self.assertEqual(bt2, bt)
        self.assertEqual(list(bt2.samples.values())[0], sa)
Beispiel #13
0
 def test_get_obj_uid(self):
     name = 'bt'
     otype = 'bt'
     bt = Beamtime('me', 123, 321, [])
     uid1 = bt._get_obj_uid('bt', 'bt')
     self.assertNotEqual(uid1, '')
     bt = Beamtime('you', 123, 321, [])
     uid2 = bt._get_obj_uid('bt', 'bt')
     self.assertEqual(uid1, uid2)
Beispiel #14
0
 def test_bt_creation(self):
     _make_clean_env()
     self.bt = Beamtime(self.PI_name,
                        self.saf_num,
                        wavelength=self.wavelength,
                        experimenters=self.experimenters,
                        base_dir=self.base_dir)
     self.assertIsInstance(self.bt, Beamtime)
     self.assertEqual(self.bt.md['bt_experimenters'],
                      [('van der Banerjee', 'S0ham', 1),
                       ('Terban', 'Max', 2)])
     self.assertEqual(self.bt.md['bt_piLast'], 'Billinge')
     self.assertEqual(self.bt.md['bt_safN'], 123)
     self.assertEqual(self.bt.md['bt_wavelength'], 0.1812)
     # test empty experimenter
     self.experimenters = []
     bt = Beamtime(self.PI_name, self.saf_num, self.wavelength,
                   self.experimenters)
     self.assertIsInstance(bt, Beamtime)
     # test empty PI
     self.PI_name = None
     bt = Beamtime(self.PI_name, self.saf_num, self.wavelength,
                   self.experimenters)
     self.assertIsInstance(bt, Beamtime)
Beispiel #15
0
 def test_min_exposure_time(self):
     bt = Beamtime("Simon", 123, [], wavelength=0.1828, custom1="A")
     # shorter than acq time -> ValueError
     glbl["frame_acq_time"] = 0.5
     print("frame acq time = {}".format(glbl["frame_acq_time"]))
     # exposure as arg
     self.assertRaises(ValueError, lambda: ScanPlan(bt, ct, 0.2))
     # exposure as kwarg
     self.assertRaises(ValueError, lambda: ScanPlan(bt, ct, exposure=0.2))
     # proper frame acq time -> pass
     glbl["frame_acq_time"] = 0.1
     ScanPlan(bt, ct, 0.2)
     # test with xrun
     xrun = CustomizedRunEngine(bt)
     xrun({}, ScanPlan(bt, ct, 0.2))  # safe, should pass
     glbl["frame_acq_time"] = 0.5
     self.assertRaises(ValueError, lambda: xrun({}, ScanPlan(bt, ct, 0.2)))
     glbl["frame_acq_time"] = 0.1  # reset after test
Beispiel #16
0
def _execute_start_beamtime(piname,
                            safn,
                            explist,
                            wavelength=None,
                            home_dir=None):
    PI_name = piname
    saf_num = safn
    _make_clean_env()
    os.chdir(home_dir)
    bt = Beamtime(PI_name, saf_num, experimenters=explist)

    # now populate the database with some lazy-user objects
    ex = Experiment('l-user', bt)
    sa = Sample('l-user', ex)
    sc01 = ScanPlan('ct', {'exposure': 0.1})
    sc05 = ScanPlan('ct', {'exposure': 0.5})
    sc1 = ScanPlan('ct', {'exposure': 1.0})
    sc5 = ScanPlan('ct', {'exposure': 5.0})
    sc10 = ScanPlan('ct', {'exposure': 10.0})
    sc30 = ScanPlan('ct', {'exposure': 30.0})
    return bt
Beispiel #17
0
class NewExptTest(unittest.TestCase):

    def setUp(self):
        self.base_dir = glbl.base
        self.home_dir = glbl.home
        self.config_dir = glbl.xpdconfig
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(self.config_dir):
            shutil.rmtree(self.config_dir)
        os.makedirs(self.config_dir, exist_ok=True)
        self.PI_name = 'Billinge '
        self.saf_num = 234
        self.wavelength = 0.1812
        self.experimenters = [('van der Banerjee','S0ham',1),('Terban ',' Max',2)]
        self.saffile = os.path.join(self.config_dir,'saf{}.yml'.format(self.saf_num))
        #_make_clean_env()
        loadinfo = {'saf number':self.saf_num,'PI last name':self.PI_name,'experimenter list':self.experimenters}
        with open(self.saffile, 'w') as fo:
            yaml.dump(loadinfo,fo)
        self.bt = _start_beamtime(self.saf_num,home_dir=self.home_dir)
        self.stbt_list = ['bt_bt.yml','ex_l-user.yml','sa_l-user.yml','sp_ct_0.1.yml','sp_ct_0.5.yml','sp_ct_1.yml','sp_ct_5.yml','sp_ct_10.yml','sp_ct_30.yml']

    def tearDown(self):
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(os.path.join(self.base_dir,'xpdConfig')):
            shutil.rmtree(os.path.join(self.base_dir,'xpdConfig'))

    def test_clean_name(self):
    	# make sure yaml dir and bt object exists
    	name = ' my test experiment '
    	cleaned = _clean_name(name)
    	self.assertEqual(cleaned,'mytestexperiment')
    	name = ' my way too long experiment name from hell. Dont let users do this already! '
    	self.assertRaises(SystemExit, lambda:_clean_name(name))
    	# what if user gives something that is not a string?
    	name = []
    	self.assertRaises(SystemExit, lambda:_clean_name(name))
    
    @unittest.expectedFailure
    def test_yaml_path(self):
    	self.fail('need a test for _yaml_path')

    @unittest.expectedFailure
    def test_loadyamls(self):
        self.fail('need a test for loadyamls')

    def test_yamify(self):
        xpdobj = XPD()
        xpdobj.name = ' test'
        xpdobj.type = 'b t'
        yaml_dir = glbl.yaml_dir
        objlist = []
        lname = os.path.join(yaml_dir,'_acqobj_list.yml')
        #initialize the objlist yaml file if it doesn't exist
        if not os.path.isfile(lname):
            fo = open(lname, 'w')
            yaml.dump(objlist, fo)
        testfname = os.path.join(yaml_dir,'bt_test.yml')
        probe = xpdobj._yamify()
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['bt_test.yml'])
        xpdobj2 = XPD()
        xpdobj2.name = ' test2'
        xpdobj2.type = 'b t'
        testfname2 = os.path.join(yaml_dir,'bt_test2.yml')
        probe2 = xpdobj2._yamify()
        newobjlist2 = _get_yaml_list()
        self.assertEqual(newobjlist2,self.stbt_list+['bt_test.yml','bt_test2.yml'])
        self.assertEqual(probe,testfname)
        self.assertTrue(os.path.isfile(probe))
        # try adding another item that is already there
        probe3 = xpdobj2._yamify()
        newobjlist3 = _get_yaml_list()
        self.assertEqual(newobjlist3,self.stbt_list+['bt_test.yml','bt_test2.yml'])

#        olist = xpdobj.loadyamls()
#        self.assertEqual(olist[0].name,'bt')
#        self.assertEqual(olist[0].type,'bt')

    def test_update_objlist(self):
        objlist = []
        newobjlist = _update_objlist(objlist,'testme')
        self.assertEqual(newobjlist,['testme'])
        newobjlist2 = _update_objlist(newobjlist,'testme2')
        self.assertEqual(newobjlist2,['testme','testme2'])
        newobjlist3 = _update_objlist(newobjlist2,'testme2')
        self.assertEqual(newobjlist3,['testme','testme2'])

    def test_get_obj_uid(self):
        name = 'bt'
        otype = 'bt'
        bt = Beamtime('me',123,321,[])
        uid1 = bt._get_obj_uid('bt','bt')
        self.assertNotEqual(uid1,'')
        bt = Beamtime('you',123,321,[])
        uid2 = bt._get_obj_uid('bt','bt')
        self.assertEqual(uid1,uid2)

    def test_make_experiment(self):
        name = 'myexp '
        self.ex = Experiment(name,self.bt)
        self.assertIsInstance(self.ex,Experiment)
        self.assertEqual(self.ex.md['bt_experimenters'],[('van der Banerjee','S0ham',1),('Terban','Max',2)])
        self.assertEqual(self.ex.md['bt_piLast'],'Billinge')
        self.assertEqual(self.ex.md['bt_safN'],234)
        self.assertEqual(self.ex.md['bt_wavelength'],None)
        self.assertEqual(self.ex.md['ex_name'],'myexp')
        uid1 = self.ex.md['ex_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml'])
        self.ex2 = Experiment(' your exp',self.bt)
        self.assertEqual(self.ex2.md['ex_name'],'your exp')
        uid2 = self.ex2.md['ex_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','ex_yourexp.yml'])
        self.ex3 = Experiment(' your exp',self.bt)
        self.assertEqual(self.ex3.md['ex_name'],'your exp')
        uid3 = self.ex3.md['ex_uid']
        self.assertEqual(uid2,uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','ex_yourexp.yml'])

    def test_make_sample(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        self.assertIsInstance(self.sa,Sample)
        self.assertEqual(self.sa.md['bt_experimenters'],[('van der Banerjee','S0ham',1),('Terban','Max',2)])
        self.assertEqual(self.sa.md['bt_piLast'],'Billinge')
        self.assertEqual(self.sa.md['bt_safN'],234)
        self.assertEqual(self.sa.md['bt_wavelength'],None)
        self.assertEqual(self.sa.md['ex_name'],'myexp')
        self.assertEqual(self.sa.md['sa_name'],'my sample')
        uid1 = self.sa.md['sa_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.sa2 = Sample(' your sample',self.ex)
        self.assertEqual(self.sa2.md['sa_name'],'your sample')
        uid2 = self.sa2.md['sa_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml','sa_yoursample.yml'])
        self.sa3 = Sample(' your sample',self.ex)
        self.assertEqual(self.sa3.md['sa_name'],'your sample')
        uid3 = self.sa3.md['sa_uid']
        self.assertEqual(uid2,uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml','sa_yoursample.yml'])

    def test_make_scanPlan(self):
        self.sp = ScanPlan('ct',{'exposure':0.7})
        self.assertIsInstance(self.sp,ScanPlan)
        self.assertEqual(self.sp.md['sp_params'],{'exposure':0.7})
        uid1 = self.sp.md['sp_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['sp_ct_0.7.yml'])
        self.sp2 = ScanPlan('ct',{'exposure':1.5})
        self.assertEqual(self.sp2.md['sp_name'],'ct_1.5')
        uid2 = self.sp2.md['sp_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['sp_ct_0.7.yml','sp_ct_1.5.yml'])
        self.sp3 = ScanPlan('ct',{'exposure':1.5})
        self.assertEqual(self.sp3.md['sp_name'],'ct_1.5')
        uid3 = self.sp3.md['sp_uid']
        self.assertEqual(uid2,uid3)
        # and one that fails the validator
        self.assertRaises(SystemExit,lambda: ScanPlan('ct',{'exposur':1.0}))


    def test_hide(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist,[1])
        hidden_list = _get_hidden_list() 
        self.assertEqual(self.hidelist,hidden_list)
  
    def test_unhide(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist,[1])
        hidden_list1 = _get_hidden_list() 
        self.assertEqual(self.hidelist,hidden_list1)
        self.bt.unhide(0)
        hidden_list2 = _get_hidden_list() 
        self.assertEqual(hidden_list1,hidden_list2)
        self.bt.unhide(1)
        hidden_list3 = _get_hidden_list() 
        self.assertEqual(hidden_list3,[])

    def test_set_wavelength(self):
        wavelength = .18448
        self.bt = Beamtime('test',123)
        self.assertEqual(self.bt.md['bt_wavelength'],None)
        self.bt.set_wavelength(wavelength)
        self.assertEqual(self.bt.md['bt_wavelength'],wavelength)
        self.assertEqual(self.bt.name,'bt')
        self.assertEqual(self.bt.md['bt_piLast'],'test')
       
    def test_Scan_validator(self):
        #########################################################
        # Note: bt.list() so far is populated with l-user list
        #       bt.get(2) -> sa,'l-user' ; bt.get(5) -> sp, 'ct1s'
        #       bt.list() goes to 8
        ##########################################################
        # incorrect assignments -> str
        self.assertRaises(SystemExit, lambda: Scan._object_parser(Scan,'blahblah','sa'))
        self.assertRaises(SystemExit, lambda: Scan._object_parser(Scan,'ct157s','sp'))
        # incorrect assignments -> ind
        self.assertRaises(SystemExit, lambda: Scan._object_parser(Scan,100,'sp'))
        self.assertRaises(SystemExit, lambda: Scan._object_parser(Scan,250,'sa'))
        # incorrect object type from 3 kind of assignments
        self.assertRaises(TypeError, lambda: Scan(self.bt.get(1), self.bt.get(5))) # give Beamtime but not Sample
        self.assertRaises(TypeError, lambda: Scan(1, 'ct10s')) # give Beamtime but not Sample
        self.assertRaises(TypeError, lambda: Scan(8, 5)) # give two ScanPlan

    def test_auto_naming_ScanPlan(self):
        # wrong ScanPlan type
        self.assertRaises(SystemExit, lambda: ScanPlan('MRI_5_300_200_5'))
        # wrong positional arguments
        ''' doc string from ScanPlan
        expected format for each type is following:
        1) 'ct_10' means Count scan with 10s exposure time in total
        2) 'Tramp_10_300_200_5' means temperature ramp from 300k to 200k with 5k step and 10s exposure time each
        3) 'tseries_10_60_5' means time series scan of 10s exposure time each time 
            and run for 5 times with 60s delay between them.
        '''
        self.assertRaises(SystemExit, lambda: ScanPlan('ct_5_25575_32767')) # extra argument
        self.assertRaises(SystemExit, lambda: ScanPlan('Tramp_5_300_200')) # incomplete arguments
        self.assertRaises(SystemExit, lambda: ScanPlan('Tramp_5_300_200_5_1111')) # extra argument
        self.assertRaises(SystemExit, lambda: ScanPlan('tseries_5_60')) # incomplete arguments
        self.assertRaises(SystemExit, lambda: ScanPlan('tseries_5_60_10_1111')) # extra argument
        # additional unit
        self.assertRaises(SystemExit, lambda: ScanPlan('ct_5s'))
        self.assertRaises(SystemExit, lambda: ScanPlan('Tramp_5s_300k_200_5'))
        # test on optional argument
        sp = ScanPlan('ct_5', shutter=False)
        self.assertEqual(sp.name, 'ct_5_nS')
        sp = ScanPlan('ct_5', shutter=True)
        self.assertEqual(sp.name, 'ct_5')

    def test_ScanPlan_longform(self):
        # test creation
        self.assertRaises(TypeError, lambda: ScanPlan())
        # test sp_name
        self.sp1 = ScanPlan('ct',{'exposure':0.5})
        self.assertEqual(self.sp1.name, 'ct_0.5')
        self.sp2 = ScanPlan('tseries',{'exposure':0.5, 'num':5, 'delay':2.5})
        self.assertEqual(self.sp2.name, 'tseries_0.5_2.5_5')
        self.sp3 = ScanPlan('Tramp',{'exposure':0.8, 'endingT':200, 'startingT':300, 'Tstep':2})
        self.assertEqual(self.sp3.name, 'Tramp_0.8_300_200_2')
        # test sp_params values
        self.assertEqual(0.5, self.sp1.sp_params['exposure'])

        self.assertEqual(0.5, self.sp2.sp_params['exposure'])
        self.assertEqual(5, self.sp2.sp_params['num'])
        self.assertEqual(2.5, self.sp2.sp_params['delay'])

        self.assertEqual(0.8, self.sp3.sp_params['exposure'])
        self.assertEqual(200, self.sp3.sp_params['endingT'])
        self.assertEqual(300, self.sp3.sp_params['startingT'])
        self.assertEqual(2, self.sp3.sp_params['Tstep'])
Beispiel #18
0
def warn_wavelength(beamtime: Beamtime, key: str = "bt_wavelength") -> None:
    """Warning if no wavelength in beamtime."""
    if beamtime and beamtime.get(key) is None:
        print("WARNING: there is no wavelength information in current"
              "beamtime object, scan will keep going....")
Beispiel #19
0
class NewExptTest(unittest.TestCase):

    def setUp(self):
        self.base_dir = glbl.base
        self.home_dir = glbl.home
        self.config_dir = glbl.xpdconfig
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(self.config_dir):
            shutil.rmtree(self.config_dir)   
        os.makedirs(self.config_dir, exist_ok=True)
        self.PI_name = 'Billinge '
        self.saf_num = 234
        self.wavelength = 0.1812
        self.experimenters = [('van der Banerjee','S0ham',1),('Terban ',' Max',2)]
        self.saffile = os.path.join(self.config_dir,'saf{}.yml'.format(self.saf_num))
        #_make_clean_env()
        loadinfo = {'saf number':self.saf_num,'PI last name':self.PI_name,'experimenter list':self.experimenters}
        with open(self.saffile, 'w') as fo:
            yaml.dump(loadinfo,fo)
        self.bt = _start_beamtime(self.saf_num,home_dir=self.home_dir)     
        self.stbt_list = ['bt_bt.yml','ex_l-user.yml','sa_l-user.yml','sp_ct.1s.yml','sp_ct.5s.yml','sp_ct1s.yml','sp_ct5s.yml','sp_ct10s.yml','sp_ct30s.yml']

    def tearDown(self):
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(os.path.join(self.base_dir,'xpdConfig')):
            shutil.rmtree(os.path.join(self.base_dir,'xpdConfig'))        

    def test_clean_name(self):
    	# make sure yaml dir and bt object exists
    	name = ' my test experiment '
    	cleaned = _clean_name(name)
    	self.assertEqual(cleaned,'mytestexperiment')
    	name = ' my way too long experiment name from hell. Dont let users do this already! '
    	self.assertRaises(SystemExit, lambda:_clean_name(name))
    	# what if user gives something that is not a string?
    	name = []
    	self.assertRaises(SystemExit, lambda:_clean_name(name))
    
    @unittest.expectedFailure
    def test_yaml_path(self):
    	self.fail('need a test for _yaml_path')

    @unittest.expectedFailure
    def test_loadyamls(self):
        self.fail('need a test for loadyamls')

    def test_yamify(self):
        xpdobj = XPD()
        xpdobj.name = ' test'
        xpdobj.type = 'b t'
        yaml_dir = glbl.yaml_dir
        objlist = []
        lname = os.path.join(yaml_dir,'_acqobj_list.yml')
        #initialize the objlist yaml file if it doesn't exist
        if not os.path.isfile(lname):
            fo = open(lname, 'w')
            yaml.dump(objlist, fo)
        testfname = os.path.join(yaml_dir,'bt_test.yml')
        probe = xpdobj._yamify()
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['bt_test.yml'])
        xpdobj2 = XPD()
        xpdobj2.name = ' test2'
        xpdobj2.type = 'b t'
        testfname2 = os.path.join(yaml_dir,'bt_test2.yml')
        probe2 = xpdobj2._yamify()
        newobjlist2 = _get_yaml_list()
        self.assertEqual(newobjlist2,self.stbt_list+['bt_test.yml','bt_test2.yml'])
        self.assertEqual(probe,testfname)
        self.assertTrue(os.path.isfile(probe))
        # try adding another item that is already there
        probe3 = xpdobj2._yamify()
        newobjlist3 = _get_yaml_list()
        self.assertEqual(newobjlist3,self.stbt_list+['bt_test.yml','bt_test2.yml'])

#        olist = xpdobj.loadyamls()
#        self.assertEqual(olist[0].name,'bt')
#        self.assertEqual(olist[0].type,'bt')

    def test_update_objlist(self):
        objlist = []
        newobjlist = _update_objlist(objlist,'testme')
        self.assertEqual(newobjlist,['testme'])
        newobjlist2 = _update_objlist(newobjlist,'testme2')
        self.assertEqual(newobjlist2,['testme','testme2'])
        newobjlist3 = _update_objlist(newobjlist2,'testme2')
        self.assertEqual(newobjlist3,['testme','testme2'])

    def test_get_obj_uid(self):
        name = 'bt'
        otype = 'bt'
        bt = Beamtime('me',123,321,[])
        uid1 = bt._get_obj_uid('bt','bt')
        self.assertNotEqual(uid1,'')
        bt = Beamtime('you',123,321,[])
        uid2 = bt._get_obj_uid('bt','bt')
        self.assertEqual(uid1,uid2)

    def test_make_experiment(self):
        name = 'myexp '
        self.ex = Experiment(name,self.bt)
        self.assertIsInstance(self.ex,Experiment)
        self.assertEqual(self.ex.md['bt_experimenters'],[('van der Banerjee','S0ham',1),('Terban','Max',2)])
        self.assertEqual(self.ex.md['bt_piLast'],'Billinge')
        self.assertEqual(self.ex.md['bt_safN'],234)
        self.assertEqual(self.ex.md['bt_wavelength'],None)
        self.assertEqual(self.ex.md['ex_name'],'myexp')
        uid1 = self.ex.md['ex_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml'])
        self.ex2 = Experiment(' your exp',self.bt)
        self.assertEqual(self.ex2.md['ex_name'],'your exp')
        uid2 = self.ex2.md['ex_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','ex_yourexp.yml'])
        self.ex3 = Experiment(' your exp',self.bt)
        self.assertEqual(self.ex3.md['ex_name'],'your exp')
        uid3 = self.ex3.md['ex_uid']
        self.assertEqual(uid2,uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','ex_yourexp.yml'])

    def test_make_sample(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        self.assertIsInstance(self.sa,Sample)
        self.assertEqual(self.sa.md['bt_experimenters'],[('van der Banerjee','S0ham',1),('Terban','Max',2)])
        self.assertEqual(self.sa.md['bt_piLast'],'Billinge')
        self.assertEqual(self.sa.md['bt_safN'],234)
        self.assertEqual(self.sa.md['bt_wavelength'],None)
        self.assertEqual(self.sa.md['ex_name'],'myexp')
        self.assertEqual(self.sa.md['sa_name'],'my sample')
        uid1 = self.sa.md['sa_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.sa2 = Sample(' your sample',self.ex)
        self.assertEqual(self.sa2.md['sa_name'],'your sample')
        uid2 = self.sa2.md['sa_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml','sa_yoursample.yml'])
        self.sa3 = Sample(' your sample',self.ex)
        self.assertEqual(self.sa3.md['sa_name'],'your sample')
        uid3 = self.sa3.md['sa_uid']
        self.assertEqual(uid2,uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml','sa_yoursample.yml'])

    def test_make_scanPlan(self):
        self.sp = ScanPlan('myScan','ct',{'exposure':1.0})
        self.assertIsInstance(self.sp,ScanPlan)
        self.assertEqual(self.sp.md['sp_params'],{'exposure':1.0,'subs':['livetable']})
        uid1 = self.sp.md['sp_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['sp_myScan.yml'])
        self.sp2 = ScanPlan(' your scan','ct',{'exposure':1.0})
        self.assertEqual(self.sp2.md['sp_name'],'your scan')
        uid2 = self.sp2.md['sp_uid']
        self.assertNotEqual(uid1,uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['sp_myScan.yml','sp_yourscan.yml'])
        self.sp3 = ScanPlan(' your scan','ct',{'exposure':1.0})
        self.assertEqual(self.sp3.md['sp_name'],'your scan')
        uid3 = self.sp3.md['sp_uid']
        self.assertEqual(uid2,uid3)
        # and one that fails the validator
        self.assertRaises(SystemExit,lambda: ScanPlan(' your scan','ct',{'exposur':1.0}))


    def test_hide(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist,[1])
        hidden_list = _get_hidden_list() 
        self.assertEqual(self.hidelist,hidden_list)
  
    def test_unhide(self):
        name = 'my sample '
        self.ex = Experiment('myexp',self.bt)
        self.sa = Sample(name,self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,self.stbt_list+['ex_myexp.yml','sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist,[1])
        hidden_list1 = _get_hidden_list() 
        self.assertEqual(self.hidelist,hidden_list1)
        self.bt.unhide(0)
        hidden_list2 = _get_hidden_list() 
        self.assertEqual(hidden_list1,hidden_list2)
        self.bt.unhide(1)
        hidden_list3 = _get_hidden_list() 
        self.assertEqual(hidden_list3,[])

    def test_set_wavelength(self):
        wavelength = .18448
        self.bt = Beamtime('test',123)
        self.assertEqual(self.bt.md['bt_wavelength'],None)
        self.bt.set_wavelength(wavelength)
        self.assertEqual(self.bt.md['bt_wavelength'],wavelength)
        self.assertEqual(self.bt.name,'bt')
        self.assertEqual(self.bt.md['bt_piLast'],'test')
Beispiel #20
0
    def test_yaml_sync(self):
        """Updating the object immediately, automatically updates the file."""

        # Adding a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        bt['new_field'] = 'test'
        with open(bt.filepath, 'r') as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt['new_field'], 'test')
        self.assertEqual(reloaded_bt, bt)

        # Setting to an existing field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt['field_to_update'] = 'after'
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change['field_to_update'],
                         'before')
        self.assertEqual(reloaded_bt_after_change['field_to_update'],
                         'after')
        self.assertEqual(reloaded_bt_after_change, bt)

        # Updating syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.update(field_to_update='after')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change['field_to_update'],
                         'before')
        self.assertEqual(reloaded_bt_after_change['field_to_update'],
                         'after')
        self.assertEqual(reloaded_bt_after_change, bt)

        # Deleting a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_remove='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        del bt['field_to_remove']
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertTrue('field_to_remove' in reloaded_bt_before_change)
        self.assertTrue('field_to_remove' not in
                        reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # Popping a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_remove='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.pop('field_to_remove')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(self.bt.filepath)
        self.assertTrue('field_to_remove' in reloaded_bt_before_change)
        self.assertTrue('field_to_remove' not in reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # setdefault syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        bt.setdefault('new_field', 'test')
        with open(bt.filepath, 'r') as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt['new_field'], 'test')
        self.assertEqual(reloaded_bt, bt)
Beispiel #21
0
 def test_list_bkg_smoke(self):
     bt = Beamtime('Simon', 123, [], wavelength=0.1828, custom1='A')
     bt.list_bkg()
Beispiel #22
0
    def test_yaml_sync(self):
        """Updating the object immediately, automatically updates the file."""

        # Adding a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        bt['new_field'] = 'test'
        with open(bt.filepath, 'r') as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt['new_field'], 'test')
        self.assertEqual(reloaded_bt, bt)

        # Setting to an existing field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt['field_to_update'] = 'after'
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change['field_to_update'],
                         'before')
        self.assertEqual(reloaded_bt_after_change['field_to_update'],
                         'after')
        self.assertEqual(reloaded_bt_after_change, bt)

        # Updating syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.update(field_to_update='after')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change['field_to_update'],
                         'before')
        self.assertEqual(reloaded_bt_after_change['field_to_update'],
                         'after')
        self.assertEqual(reloaded_bt_after_change, bt)

        # Deleting a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_remove='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        del bt['field_to_remove']
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertTrue('field_to_remove' in reloaded_bt_before_change)
        self.assertTrue('field_to_remove' not in
                        reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # Popping a field syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_remove='before')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.pop('field_to_remove')
        with open(bt.filepath, 'r') as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(self.bt.filepath)
        self.assertTrue('field_to_remove' in reloaded_bt_before_change)
        self.assertTrue('field_to_remove' not in reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # setdefault syncs
        bt = Beamtime('Simon', '123', [], wavelength=0.1828,
                      field_to_update='before')
        bt.setdefault('new_field', 'test')
        with open(bt.filepath, 'r') as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt['new_field'], 'test')
        self.assertEqual(reloaded_bt, bt)
Beispiel #23
0
 def test_list_bkg_smoke(self):
     bt = Beamtime("Simon", 123, [], wavelength=0.1828, custom1="A")
     bt.list_bkg()
Beispiel #24
0
 def test_beamtime_roundtrip(self):
     # This includes checking that a new uid is only generated once
     # and persists thereafter.
     reloaded_bt = Beamtime.from_yaml(self.bt.to_yaml())
     os.remove(self.bt.filepath)
     self.assertEqual(reloaded_bt, self.bt)
Beispiel #25
0
    def test_yaml_sync(self):
        """Updating the object immediately, automatically updates the file."""

        # Adding a field syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_update="before")
        bt["new_field"] = "test"
        with open(bt.filepath, "r") as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt["new_field"], "test")
        self.assertEqual(reloaded_bt, bt)

        # Setting to an existing field syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_update="before")
        with open(bt.filepath, "r") as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt["field_to_update"] = "after"
        with open(bt.filepath, "r") as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change["field_to_update"],
                         "before")
        self.assertEqual(reloaded_bt_after_change["field_to_update"], "after")
        self.assertEqual(reloaded_bt_after_change, bt)

        # Updating syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_update="before")
        with open(bt.filepath, "r") as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.update(field_to_update="after")
        with open(bt.filepath, "r") as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt_before_change["field_to_update"],
                         "before")
        self.assertEqual(reloaded_bt_after_change["field_to_update"], "after")
        self.assertEqual(reloaded_bt_after_change, bt)

        # Deleting a field syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_remove="before")
        with open(bt.filepath, "r") as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        del bt["field_to_remove"]
        with open(bt.filepath, "r") as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertTrue("field_to_remove" in reloaded_bt_before_change)
        self.assertTrue("field_to_remove" not in reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # Popping a field syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_remove="before")
        with open(bt.filepath, "r") as f:
            reloaded_bt_before_change = bt.from_yaml(f)
        bt.pop("field_to_remove")
        with open(bt.filepath, "r") as f:
            reloaded_bt_after_change = bt.from_yaml(f)
        os.remove(self.bt.filepath)
        self.assertTrue("field_to_remove" in reloaded_bt_before_change)
        self.assertTrue("field_to_remove" not in reloaded_bt_after_change)
        self.assertEqual(reloaded_bt_after_change, bt)

        # setdefault syncs
        bt = Beamtime("Simon",
                      "123", [],
                      wavelength=0.1828,
                      field_to_update="before")
        bt.setdefault("new_field", "test")
        with open(bt.filepath, "r") as f:
            reloaded_bt = bt.from_yaml(f)
        os.remove(bt.filepath)
        self.assertEqual(reloaded_bt["new_field"], "test")
        self.assertEqual(reloaded_bt, bt)
Beispiel #26
0
 def test_scanplan_roundtrip(self):
     bt = Beamtime("Simon", "123", [], wavelength=0.1828)
     sp = ScanPlan(self.bt, ct, 1)
     reload_sp = ScanPlan.from_yaml(sp.to_yaml())
     self.assertEqual(reload_sp, sp)
Beispiel #27
0
class NewExptTest(unittest.TestCase):
    def setUp(self):
        self.base_dir = glbl.base
        self.home_dir = glbl.home
        self.config_dir = glbl.xpdconfig
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(self.config_dir):
            shutil.rmtree(self.config_dir)
        os.makedirs(self.config_dir, exist_ok=True)
        self.PI_name = 'Billinge '
        self.saf_num = 234
        self.wavelength = 0.1812
        self.experimenters = [('van der Banerjee', 'S0ham', 1),
                              ('Terban ', ' Max', 2)]
        self.saffile = os.path.join(self.config_dir,
                                    'saf{}.yml'.format(self.saf_num))
        #_make_clean_env()
        loadinfo = {
            'saf number': self.saf_num,
            'PI last name': self.PI_name,
            'experimenter list': self.experimenters
        }
        with open(self.saffile, 'w') as fo:
            yaml.dump(loadinfo, fo)
        self.bt = _start_beamtime(self.saf_num, home_dir=self.home_dir)
        self.stbt_list = [
            'bt_bt.yml', 'ex_l-user.yml', 'sa_l-user.yml', 'sp_ct_0.1.yml',
            'sp_ct_0.5.yml', 'sp_ct_1.yml', 'sp_ct_5.yml', 'sp_ct_10.yml',
            'sp_ct_30.yml'
        ]

    def tearDown(self):
        os.chdir(self.base_dir)
        if os.path.isdir(self.home_dir):
            shutil.rmtree(self.home_dir)
        if os.path.isdir(os.path.join(self.base_dir, 'xpdConfig')):
            shutil.rmtree(os.path.join(self.base_dir, 'xpdConfig'))

    def test_clean_name(self):
        # make sure yaml dir and bt object exists
        name = ' my test experiment '
        cleaned = _clean_name(name)
        self.assertEqual(cleaned, 'mytestexperiment')
        name = ' my way too long experiment name from hell. Dont let users do this already! '
        self.assertRaises(SystemExit, lambda: _clean_name(name))
        # what if user gives something that is not a string?
        name = []
        self.assertRaises(SystemExit, lambda: _clean_name(name))

    @unittest.expectedFailure
    def test_yaml_path(self):
        self.fail('need a test for _yaml_path')

    @unittest.expectedFailure
    def test_loadyamls(self):
        self.fail('need a test for loadyamls')

    def test_yamify(self):
        xpdobj = XPD()
        xpdobj.name = ' test'
        xpdobj.type = 'b t'
        yaml_dir = glbl.yaml_dir
        objlist = []
        lname = os.path.join(yaml_dir, '_acqobj_list.yml')
        #initialize the objlist yaml file if it doesn't exist
        if not os.path.isfile(lname):
            fo = open(lname, 'w')
            yaml.dump(objlist, fo)
        testfname = os.path.join(yaml_dir, 'bt_test.yml')
        probe = xpdobj._yamify()
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist, self.stbt_list + ['bt_test.yml'])
        xpdobj2 = XPD()
        xpdobj2.name = ' test2'
        xpdobj2.type = 'b t'
        testfname2 = os.path.join(yaml_dir, 'bt_test2.yml')
        probe2 = xpdobj2._yamify()
        newobjlist2 = _get_yaml_list()
        self.assertEqual(newobjlist2,
                         self.stbt_list + ['bt_test.yml', 'bt_test2.yml'])
        self.assertEqual(probe, testfname)
        self.assertTrue(os.path.isfile(probe))
        # try adding another item that is already there
        probe3 = xpdobj2._yamify()
        newobjlist3 = _get_yaml_list()
        self.assertEqual(newobjlist3,
                         self.stbt_list + ['bt_test.yml', 'bt_test2.yml'])

#        olist = xpdobj.loadyamls()
#        self.assertEqual(olist[0].name,'bt')
#        self.assertEqual(olist[0].type,'bt')

    def test_update_objlist(self):
        objlist = []
        newobjlist = _update_objlist(objlist, 'testme')
        self.assertEqual(newobjlist, ['testme'])
        newobjlist2 = _update_objlist(newobjlist, 'testme2')
        self.assertEqual(newobjlist2, ['testme', 'testme2'])
        newobjlist3 = _update_objlist(newobjlist2, 'testme2')
        self.assertEqual(newobjlist3, ['testme', 'testme2'])

    def test_get_obj_uid(self):
        name = 'bt'
        otype = 'bt'
        bt = Beamtime('me', 123, 321, [])
        uid1 = bt._get_obj_uid('bt', 'bt')
        self.assertNotEqual(uid1, '')
        bt = Beamtime('you', 123, 321, [])
        uid2 = bt._get_obj_uid('bt', 'bt')
        self.assertEqual(uid1, uid2)

    def test_make_experiment(self):
        name = 'myexp '
        self.ex = Experiment(name, self.bt)
        self.assertIsInstance(self.ex, Experiment)
        self.assertEqual(self.ex.md['bt_experimenters'],
                         [('van der Banerjee', 'S0ham', 1),
                          ('Terban', 'Max', 2)])
        self.assertEqual(self.ex.md['bt_piLast'], 'Billinge')
        self.assertEqual(self.ex.md['bt_safN'], 234)
        self.assertEqual(self.ex.md['bt_wavelength'], None)
        self.assertEqual(self.ex.md['ex_name'], 'myexp')
        uid1 = self.ex.md['ex_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist, self.stbt_list + ['ex_myexp.yml'])
        self.ex2 = Experiment(' your exp', self.bt)
        self.assertEqual(self.ex2.md['ex_name'], 'your exp')
        uid2 = self.ex2.md['ex_uid']
        self.assertNotEqual(uid1, uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['ex_myexp.yml', 'ex_yourexp.yml'])
        self.ex3 = Experiment(' your exp', self.bt)
        self.assertEqual(self.ex3.md['ex_name'], 'your exp')
        uid3 = self.ex3.md['ex_uid']
        self.assertEqual(uid2, uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['ex_myexp.yml', 'ex_yourexp.yml'])

    def test_make_sample(self):
        name = 'my sample '
        self.ex = Experiment('myexp', self.bt)
        self.sa = Sample(name, self.ex)
        self.assertIsInstance(self.sa, Sample)
        self.assertEqual(self.sa.md['bt_experimenters'],
                         [('van der Banerjee', 'S0ham', 1),
                          ('Terban', 'Max', 2)])
        self.assertEqual(self.sa.md['bt_piLast'], 'Billinge')
        self.assertEqual(self.sa.md['bt_safN'], 234)
        self.assertEqual(self.sa.md['bt_wavelength'], None)
        self.assertEqual(self.sa.md['ex_name'], 'myexp')
        self.assertEqual(self.sa.md['sa_name'], 'my sample')
        uid1 = self.sa.md['sa_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['ex_myexp.yml', 'sa_mysample.yml'])
        self.sa2 = Sample(' your sample', self.ex)
        self.assertEqual(self.sa2.md['sa_name'], 'your sample')
        uid2 = self.sa2.md['sa_uid']
        self.assertNotEqual(uid1, uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(
            newobjlist, self.stbt_list +
            ['ex_myexp.yml', 'sa_mysample.yml', 'sa_yoursample.yml'])
        self.sa3 = Sample(' your sample', self.ex)
        self.assertEqual(self.sa3.md['sa_name'], 'your sample')
        uid3 = self.sa3.md['sa_uid']
        self.assertEqual(uid2, uid3)
        newobjlist = _get_yaml_list()
        self.assertEqual(
            newobjlist, self.stbt_list +
            ['ex_myexp.yml', 'sa_mysample.yml', 'sa_yoursample.yml'])

    def test_make_scanPlan(self):
        self.sp = ScanPlan('ct', {'exposure': 0.7})
        self.assertIsInstance(self.sp, ScanPlan)
        self.assertEqual(self.sp.md['sp_params'], {'exposure': 0.7})
        uid1 = self.sp.md['sp_uid']
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist, self.stbt_list + ['sp_ct_0.7.yml'])
        self.sp2 = ScanPlan('ct', {'exposure': 1.5})
        self.assertEqual(self.sp2.md['sp_name'], 'ct_1.5')
        uid2 = self.sp2.md['sp_uid']
        self.assertNotEqual(uid1, uid2)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['sp_ct_0.7.yml', 'sp_ct_1.5.yml'])
        self.sp3 = ScanPlan('ct', {'exposure': 1.5})
        self.assertEqual(self.sp3.md['sp_name'], 'ct_1.5')
        uid3 = self.sp3.md['sp_uid']
        self.assertEqual(uid2, uid3)
        # and one that fails the validator
        self.assertRaises(SystemExit, lambda: ScanPlan('ct', {'exposur': 1.0}))

    def test_hide(self):
        name = 'my sample '
        self.ex = Experiment('myexp', self.bt)
        self.sa = Sample(name, self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['ex_myexp.yml', 'sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist, [1])
        hidden_list = _get_hidden_list()
        self.assertEqual(self.hidelist, hidden_list)

    def test_unhide(self):
        name = 'my sample '
        self.ex = Experiment('myexp', self.bt)
        self.sa = Sample(name, self.ex)
        newobjlist = _get_yaml_list()
        self.assertEqual(newobjlist,
                         self.stbt_list + ['ex_myexp.yml', 'sa_mysample.yml'])
        self.hidelist = self.bt.hide(1)
        self.assertEqual(self.hidelist, [1])
        hidden_list1 = _get_hidden_list()
        self.assertEqual(self.hidelist, hidden_list1)
        self.bt.unhide(0)
        hidden_list2 = _get_hidden_list()
        self.assertEqual(hidden_list1, hidden_list2)
        self.bt.unhide(1)
        hidden_list3 = _get_hidden_list()
        self.assertEqual(hidden_list3, [])

    def test_set_wavelength(self):
        wavelength = .18448
        self.bt = Beamtime('test', 123)
        self.assertEqual(self.bt.md['bt_wavelength'], None)
        self.bt.set_wavelength(wavelength)
        self.assertEqual(self.bt.md['bt_wavelength'], wavelength)
        self.assertEqual(self.bt.name, 'bt')
        self.assertEqual(self.bt.md['bt_piLast'], 'test')

    def test_Scan_validator(self):
        #########################################################
        # Note: bt.list() so far is populated with l-user list
        #       bt.get(2) -> sa,'l-user' ; bt.get(5) -> sp, 'ct1s'
        #       bt.list() goes to 8
        ##########################################################
        # incorrect assignments -> str
        self.assertRaises(SystemExit,
                          lambda: Scan._object_parser(Scan, 'blahblah', 'sa'))
        self.assertRaises(SystemExit,
                          lambda: Scan._object_parser(Scan, 'ct157s', 'sp'))
        # incorrect assignments -> ind
        self.assertRaises(SystemExit,
                          lambda: Scan._object_parser(Scan, 100, 'sp'))
        self.assertRaises(SystemExit,
                          lambda: Scan._object_parser(Scan, 250, 'sa'))
        # incorrect object type from 3 kind of assignments
        self.assertRaises(TypeError, lambda: Scan(self.bt.get(1), self.bt.get(
            5)))  # give Beamtime but not Sample
        self.assertRaises(
            TypeError,
            lambda: Scan(1, 'ct10s'))  # give Beamtime but not Sample
        self.assertRaises(TypeError, lambda: Scan(8, 5))  # give two ScanPlan

    def test_auto_naming_ScanPlan(self):
        # wrong ScanPlan type
        self.assertRaises(SystemExit, lambda: ScanPlan('MRI_5_300_200_5'))
        # wrong positional arguments
        ''' doc string from ScanPlan
        expected format for each type is following:
        1) 'ct_10' means Count scan with 10s exposure time in total
        2) 'Tramp_10_300_200_5' means temperature ramp from 300k to 200k with 5k step and 10s exposure time each
        3) 'tseries_10_60_5' means time series scan of 10s exposure time each time 
            and run for 5 times with 60s delay between them.
        '''
        self.assertRaises(
            SystemExit, lambda: ScanPlan('ct_5_25575_32767'))  # extra argument
        self.assertRaises(
            SystemExit,
            lambda: ScanPlan('Tramp_5_300_200'))  # incomplete arguments
        self.assertRaises(
            SystemExit,
            lambda: ScanPlan('Tramp_5_300_200_5_1111'))  # extra argument
        self.assertRaises(
            SystemExit,
            lambda: ScanPlan('tseries_5_60'))  # incomplete arguments
        self.assertRaises(
            SystemExit,
            lambda: ScanPlan('tseries_5_60_10_1111'))  # extra argument
        # additional unit
        self.assertRaises(SystemExit, lambda: ScanPlan('ct_5s'))
        self.assertRaises(SystemExit, lambda: ScanPlan('Tramp_5s_300k_200_5'))
        # test on optional argument
        sp = ScanPlan('ct_5', shutter=False)
        self.assertEqual(sp.name, 'ct_5_nS')
        sp = ScanPlan('ct_5', shutter=True)
        self.assertEqual(sp.name, 'ct_5')

    def test_ScanPlan_longform(self):
        # test creation
        self.assertRaises(TypeError, lambda: ScanPlan())
        # test sp_name
        self.sp1 = ScanPlan('ct', {'exposure': 0.5})
        self.assertEqual(self.sp1.name, 'ct_0.5')
        self.sp2 = ScanPlan('tseries', {
            'exposure': 0.5,
            'num': 5,
            'delay': 2.5
        })
        self.assertEqual(self.sp2.name, 'tseries_0.5_2.5_5')
        self.sp3 = ScanPlan('Tramp', {
            'exposure': 0.8,
            'endingT': 200,
            'startingT': 300,
            'Tstep': 2
        })
        self.assertEqual(self.sp3.name, 'Tramp_0.8_300_200_2')
        # test sp_params values
        self.assertEqual(0.5, self.sp1.sp_params['exposure'])

        self.assertEqual(0.5, self.sp2.sp_params['exposure'])
        self.assertEqual(5, self.sp2.sp_params['num'])
        self.assertEqual(2.5, self.sp2.sp_params['delay'])

        self.assertEqual(0.8, self.sp3.sp_params['exposure'])
        self.assertEqual(200, self.sp3.sp_params['endingT'])
        self.assertEqual(300, self.sp3.sp_params['startingT'])
        self.assertEqual(2, self.sp3.sp_params['Tstep'])