示例#1
0
 def test_start_beamtime(self):
     # sanity check. xpdUser directory exists.
     # First make sure the code works right when it doesn't exist.
     self.assertFalse(os.path.isdir(self.home_dir))
     self.assertRaises(RuntimeError,
                       lambda: _start_beamtime(self.PI_name, self.saf_num))
     # now make it the proper thing...xpdUser directory
     os.mkdir(self.home_dir)
     self.assertTrue(os.path.isdir(self.home_dir))
     # but put a file in it
     self.newfile = os.path.join(self.home_dir, 'touched.txt')
     open(self.newfile, 'a').close()
     self.assertTrue(os.path.isfile(self.newfile))
     self.assertRaises(FileExistsError,
                       lambda: _start_beamtime(self.PI_name, self.saf_num))
     os.remove(self.newfile)
     # do the same but with directories
     self.newdir = os.path.join(self.home_dir, 'userJunk')
     os.mkdir(self.newdir)
     self.assertTrue(os.path.isdir(self.newdir))
     self.assertRaises(FileExistsError,
                       lambda: _start_beamtime(self.PI_name, self.saf_num))
     os.removedirs(self.newdir)
     # real doing: 
     os.mkdir(self.home_dir)
     self.assertTrue(os.path.isdir(self.home_dir))
     self.bt = _start_beamtime(self.PI_name, self.saf_num,
                               self.experimenters,
                               wavelength=self.wavelength)
     self.assertIsInstance(self.bt, Beamtime)
     # test normalized md
     self.assertEqual('Billinge', self.bt.get('bt_piLast'))
     self.assertEqual('123', self.bt.get('bt_safN'))
     self.assertEqual(self.experimenters, self.bt.get('bt_experimenters'))
     self.assertEqual(self.wavelength, self.bt.get('bt_wavelength'))
     self.assertEqual(os.getcwd(), self.home_dir)
     # test prepoluate ScanPlan
     self.assertEqual(len(self.bt.scanplans), len(EXPO_LIST))
     for sp, expect_arg in zip(self.bt.scanplans, EXPO_LIST):
         self.assertEqual(sp['sp_args'], (expect_arg,))
     # test if yml files are saved properly
     for expo in EXPO_LIST:
         f_path = os.path.join(glbl.scanplan_dir,
                               'ct_{}.yml'.format(expo))
         self.assertTrue(os.path.isfile(f_path))
     # test if it can be reloaded
     for current_sp in self.bt.scanplans:
         reload_sp = ScanPlan.from_yaml(current_sp.to_yaml())
         self.assertEqual(reload_sp, current_sp)
         self.assertFalse(id(reload_sp) ==  id(current_sp))
示例#2
0
    def test_scanplan_yamlize(self):
        sp = ScanPlan(self.bt, ct, 1)
        # bound arguments
        # expected_bound_args = {'exposure': 1, 'md': None}
        expected_bound_args = {"exposure": 1}  # py3.4 only get args
        self.assertEqual(dict(sp.bound_arguments), expected_bound_args)
        # reload
        reload_dict = yaml.unsafe_load(sp.to_yaml())
        self.assertEqual(len(reload_dict), 2)  # bt and sp
        ## contents of chainmap
        self.assertEqual(reload_dict[0], sp.maps[0])
        self.assertEqual(reload_dict[1], sp.maps[1])

        # equality
        reload_scanplan = ScanPlan.from_yaml(sp.to_yaml())
        other_sp = ScanPlan(self.bt, ct, 5)
        self.assertFalse(sp == other_sp)
        self.assertTrue(sp == reload_scanplan)
