[view, plot] deprecate flot and encourage usage of the jqplot cube (closes #1625218)
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""cubicweb.cwconfig unit tests"""importsysimportosimporttempfilefromos.pathimportdirname,join,abspathfromlogilab.common.modutilsimportcleanup_sys_modulesfromlogilab.common.testlibimport(TestCase,unittest_main,with_tempdir)fromlogilab.common.changelogimportVersionfromcubicweb.devtoolsimportApptestConfigurationfromcubicweb.cwconfigimport_find_prefixdefunabsolutize(path):parts=path.split(os.sep)fori,partinreversed(tuple(enumerate(parts))):ifpart.startswith('cubicweb')orpart=='cubes':return'/'.join(parts[i+1:])raiseException('duh? %s'%path)CUSTOM_CUBES_DIR=abspath(join(dirname(__file__),'data','cubes'))classCubicWebConfigurationTC(TestCase):defsetUp(self):cleanup_sys_modules([CUSTOM_CUBES_DIR,ApptestConfiguration.CUBES_DIR])self.config=ApptestConfiguration('data',apphome=self.datadir)self.config._cubes=('email','file')deftearDown(self):ApptestConfiguration.CUBES_PATH=[]deftest_reorder_cubes(self):self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR]self.config.adjust_sys_path()# forge depends on email and file and comment# email depends on fileself.assertEqual(self.config.reorder_cubes(['file','email','forge']),('forge','email','file'))self.assertEqual(self.config.reorder_cubes(['email','file','forge']),('forge','email','file'))self.assertEqual(self.config.reorder_cubes(['email','forge','file']),('forge','email','file'))self.assertEqual(self.config.reorder_cubes(['file','forge','email']),('forge','email','file'))self.assertEqual(self.config.reorder_cubes(['forge','file','email']),('forge','email','file'))self.assertEqual(self.config.reorder_cubes(('forge','email','file')),('forge','email','file'))deftest_reorder_cubes_recommends(self):self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR]self.config.adjust_sys_path()fromcubes.commentimport__pkginfo__ascomment_pkginfocomment_pkginfo.__recommends_cubes__={'file':None}try:# email recommends comment# comment recommends fileself.assertEqual(self.config.reorder_cubes(('forge','email','file','comment')),('forge','email','comment','file'))self.assertEqual(self.config.reorder_cubes(('forge','email','comment','file')),('forge','email','comment','file'))self.assertEqual(self.config.reorder_cubes(('forge','comment','email','file')),('forge','email','comment','file'))self.assertEqual(self.config.reorder_cubes(('comment','forge','email','file')),('forge','email','comment','file'))finally:comment_pkginfo.__recommends_cubes__={}# def test_vc_config(self):# vcconf = self.config.vc_config()# self.assertIsInstance(vcconf['EEMAIL'], Version)# self.assertEqual(vcconf['EEMAIL'], (0, 3, 1))# self.assertEqual(vcconf['CW'], (2, 31, 2))# self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION')# self.assertRaises(KeyError, vcconf.__getitem__, 'CRM')deftest_expand_cubes(self):self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR]self.config.adjust_sys_path()self.assertEqual(self.config.expand_cubes(('email','comment')),['email','comment','file'])deftest_vregistry_path(self):self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR]self.config.adjust_sys_path()self.assertEqual([unabsolutize(p)forpinself.config.vregistry_path()],['entities','web/views','sobjects','hooks','file/entities','file/views.py','file/hooks','email/entities.py','email/views','email/hooks.py','test/data/entities.py','test/data/views.py'])deftest_cubes_path(self):# make sure we don't import the email cube, but the stdlib email packageimportemailself.assertNotEqual(dirname(email.__file__),self.config.CUBES_DIR)self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR]self.assertEqual(self.config.cubes_search_path(),[CUSTOM_CUBES_DIR,self.config.CUBES_DIR])self.config.__class__.CUBES_PATH=[CUSTOM_CUBES_DIR,self.config.CUBES_DIR,'unexistant']# filter out unexistant and duplicatesself.assertEqual(self.config.cubes_search_path(),[CUSTOM_CUBES_DIR,self.config.CUBES_DIR])self.assertTrue('mycube'inself.config.available_cubes())# test cubes python pathself.config.adjust_sys_path()importcubesself.assertEqual(cubes.__path__,self.config.cubes_search_path())# this import should succeed once path is adjustedfromcubesimportmycubeself.assertEqual(mycube.__path__,[join(CUSTOM_CUBES_DIR,'mycube')])# file cube should be overriden by the one found in data/cubessys.modules.pop('cubes.file',None)delcubes.filefromcubesimportfileself.assertEqual(file.__path__,[join(CUSTOM_CUBES_DIR,'file')])classFindPrefixTC(TestCase):defmake_dirs(self,*args):path=join(tempfile.tempdir,*args)ifnotos.path.exists(path):os.makedirs(path)returnpathdefmake_file(self,*args):self.make_dirs(*args[:-1])file_path=join(tempfile.tempdir,*args)file_obj=open(file_path,'w')file_obj.write('""" None """')file_obj.close()returnfile_path@with_tempdirdeftest_samedir(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')self.assertEqual(_find_prefix(prefix),prefix)@with_tempdirdeftest_samedir_filepath(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')file_path=self.make_file('bob.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_dir_inside_prefix(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')dir_path=self.make_dirs('bob')self.assertEqual(_find_prefix(dir_path),prefix)@with_tempdirdeftest_file_in_dir_inside_prefix(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')file_path=self.make_file('bob','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_file_in_deeper_dir_inside_prefix(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')file_path=self.make_file('bob','pyves','alain','adim','syt','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_multiple_candidate_prefix(self):self.make_dirs('share','cubicweb')prefix=self.make_dirs('bob')self.make_dirs('bob','share','cubicweb')file_path=self.make_file('bob','pyves','alain','adim','syt','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_sister_candidate_prefix(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')self.make_dirs('bob','share','cubicweb')file_path=self.make_file('bell','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_multiple_parent_candidate_prefix(self):self.make_dirs('share','cubicweb')prefix=self.make_dirs('share','cubicweb','bob')self.make_dirs('share','cubicweb','bob','share','cubicweb')file_path=self.make_file('share','cubicweb','bob','pyves','alain','adim','syt','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_upper_candidate_prefix(self):prefix=tempfile.tempdirself.make_dirs('share','cubicweb')self.make_dirs('bell','bob','share','cubicweb')file_path=self.make_file('bell','toto.py')self.assertEqual(_find_prefix(file_path),prefix)@with_tempdirdeftest_no_prefix(self):prefix=tempfile.tempdirself.assertEqual(_find_prefix(prefix),sys.prefix)if__name__=='__main__':unittest_main()