def test_new_default_param(self): # in this case an updated version of the codes brings in a new parameter default = {'A': 'tata2', 'O': 'toto2', 'I': 'titi2', 'E': 'tete2', 'num': 15, 'liste': [1, 'turlu']} expected_result = {'A': 'tata', 'O': 'toto', 'I': 'titi', 'num': 15, 'liste': [1, 'turlu'], 'apath': str(Path('/gna/gna/gna')), 'E': 'tete2', } par2 = params.read('toto', default=default) self.assertEqual(par2, params.from_dict(expected_result)) # on the next path the parameter has been added to the param file par2 = params.read('toto', default=default) self.assertEqual(par2, params.from_dict(expected_result)) # check that it doesn't break if a named tuple is given instead of a dict par3 = params.read('toto', default=par2) self.assertEqual(par2, par3) # check that a non-existing parfile returns None pstring = str(uuid.uuid4()) par = params.read(pstring) self.assertIsNone(par) # check that a non-existing parfile with default returns default par = params.read(pstring, default=default) self.assertEqual(par, params.from_dict(default)) # even if this default is a Params named tuple par = params.read(pstring, default=par) self.assertEqual(par, params.from_dict(default))
def setup(): par_default = default() par_current = iopar.read(_PAR_ID_STR, par_default) par = iopar.as_dict(par_default) for k in par.keys(): cpar = _get_current_par(k, par_current) if "PWD" not in k: par[k] = input("Param " + k + ", current value is [" + str(cpar) + "]:") or cpar cpar = _get_current_par("ALYX_PWD", par_current) prompt = "Enter the Alyx password for " + par[ "ALYX_LOGIN"] + '(leave empty to keep current):' par["ALYX_PWD"] = getpass(prompt) or cpar cpar = _get_current_par("HTTP_DATA_SERVER_PWD", par_current) prompt = "Enter the FlatIron HTTP password for " + par["HTTP_DATA_SERVER_LOGIN"] +\ '(leave empty to keep current): ' par["HTTP_DATA_SERVER_PWD"] = getpass(prompt) or cpar # default to home dir if empty dir somehow made it here if len(par['CACHE_DIR']) == 0: par['CACHE_DIR'] = str(Path.home() / "Downloads" / "FlatIron") par = iopar.from_dict(par) # create directory if needed if par.CACHE_DIR and not os.path.isdir(par.CACHE_DIR): os.mkdir(par.CACHE_DIR) iopar.write(_PAR_ID_STR, par) print('ONE Parameter file location: ' + iopar.getfile(_PAR_ID_STR))
def test_params(self): # first go to and from dictionary par_dict = self.par_dict par = params.from_dict(par_dict) self.assertEqual(params.as_dict(par), par_dict) # next go to and from dictionary via json par2 = params.read('toto') self.assertEqual(par, par2)
def setUp(self): self.par_dict = {'A': 'tata', 'O': 'toto', 'I': 'titi', 'num': 15, 'liste': [1, 'turlu']} params.write('toto', self.par_dict) params.write('toto', params.from_dict(self.par_dict))
def test_new_default_param(self): # in this case an updated version of the codes brings in a new parameter default = { 'A': 'tata2', 'O': 'toto2', 'I': 'titi2', 'E': 'tete2', 'num': 15, 'liste': [1, 'turlu'] } expected_result = { 'A': 'tata', 'O': 'toto', 'I': 'titi', 'num': 15, 'liste': [1, 'turlu'], 'apath': str(Path('/gna/gna/gna')), 'E': 'tete2', } par2 = params.read('toto', default=default) self.assertCountEqual(par2.as_dict(), expected_result) # on the next path the parameter has been added to the param file par2 = params.read('toto', default=default) self.assertCountEqual(par2.as_dict(), expected_result) # check that it doesn't break if a named tuple is given instead of a dict par3 = params.read('toto', default=par2) self.assertEqual(par2, par3) # check that a non-existing parfile raises error pstring = str(uuid.uuid4()) with self.assertRaises(FileNotFoundError): params.read(pstring) # check that a non-existing parfile with default returns default par = params.read(pstring, default=default) self.assertCountEqual(par, params.from_dict(default)) # even if this default is a Params named tuple par = params.read(pstring, default=par) self.assertEqual(par, params.from_dict(default)) # check default empty dict pstring = 'foobar' filename = Path(params.getfile(pstring)) self.assertFalse(filename.exists()) par = params.read(pstring, default={}) self.assertIsNone(par) self.assertTrue(filename.exists())
def default(): par = { "ALYX_LOGIN": "******", "ALYX_PWD": "TapetesBloc18", "ALYX_URL": "https://test.alyx.internationalbrainlab.org", "CACHE_DIR": str(Path.home() / "Downloads" / "FlatIron"), "HTTP_DATA_SERVER": "https://ibl.flatironinstitute.org", "HTTP_DATA_SERVER_LOGIN": "******", "HTTP_DATA_SERVER_PWD": None, } return iopar.from_dict(par)
def default(): par = {"ALYX_LOGIN": "******", "ALYX_PWD": None, "ALYX_URL": "https://test.alyx.internationalbrainlab.org", "CACHE_DIR": str(PurePath(Path.home(), "Downloads", "FlatIron")), "FTP_DATA_SERVER": "ftp://ibl.flatironinstitute.org", "FTP_DATA_SERVER_LOGIN": "******", "FTP_DATA_SERVER_PWD": None, "HTTP_DATA_SERVER": "http://ibl.flatironinstitute.org", "HTTP_DATA_SERVER_LOGIN": "******", "HTTP_DATA_SERVER_PWD": None, "GLOBUS_CLIENT_ID": None, } return iopar.from_dict(par)
def setup_silent(): par_current = iopar.read(_PAR_ID_STR) par_default = default() if par_current is None: par = par_default else: par = iopar.as_dict(par_default) for k in par.keys(): cpar = _get_current_par(k, par_current) par[k] = cpar par = iopar.from_dict(par) if par.CACHE_DIR: Path(par.CACHE_DIR).mkdir(parents=True, exist_ok=True) iopar.write(_PAR_ID_STR, par)
def test_login_auto(self, mock_params): client_id = 'h3u2i' # Test ValueError thrown with incorrect parameters mock_params.return_value = None # No parameters saved with self.assertRaises(ValueError): globus.login_auto(client_id) mock_params.assert_called_with('globus/default') pars = params.from_dict({'access_token': '7r3hj89', 'expires_at_seconds': '2020-09-10'}) mock_params.return_value = pars # Incomplete parameter object with self.assertRaises(ValueError): globus.login_auto(client_id) # Complete parameter object mock_params.return_value = pars.set('refresh_token', '37yh4') gtc = globus.login_auto(client_id) self.assertIsInstance(gtc, unittest.mock.Mock) mock, _ = self.patcher.get_original() mock.assert_called_once_with(client_id)