示例#3
0
    def test_scanplan_yamlize(self):
        sp = ScanPlan(self.bt, ct, 1)
        # bound arguments
        # expected_bound_args = {'exposure': 1, 'md': None}
        expected_bound_args = {'exposure': 1}  # py3.4 only get args
        self.assertEqual(dict(sp.bound_arguments),
                         expected_bound_args)
        # reload
        reload_dict = yaml.load(sp.to_yaml())
        self.assertEqual(len(reload_dict), 2)  # bt and sp
        ## contents of chainmap
        self.assertEqual(reload_dict[0], sp.maps[0])
        self.assertEqual(reload_dict[1], sp.maps[1])

        # equality
        reload_scanplan = ScanPlan.from_yaml(sp.to_yaml())
        other_sp = ScanPlan(self.bt, ct, 5)
        self.assertFalse(sp == other_sp)
        self.assertTrue(sp == reload_scanplan)
示例#4
0
 def test_start_beamtime(self):
     # sanity check. xpdUser directory exists.
     # First make sure the code works right when it doesn't exist.
     self.assertFalse(os.path.isdir(self.home_dir))
     self.assertRaises(
         RuntimeError, lambda: _start_beamtime(self.PI_name, self.saf_num)
     )
     # now make it the proper thing...xpdUser directory
     os.mkdir(self.home_dir)
     self.assertTrue(os.path.isdir(self.home_dir))
     # but put a file in it
     self.newfile = os.path.join(self.home_dir, "touched.txt")
     open(self.newfile, "a").close()
     self.assertTrue(os.path.isfile(self.newfile))
     self.assertRaises(
         FileExistsError,
         lambda: _start_beamtime(self.PI_name, self.saf_num),
     )
     os.remove(self.newfile)
     # do the same but with directories
     self.newdir = os.path.join(self.home_dir, "userJunk")
     os.mkdir(self.newdir)
     self.assertTrue(os.path.isdir(self.newdir))
     self.assertRaises(
         FileExistsError,
         lambda: _start_beamtime(self.PI_name, self.saf_num),
     )
     os.removedirs(self.newdir)
     # real doing:
     os.mkdir(self.home_dir)
     self.assertTrue(os.path.isdir(self.home_dir))
     # copying example longterm config file
     pytest_dir = rs_fn("xpdacq", "tests/")
     config = "XPD_beamline_config.yml"
     configsrc = os.path.join(pytest_dir, config)
     shutil.copyfile(configsrc, os.path.join(self.config_dir, config))
     self.bt = _start_beamtime(
         self.PI_name,
         self.saf_num,
         self.experimenters,
         wavelength=self.wavelength,
         test=True,
     )
     self.assertIsInstance(self.bt, Beamtime)
     # test normalized md
     self.assertEqual("Billinge", self.bt.get("bt_piLast"))
     self.assertEqual("123", self.bt.get("bt_safN"))
     self.assertEqual(self.experimenters, self.bt.get("bt_experimenters"))
     self.assertEqual(self.wavelength, self.bt.get("bt_wavelength"))
     self.assertEqual(os.getcwd(), self.home_dir)
     # test prepoluate ScanPlan
     self.assertEqual(len(self.bt.scanplans), len(EXPO_LIST))
     for sp, expect_arg in zip(list(self.bt.scanplans.values()), EXPO_LIST):
         self.assertEqual(sp["sp_args"], (expect_arg,))
     # test if yml files are saved properly
     for expo in EXPO_LIST:
         f_path = os.path.join(
             glbl_dict["scanplan_dir"], "ct_{}.yml".format(expo)
         )
         self.assertTrue(os.path.isfile(f_path))
     # test if it can be reloaded
     for current_sp in self.bt.scanplans.values():
         reload_sp = ScanPlan.from_yaml(current_sp.to_yaml())
         self.assertEqual(reload_sp, current_sp)
         self.assertFalse(id(reload_sp) == id(current_sp))
示例#5
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)
示例#6
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)
示例#7
0
 def test_scanplan_roundtrip(self):
     sp = ScanPlan(self.bt, ct, 1)
     reload_sp = ScanPlan.from_yaml(sp.to_yaml())
     self.assertEqual(reload_sp, sp)