Wire up python unit tests, unify gettext setup

This commit is contained in:
Cole Robinson 2013-03-17 18:18:22 -04:00
parent 88603e4fad
commit d6c8ad0297
48 changed files with 149 additions and 93 deletions

129
setup.py
View File

@ -2,6 +2,8 @@
import glob import glob
import os import os
import sys
import unittest
from distutils.core import Command, setup from distutils.core import Command, setup
from distutils.command.install_egg_info import install_egg_info from distutils.command.install_egg_info import install_egg_info
@ -170,6 +172,130 @@ if not cliconfig.with_tui:
tui_files = [] tui_files = []
class TestBaseCommand(Command):
user_options = [('debug', 'd', 'Show debug output')]
boolean_options = ['debug']
def initialize_options(self):
self.debug = 0
self._testfiles = []
self._dir = os.getcwd()
def finalize_options(self):
if self.debug and "DEBUG_TESTS" not in os.environ:
os.environ["DEBUG_TESTS"] = "1"
def run(self):
try:
# Use system 'coverage' if available
import coverage
use_coverage = True
except:
use_coverage = False
tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
t = unittest.TextTestRunner(verbosity=1)
if use_coverage:
coverage.erase()
coverage.start()
if hasattr(unittest, "installHandler"):
try:
unittest.installHandler()
except:
print "installHandler hack failed"
try:
result = t.run(tests)
except KeyboardInterrupt:
sys.exit(1)
if use_coverage:
coverage.stop()
sys.exit(int(bool(len(result.failures) > 0 or
len(result.errors) > 0)))
class TestCommand(TestBaseCommand):
description = "Runs a quick unit test suite"
user_options = TestBaseCommand.user_options + \
[("testfile=", None, "Specific test file to run (e.g "
"validation, storage, ...)"),
("skipcli", None, "Skip CLI tests")]
def initialize_options(self):
TestBaseCommand.initialize_options(self)
self.testfile = None
self.skipcli = None
def finalize_options(self):
TestBaseCommand.finalize_options(self)
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
testfiles = []
for t in glob.glob(os.path.join(self._dir, 'tests', '*.py')):
if (t.endswith("__init__.py") or
t.endswith("urltest.py")):
continue
base = os.path.basename(t)
if self.testfile:
check = os.path.basename(self.testfile)
if base != check and base != (check + ".py"):
continue
if self.skipcli and base.count("clitest"):
continue
testfiles.append('.'.join(['tests', os.path.splitext(base)[0]]))
if not testfiles:
raise RuntimeError("--testfile didn't catch anything")
self._testfiles = testfiles
TestBaseCommand.run(self)
class TestURLFetch(TestBaseCommand):
description = "Test fetching kernels and isos from various distro trees"
user_options = TestBaseCommand.user_options + \
[("match=", None, "Regular expression of dist names to "
"match [default: '.*']"),
("path=", None, "Paths to local iso or directory or check"
" for installable distro. Comma separated")]
def initialize_options(self):
TestBaseCommand.initialize_options(self)
self.match = None
self.path = ""
def finalize_options(self):
TestBaseCommand.finalize_options(self)
if self.match is None:
self.match = ".*"
origpath = str(self.path)
if not origpath:
self.path = []
else:
self.path = origpath.split(",")
def run(self):
import tests
self._testfiles = ["tests.urltest"]
tests.urltest.MATCH_FILTER = self.match
if self.path:
for p in self.path:
tests.urltest.LOCAL_MEDIA.append(p)
TestBaseCommand.run(self)
setup( setup(
name = "virt-manager", name = "virt-manager",
version = cliconfig.__version__, version = cliconfig.__version__,
@ -195,11 +321,12 @@ setup(
'build_i18n': my_build_i18n, 'build_i18n': my_build_i18n,
'build_icons': my_build_icons, 'build_icons': my_build_icons,
'sdist': sdist_auto, 'sdist': sdist_auto,
'install_egg_info': my_egg_info, 'install_egg_info': my_egg_info,
'configure': configure, 'configure': configure,
'rpm': my_rpm, 'rpm': my_rpm,
'test': TestCommand,
'test_urls' : TestURLFetch,
} }
) )

