[editcontroller] req=self._cw makes things easier to read
# 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/>.""""""fromlogilab.common.testlibimportTestCase,unittest_mainimportcubicwebfsimportsredefspec_parser(filename):""" extract tests from specification """sections=[]buffer=""in_section=Falseforlineinfile(filename):ifline.startswith('Test::'):in_section=Truebuffer=""elifin_section:ifline.startswith(" ")ornotline.strip():buffer+=line.lstrip()else:sections.append(buffer)in_section=Falsetests=[]forsectioninsections:subsections=[tfortinsection.strip().split('$ ls')ift]forsubsectioninsubsections:path,results=subsection.splitlines()[0],subsection.splitlines()[1:]path=path.strip()items=set([iforiinsre.split('[\t\n]','\n'.join(results))ifi])tests.append((path,items))returnteststests=spec_parser("cubicwebfs-spec.txt")classmonTC(TestCase):passforindex,(path,results)inenumerate(tests):deff(self,p=path,r=results):res=set(cubicwebfs.ls(p))self.assertEqual(r,res)#, 'en trop %s\nmanque %s' % (r-results,results-r))f.__doc__="%s%s"%(index,path)setattr(monTC,'test_%s'%index,f)if__name__=='__main__':unittest_main()