def test_central_directory_Creation(self): tmp_dir = tempfile.mkdtemp(__name__) config._config[config.BASE_DIR_LOCATION] = tmp_dir config._config[ config. DIRECTORY_STRUCTURE_TYPE] = config.DIRECTORY_STRUCTURE.CENTRAL testUser = DummyUser(random_home=False, **Test.DUMMY_USER) dir1 = testUser.getUserBaseDir() self.assertEquals( dir1, os.path.join(config.get(config.BASE_DIR_LOCATION), config.get(config.BASE_DIR), str(testUser.getName()))) dir2 = testUser.getUserOutputDir('sometool') self.assertEquals( dir2, os.path.join(config.get(config.BASE_DIR_LOCATION), config.get(config.BASE_DIR), str(testUser.getName()), User.OUTPUT_DIR, 'sometool')) print dir2 config.reloadConfiguration() if os.path.isdir(tmp_dir) and tmp_dir.startswith( tempfile.gettempdir()): #make sure the home is a temporary one!!! print "Cleaning up %s" % tmp_dir shutil.rmtree(tmp_dir)
def test_reload(self): """Test we can reload the configuration""" config._config[config.BASE_DIR_LOCATION] = 'TEST' c1 = config.get(config.BASE_DIR_LOCATION) self.assertEquals(c1, 'TEST') config.reloadConfiguration() c2 = config.get(config.BASE_DIR_LOCATION) self.assertNotEquals(c1, c2)
def setUp(self): uid = os.getuid() self.udata = pwd.getpwuid(uid) self.user = DummyUser(random_home=True, **{'pw_name': self.udata.pw_name}) os.environ['EVALUATION_SYSTEM_CONFIG_FILE'] = os.path.dirname( __file__) + '/test.conf' config.reloadConfiguration() pm.reloadPlugins() self.cmd = Command()
def setUp(self): # this gets overwritten by the nosetest framework (it reloads all modules again) # we have to reset it every time. os.environ['EVALUATION_SYSTEM_CONFIG_FILE'] = os.path.dirname( __file__) + '/test.conf' config.reloadConfiguration() self.user = DummyUser(random_home=True, pw_name='test_user') pm.reloadPlugins(self.user.getName()) self.user_django, created = User.objects.get_or_create( username=self.user.getName())
def setUp(self): os.environ['EVALUATION_SYSTEM_CONFIG_FILE'] = os.path.dirname( __file__) + '/test.conf' config.reloadConfiguration() self.solr_port = config.get('solr.port') self.solr_host = config.get('solr.host') # test instances, check they are as expected self.all_files = SolrCore(core='files', host=self.solr_host, port=self.solr_port) self.latest = SolrCore(core='latest', host=self.solr_host, port=self.solr_port) self.assertEquals(self.all_files.status()['index']['numDocs'], 0) self.assertEquals(self.latest.status()['index']['numDocs'], 0)
def test_config_file(self): """If a config file is provided it should be read""" import tempfile fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write('[evaluation_system]\n%s=nowhere\n' % config.BASE_DIR) self.assertEquals(config.get(config.BASE_DIR), 'evaluation_system') os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name config.reloadConfiguration() self.assertEquals(config.get(config.BASE_DIR), 'nowhere') os.unlink(name) # check wrong section fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write('[wrong_section]\n%s=nowhere\n' % config.BASE_DIR) os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name self.failUnlessRaises(ConfigurationException, reloadConfiguration) os.unlink(name) # check directory structure value fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write('[evaluation_system]\n%s=wrong_value\n' % config.DIRECTORY_STRUCTURE_TYPE) os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name self.failUnlessRaises(ConfigurationException, reloadConfiguration) os.unlink(name) # check $EVALUATION_SYSTEM_HOME get's resolved properly fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write('[evaluation_system]\n%s=$EVALUATION_SYSTEM_HOME\n' % config.BASE_DIR) self.assertEquals(config.get(config.BASE_DIR), 'evaluation_system') os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name config.reloadConfiguration() self.assertEquals(config.get(config.BASE_DIR), '/'.join(__file__.split('/')[:-4])) os.unlink(name)
def setUp(self): os.environ['EVALUATION_SYSTEM_CONFIG_FILE'] = os.path.dirname( __file__) + '/test.conf' config.reloadConfiguration() self.solr_port = config.get('solr.port') self.solr_host = config.get('solr.host') # test instances, check they are as expected self.all_files = SolrCore(core='files', host=self.solr_host, port=self.solr_port) self.latest = SolrCore(core='latest', host=self.solr_host, port=self.solr_port) self.assertEquals(self.all_files.status()['index']['numDocs'], 0) self.assertEquals(self.latest.status()['index']['numDocs'], 0) # add some files to the cores supermakedirs('/tmp/some_temp_solr_core/', 0777) self.tmpdir = '/tmp/some_temp_solr_core' self.orig_dir = DRSFile.DRS_STRUCTURE[CMIP5]['root_dir'] DRSFile.DRS_STRUCTURE[CMIP5]['root_dir'] = self.tmpdir self.files = [ 'cmip5/output1/MOHC/HadCM3/historical/mon/aerosol/aero/r2i1p1/v20110728/wetso2/wetso2_aero_HadCM3_historical_r2i1p1_190912-193411.nc', 'cmip5/output1/MOHC/HadCM3/decadal2008/mon/atmos/Amon/r9i3p1/v20120523/tauu/tauu_Amon_HadCM3_decadal2008_r9i3p1_200811-201812.nc', 'cmip5/output1/MOHC/HadCM3/decadal2009/mon/atmos/Amon/r7i2p1/v20110719/ua/ua_Amon_HadCM3_decadal2009_r7i2p1_200911-201912.nc', 'cmip5/output1/MOHC/HadCM3/decadal2009/mon/atmos/Amon/r7i2p1/v20110819/ua/ua_Amon_HadCM3_decadal2009_r7i2p1_200911-201912.nc', 'cmip5/output1/MOHC/HadCM3/decadal2009/mon/atmos/Amon/r7i2p1/v20110419/ua/ua_Amon_HadCM3_decadal2009_r7i2p1_200911-201912.nc' ] for f in self.files: abs_path = os.path.abspath(os.path.join(self.tmpdir, f)) try: os.makedirs(os.path.dirname(abs_path)) except: # pragma nocover pass with open(abs_path, 'w') as f_out: f_out.write(' ') dump_file = self.tmpdir + '/dump1.csv' # add the files to solr SolrCore.dump_fs_to_file(self.tmpdir + '/cmip5', dump_file) SolrCore.load_fs_from_file(dump_file, abort_on_errors=True, core_all_files=self.all_files, core_latest=self.latest) self.fn = os.path.join(self.tmpdir, self.files[0]) self.drs = DRSFile.from_path(self.fn)
def test_plugin_conf(self): import tempfile fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write(""" [evaluation_system] base_dir=~ [plugin:pca] plugin_path=$EVALUATION_SYSTEM_HOME/tool/pca python_path=$EVALUATION_SYSTEM_HOME/tool/pca/integration module=pca.api [plugin:climval] plugin_path=$EVALUATION_SYSTEM_HOME/tool/climval python_path=$EVALUATION_SYSTEM_HOME/tool/climval/src module=climval.tool """) os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name config.reloadConfiguration() plugins_dict = config.get(config.PLUGINS) self.assertEquals(set(plugins_dict), set(['pca', 'climval'])) es_home = '/'.join(__file__.split('/')[:-4]) self.assertEquals(config.get_plugin('pca', config.PLUGIN_PATH), es_home + '/tool/pca') self.assertEquals(config.get_plugin('pca', config.PLUGIN_PYTHON_PATH), es_home + '/tool/pca/integration') self.assertEquals(config.get_plugin('pca', config.PLUGIN_MODULE), 'pca.api') self.assertEquals( config.get_plugin('pca', 'not_existing', 'some_default'), 'some_default') self.assertEquals(config.get_plugin('climval', config.PLUGIN_MODULE), 'climval.tool') os.unlink(name)
def test_get_section(self): import tempfile fd, name = tempfile.mkstemp(__name__, text=True) with os.fdopen(fd, 'w') as f: f.write(""" [evaluation_system] base_dir=/home/lala [some_other_section] param=value some=val """) os.environ[config._DEFAULT_ENV_CONFIG_FILE] = name config.reloadConfiguration() eval = config.get_section('evaluation_system') self.assertEqual(eval, {'base_dir': '/home/lala'}) other = config.get_section('some_other_section') self.assertEqual(other, {'param': 'value', 'some': 'val'}) # no valid section # config.get_section('safasfas') self.assertRaises(config.NoSectionError, config.get_section, 'novalid_section')
def setUp(self): os.environ['EVALUATION_SYSTEM_CONFIG_FILE'] = os.path.dirname( __file__) + '/test.conf' config.reloadConfiguration() pm.reloadPlugins() self.cmd = Command()
def tearDown(self): if config._DEFAULT_ENV_CONFIG_FILE in os.environ: del os.environ[config._DEFAULT_ENV_CONFIG_FILE] config.reloadConfiguration()