View File

@ -16,9 +16,10 @@
import logging import logging
import os import os
import virtinst
import utils import virtinst
from tests import utils
# Force certain helpers to return consistent values # Force certain helpers to return consistent values
virtinst._util.is_blktap_capable = lambda: False virtinst._util.is_blktap_capable = lambda: False

View File

@ -20,18 +20,18 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import sys
import logging
import virtinst.CloneManager as clmgr
import urlgrabber.progress as progress
import optparse import optparse
from optparse import OptionGroup from optparse import OptionGroup
import sys
import logging
import urlgrabber.progress as progress
import virtinst.CloneManager as clmgr
import virtinst.cli as cli import virtinst.cli as cli
from virtinst.cli import fail, print_stdout, print_stderr from virtinst.cli import fail, print_stdout, print_stderr
from virtinst.User import User from virtinst.User import User
cli.setupGettext()
### General input gathering functions ### General input gathering functions
def get_clone_name(new_name, auto_clone, design): def get_clone_name(new_name, auto_clone, design):

View File

@ -34,7 +34,6 @@ import virtconv.formats as formats
import virtconv.vmcfg as vmcfg import virtconv.vmcfg as vmcfg
import virtconv.diskcfg as diskcfg import virtconv.diskcfg as diskcfg
cli.setupGettext()
def parse_args(): def parse_args():
"""Parse and verify command line.""" """Parse and verify command line."""

View File

@ -32,7 +32,6 @@ from virtinst.cli import fail, print_stdout, print_stderr
import optparse import optparse
from optparse import OptionGroup from optparse import OptionGroup
cli.setupGettext()
### General input gathering functions ### General input gathering functions

View File

@ -38,7 +38,6 @@ import virtinst._util as _util
from virtinst.VirtualDevice import VirtualDevice from virtinst.VirtualDevice import VirtualDevice
from virtinst.cli import fail, print_stdout, print_stderr from virtinst.cli import fail, print_stdout, print_stderr
cli.setupGettext()
############################## ##############################

View File

@ -21,20 +21,6 @@
import pkgutil import pkgutil
import imp import imp
import os import os
import sys
import gettext
gettext.bindtextdomain("virtinst")
_gettext = lambda m: gettext.dgettext("virtinst", m)
try:
import _config
except ImportError:
print "virtconv: Please run 'python setup.py build' in the source"
print " directory before using the code."
sys.exit(1)
__version__ = _config.__version__
__version_info__ = _config.__version_info__
parsers_path = [os.path.join(__path__[0], "parsers/")] parsers_path = [os.path.join(__path__[0], "parsers/")]

View File

@ -27,7 +27,6 @@ import os
import re import re
import logging import logging
from virtconv import _gettext as _
DISK_FORMAT_NONE = 0 DISK_FORMAT_NONE = 0
DISK_FORMAT_RAW = 1 DISK_FORMAT_RAW = 1

View File

@ -20,10 +20,9 @@
import os import os
from virtconv import _gettext as _
_parsers = [ ] _parsers = [ ]
class parser(object): class parser(object):
""" """
Base class for particular config file format definitions of Base class for particular config file format definitions of

View File

@ -20,7 +20,6 @@
import libxml2 import libxml2
from virtconv import _gettext as _
import virtconv.formats as formats import virtconv.formats as formats
import virtconv.vmcfg as vmcfg import virtconv.vmcfg as vmcfg
import virtconv.diskcfg as diskcfg import virtconv.diskcfg as diskcfg

View File

