skeleton/test/pytestconf.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
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
       
    17 # along with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """
       
    19 
       
    20 """
       
    21 import os
       
    22 import sys
       
    23 
       
    24 from logilab.common.pytest import PyTester
       
    25 
       
    26 
       
    27 def getlogin():
       
    28     """avoid usinng os.getlogin() because of strange tty / stdin problems
       
    29     (man 3 getlogin)
       
    30     Another solution would be to use $LOGNAME, $USER or $USERNAME
       
    31     """
       
    32     if sys.platform == 'win32':
       
    33         return os.environ.get('USERNAME') or 'cubicweb'
       
    34     import pwd
       
    35     return pwd.getpwuid(os.getuid())[0]
       
    36 
       
    37 
       
    38 def update_parser(parser):
       
    39     login = getlogin()
       
    40     parser.add_option('-r', '--rebuild-database', dest='rebuild_db',
       
    41                       default=False, action="store_true",
       
    42                       help="remove tmpdb and rebuilds the test database")
       
    43     parser.add_option('-u', '--dbuser', dest='dbuser', action='store',
       
    44                       default=login, help="database user")
       
    45     parser.add_option('-w', '--dbpassword', dest='dbpassword', action='store',
       
    46                       default=login, help="database user's password")
       
    47     parser.add_option('-n', '--dbname', dest='dbname', action='store',
       
    48                       default=None, help="database name")
       
    49     parser.add_option('--euser', dest='euser', action='store',
       
    50                       default=login, help="euser name")
       
    51     parser.add_option('--epassword', dest='epassword', action='store',
       
    52                       default=login, help="euser's password' name")
       
    53     return parser
       
    54 
       
    55 
       
    56 class CustomPyTester(PyTester):
       
    57     def __init__(self, cvg, options):
       
    58         super(CustomPyTester, self).__init__(cvg, options)
       
    59         if options.rebuild_db:
       
    60             os.unlink('tmpdb')
       
    61             os.unlink('tmpdb-template')