cubicweb/misc/cwfs/cwfs_test.py
changeset 11057 0b59724cb3f2
parent 10614 57dfde80df11
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
       
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """
       
    19 
       
    20 """
       
    21 from logilab.common.testlib import TestCase, unittest_main
       
    22 
       
    23 import cubicwebfs
       
    24 import sre
       
    25 
       
    26 def spec_parser(filename) :
       
    27     """
       
    28     extract tests from specification
       
    29     """
       
    30     sections = []
       
    31     buffer = ""
       
    32     in_section = False
       
    33     for line in open(filename) :
       
    34         if line.startswith('Test::'):
       
    35             in_section = True
       
    36             buffer = ""
       
    37         elif in_section :
       
    38             if line.startswith("  ") or not line.strip() :
       
    39                 buffer += line.lstrip()
       
    40             else :
       
    41                 sections.append(buffer)
       
    42                 in_section = False
       
    43     tests = []
       
    44     for section in sections :
       
    45         subsections = [t for t in section.strip().split('$ ls') if t]
       
    46         for subsection in subsections :
       
    47             path, results = subsection.splitlines()[0], subsection.splitlines()[1:]
       
    48             path = path.strip()
       
    49             items = set([i for i in sre.split('[\t\n]', '\n'.join(results)) if i])
       
    50             tests.append((path, items))
       
    51     return tests
       
    52 
       
    53 tests = spec_parser("cubicwebfs-spec.txt")
       
    54 
       
    55 class monTC(TestCase) :
       
    56     pass
       
    57 
       
    58 for index, (path, results) in enumerate(tests) :
       
    59     def f(self, p=path, r=results) :
       
    60         res = set(cubicwebfs.ls(p))
       
    61         self.assertEqual(r, res) #, 'en trop %s\nmanque %s' % (r-results,results-r))
       
    62     f.__doc__ = "%s %s"%(index,path)
       
    63     setattr(monTC,'test_%s'%index,f)
       
    64 
       
    65 if __name__ == '__main__':
       
    66     unittest_main()