@ -19,7 +19,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
# #
from virtconv import _gettext as _
import virtconv.formats as formats import virtconv.formats as formats
import virtconv.vmcfg as vmcfg import virtconv.vmcfg as vmcfg
import virtconv.diskcfg as diskcfg import virtconv.diskcfg as diskcfg

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
# #
from virtconv import _gettext as _
import virtconv.formats as formats import virtconv.formats as formats
import virtconv.vmcfg as vmcfg import virtconv.vmcfg as vmcfg
import virtconv.diskcfg as diskcfg import virtconv.diskcfg as diskcfg

View File

@ -19,7 +19,6 @@
# #
import platform import platform
from virtconv import _gettext as _
from virtconv import diskcfg from virtconv import diskcfg
from virtinst import CapabilitiesParser from virtinst import CapabilitiesParser

View File

@ -21,7 +21,6 @@
import re import re
from virtinst import _gettext as _
import _util import _util
class CapabilitiesParserException(Exception): class CapabilitiesParserException(Exception):

View File

@ -44,7 +44,6 @@ import Guest
from VirtualNetworkInterface import VirtualNetworkInterface from VirtualNetworkInterface import VirtualNetworkInterface
from VirtualDisk import VirtualDisk from VirtualDisk import VirtualDisk
from virtinst import Storage from virtinst import Storage
from virtinst import _gettext as _
import _util import _util
def _listify(val): def _listify(val):

View File

@ -33,7 +33,6 @@ from VirtualDisk import VirtualDisk
from User import User from User import User
import OSDistro import OSDistro
from virtinst import _gettext as _
def _is_url(url, is_local): def _is_url(url, is_local):
""" """

View File

@ -22,7 +22,6 @@ import re
import _util import _util
import XMLBuilderDomain import XMLBuilderDomain
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
class DomainNumatune(XMLBuilderDomain.XMLBuilderDomain): class DomainNumatune(XMLBuilderDomain.XMLBuilderDomain):
""" """

View File

@ -48,7 +48,6 @@ from DomainNumatune import DomainNumatune
from DomainFeatures import DomainFeatures from DomainFeatures import DomainFeatures
import osdict import osdict
from virtinst import _gettext as _
class Guest(XMLBuilderDomain.XMLBuilderDomain): class Guest(XMLBuilderDomain.XMLBuilderDomain):

View File

@ -28,7 +28,7 @@ import urllib2
import urlparse import urlparse
import ftplib import ftplib
import tempfile import tempfile
from virtinst import _gettext as _
# This is a generic base class for fetching/extracting files from # This is a generic base class for fetching/extracting files from
# a media source, such as CD ISO, NFS server, or HTTP/FTP server # a media source, such as CD ISO, NFS server, or HTTP/FTP server

View File

@ -24,7 +24,7 @@ import Installer
import ImageParser import ImageParser
import CapabilitiesParser as Cap import CapabilitiesParser as Cap
from VirtualDisk import VirtualDisk from VirtualDisk import VirtualDisk
from virtinst import _gettext as _
class ImageInstallerException(Exception): class ImageInstallerException(Exception):
def __init__(self, msg): def __init__(self, msg):

View File

@ -26,7 +26,6 @@ import libxml2
import urlgrabber import urlgrabber
import CapabilitiesParser import CapabilitiesParser
from virtinst import _gettext as _
import _util import _util

View File

@ -31,7 +31,6 @@ import virtinst
import XMLBuilderDomain import XMLBuilderDomain
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import CapabilitiesParser from virtinst import CapabilitiesParser
from virtinst import _gettext as _
from VirtualDisk import VirtualDisk from VirtualDisk import VirtualDisk
from Boot import Boot from Boot import Boot

View File

@ -26,7 +26,7 @@ import logging
import _util import _util
import support import support
from virtinst import _gettext as _
class Interface(object): class Interface(object):
""" """

View File

@ -21,7 +21,7 @@
import Installer import Installer
from VirtualDisk import VirtualDisk from VirtualDisk import VirtualDisk
from virtinst import _gettext as _
class LiveCDInstallerException(Exception): class LiveCDInstallerException(Exception):
def __init__(self, msg): def __init__(self, msg):

View File

@ -17,7 +17,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA. # MA 02110-1301 USA.
from virtinst import _gettext as _
import support import support
import _util import _util
import libvirt import libvirt

View File

@ -30,7 +30,6 @@ import ConfigParser
import virtinst import virtinst
import osdict import osdict
from virtinst import _util from virtinst import _util
from virtinst import _gettext as _
from ImageFetcher import MountedImageFetcher from ImageFetcher import MountedImageFetcher
from ImageFetcher import FTPImageFetcher from ImageFetcher import FTPImageFetcher

View File

@ -56,7 +56,6 @@ import urlgrabber
from _util import xml_escape as escape from _util import xml_escape as escape
import _util import _util
import support import support
from virtinst import _gettext as _
DEFAULT_DEV_TARGET = "/dev" DEFAULT_DEV_TARGET = "/dev"

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualAudio(VirtualDevice.VirtualDevice): class VirtualAudio(VirtualDevice.VirtualDevice):

View File

@ -21,7 +21,6 @@ import VirtualDevice
from _util import xml_escape from _util import xml_escape
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
class VirtualCharDevice(VirtualDevice.VirtualDevice): class VirtualCharDevice(VirtualDevice.VirtualDevice):
""" """

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import VirtualDevice import VirtualDevice
#from virtinst import _gettext as _
from XMLBuilderDomain import XMLBuilderDomain, _xml_property from XMLBuilderDomain import XMLBuilderDomain, _xml_property
import logging import logging

View File

@ -20,7 +20,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
from XMLBuilderDomain import XMLBuilderDomain, _xml_property from XMLBuilderDomain import XMLBuilderDomain, _xml_property
from virtinst import _gettext as _
import logging import logging
class VirtualDevice(XMLBuilderDomain): class VirtualDevice(XMLBuilderDomain):

View File

@ -35,7 +35,6 @@ import _util
import Storage import Storage
from VirtualDevice import VirtualDevice from VirtualDevice import VirtualDevice
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
def _vdisk_create(path, size, kind, sparse=True): def _vdisk_create(path, size, kind, sparse=True):
force_fixed = "raw" force_fixed = "raw"

View File

@ -20,7 +20,6 @@
import os import os
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualFilesystem(VirtualDevice.VirtualDevice): class VirtualFilesystem(VirtualDevice.VirtualDevice):

View File

@ -24,7 +24,6 @@ import _util
import VirtualDevice import VirtualDevice
import support import support
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
def _get_mode_prop(channel_type): def _get_mode_prop(channel_type):
xpath = "./channel[@name='%s']/@mode" % channel_type xpath = "./channel[@name='%s']/@mode" % channel_type

View File

@ -21,7 +21,6 @@ import VirtualDevice
import NodeDeviceParser import NodeDeviceParser
import logging import logging
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualHostDevice(VirtualDevice.VirtualDevice): class VirtualHostDevice(VirtualDevice.VirtualDevice):

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualInputDevice(VirtualDevice.VirtualDevice): class VirtualInputDevice(VirtualDevice.VirtualDevice):

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualMemballoon(VirtualDevice.VirtualDevice): class VirtualMemballoon(VirtualDevice.VirtualDevice):

View File

@ -24,7 +24,6 @@ import _util
import VirtualDevice import VirtualDevice
import XMLBuilderDomain import XMLBuilderDomain
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
def _countMACaddr(vms, searchmac): def _countMACaddr(vms, searchmac):
if not searchmac: if not searchmac:

View File

@ -21,7 +21,6 @@
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualRedirDevice(VirtualDevice.VirtualDevice): class VirtualRedirDevice(VirtualDevice.VirtualDevice):

View File

@ -21,7 +21,6 @@
import VirtualDevice import VirtualDevice
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
from virtinst import _gettext as _
class VirtualSmartCardDevice(VirtualDevice.VirtualDevice): class VirtualSmartCardDevice(VirtualDevice.VirtualDevice):

View File

@ -18,7 +18,6 @@
# MA 02110-1301 USA. # MA 02110-1301 USA.
import VirtualDevice import VirtualDevice
from virtinst import _gettext as _
from XMLBuilderDomain import _xml_property from XMLBuilderDomain import _xml_property
class VirtualWatchdog(VirtualDevice.VirtualDevice): class VirtualWatchdog(VirtualDevice.VirtualDevice):

View File

@ -27,7 +27,6 @@ import libxml2
import CapabilitiesParser import CapabilitiesParser
import _util import _util
from virtinst import _gettext as _
_xml_refs_lock = threading.Lock() _xml_refs_lock = threading.Lock()
_xml_refs = {} _xml_refs = {}

View File

@ -14,21 +14,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA. # MA 02110-1301 USA.
import gettext from virtcli import cliconfig, cliutils
import sys enable_rhel6_defaults = not cliconfig.rhel_enable_unsupported_opts
cliutils.setup_i18n()
gettext.bindtextdomain("virtinst")
_gettext = lambda m: gettext.dgettext("virtinst", m)
try:
import _config
except ImportError:
print "virtinst: Please run 'python setup.py build' in the source"
print " directory before using the code."
sys.exit(1)
__version__ = _config.__version__
__version_info__ = _config.__version_info__
enable_rhel6_defaults = _config.rhel6defaults
# Public imports # Public imports

View File

@ -35,7 +35,6 @@ import libxml2
import libvirt import libvirt
import virtinst.util as util import virtinst.util as util
from virtinst import _gettext as _
try: try:
import selinux import selinux

View File

@ -34,10 +34,11 @@ import itertools
import libvirt import libvirt
from virtcli import cliconfig
import virtinst import virtinst
from virtinst import _util from virtinst import _util
from _util import listify from _util import listify
from virtinst import _gettext as _
from virtinst import Guest from virtinst import Guest
from virtinst import VirtualNetworkInterface from virtinst import VirtualNetworkInterface
@ -48,6 +49,7 @@ from virtinst import VirtualCharDevice
from virtinst import VirtualDevice from virtinst import VirtualDevice
from virtinst import User from virtinst import User
DEFAULT_POOL_PATH = "/var/lib/libvirt/images" DEFAULT_POOL_PATH = "/var/lib/libvirt/images"
DEFAULT_POOL_NAME = "default" DEFAULT_POOL_NAME = "default"
@ -141,20 +143,9 @@ def setupParser(usage=None):
parser = parse_class(usage=usage, parser = parse_class(usage=usage,
formatter=VirtHelpFormatter(), formatter=VirtHelpFormatter(),
version=virtinst.__version__) version=cliconfig.__version__)
return parser return parser
def setupGettext():
try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error, e:
print >> sys.stderr, "warning: failed to set locale, defaulting to C"
os.environ['LC_ALL'] = 'C'
locale.setlocale(locale.LC_ALL, 'C')
gettext.bindtextdomain("virtinst")
gettext.install("virtinst")
def earlyLogging(): def earlyLogging():
logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(level=logging.DEBUG, format='%(message)s')

View File

@ -21,7 +21,6 @@
import support import support
from VirtualDevice import VirtualDevice from VirtualDevice import VirtualDevice
from virtinst import _gettext as _
HV_ALL = "all" HV_ALL = "all"

View File

@ -22,7 +22,6 @@
import libvirt import libvirt
import _util import _util
from virtinst import _gettext as _
# Flags for check_conn_support # Flags for check_conn_support
SUPPORT_CONN_STORAGE = 0 SUPPORT_CONN_STORAGE = 0

View File

@ -36,7 +36,6 @@ import logging
import subprocess import subprocess
import libvirt import libvirt
from virtinst import _gettext as _
import virtinst import virtinst
import CapabilitiesParser import CapabilitiesParser
import User import User