Wire up python unit tests, unify gettext setup
This commit is contained in:
parent
88603e4fad
commit
d6c8ad0297
129
setup.py
129
setup.py
|
@ -2,6 +2,8 @@
|
|||
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from distutils.core import Command, setup
|
||||
from distutils.command.install_egg_info import install_egg_info
|
||||
|
@ -170,6 +172,130 @@ if not cliconfig.with_tui:
|
|||
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(
|
||||
name = "virt-manager",
|
||||
version = cliconfig.__version__,
|
||||
|
@ -195,11 +321,12 @@ setup(
|
|||
'build_i18n': my_build_i18n,
|
||||
'build_icons': my_build_icons,
|
||||
'sdist': sdist_auto,
|
||||
|
||||
'install_egg_info': my_egg_info,
|
||||
|
||||
'configure': configure,
|
||||
|
||||
'rpm': my_rpm,
|
||||
'test': TestCommand,
|
||||
'test_urls' : TestURLFetch,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
import virtinst
|
||||
|
||||
import utils
|
||||
import virtinst
|
||||
from tests import utils
|
||||
|
||||
|
||||
# Force certain helpers to return consistent values
|
||||
virtinst._util.is_blktap_capable = lambda: False
|
||||
|
|
12
virt-clone
12
virt-clone
|
@ -20,18 +20,18 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import virtinst.CloneManager as clmgr
|
||||
import urlgrabber.progress as progress
|
||||
|
||||
import optparse
|
||||
from optparse import OptionGroup
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import urlgrabber.progress as progress
|
||||
|
||||
import virtinst.CloneManager as clmgr
|
||||
import virtinst.cli as cli
|
||||
from virtinst.cli import fail, print_stdout, print_stderr
|
||||
from virtinst.User import User
|
||||
|
||||
cli.setupGettext()
|
||||
|
||||
### General input gathering functions
|
||||
def get_clone_name(new_name, auto_clone, design):
|
||||
|
|
|
@ -34,7 +34,6 @@ import virtconv.formats as formats
|
|||
import virtconv.vmcfg as vmcfg
|
||||
import virtconv.diskcfg as diskcfg
|
||||
|
||||
cli.setupGettext()
|
||||
|
||||
def parse_args():
|
||||
"""Parse and verify command line."""
|
||||
|
|
|
@ -32,7 +32,6 @@ from virtinst.cli import fail, print_stdout, print_stderr
|
|||
import optparse
|
||||
from optparse import OptionGroup
|
||||
|
||||
cli.setupGettext()
|
||||
|
||||
### General input gathering functions
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import virtinst._util as _util
|
|||
from virtinst.VirtualDevice import VirtualDevice
|
||||
from virtinst.cli import fail, print_stdout, print_stderr
|
||||
|
||||
cli.setupGettext()
|
||||
|
||||
|
||||
##############################
|
||||
|
|
|
@ -21,20 +21,6 @@
|
|||
import pkgutil
|
||||
import imp
|
||||
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/")]
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import os
|
|||
import re
|
||||
import logging
|
||||
|
||||
from virtconv import _gettext as _
|
||||
|
||||
DISK_FORMAT_NONE = 0
|
||||
DISK_FORMAT_RAW = 1
|
||||
|
|
|
@ -20,10 +20,9 @@
|
|||
|
||||
import os
|
||||
|
||||
from virtconv import _gettext as _
|
||||
|
||||
_parsers = [ ]
|
||||
|
||||
|
||||
class parser(object):
|
||||
"""
|
||||
Base class for particular config file format definitions of
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
import libxml2
|
||||
|
||||
from virtconv import _gettext as _
|
||||
import virtconv.formats as formats
|
||||
import virtconv.vmcfg as vmcfg
|
||||
import virtconv.diskcfg as diskcfg
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from virtconv import _gettext as _
|
||||
import virtconv.formats as formats
|
||||
import virtconv.vmcfg as vmcfg
|
||||
import virtconv.diskcfg as diskcfg
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from virtconv import _gettext as _
|
||||
import virtconv.formats as formats
|
||||
import virtconv.vmcfg as vmcfg
|
||||
import virtconv.diskcfg as diskcfg
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#
|
||||
|
||||
import platform
|
||||
from virtconv import _gettext as _
|
||||
from virtconv import diskcfg
|
||||
from virtinst import CapabilitiesParser
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
import re
|
||||
|
||||
from virtinst import _gettext as _
|
||||
import _util
|
||||
|
||||
class CapabilitiesParserException(Exception):
|
||||
|
|
|
@ -44,7 +44,6 @@ import Guest
|
|||
from VirtualNetworkInterface import VirtualNetworkInterface
|
||||
from VirtualDisk import VirtualDisk
|
||||
from virtinst import Storage
|
||||
from virtinst import _gettext as _
|
||||
import _util
|
||||
|
||||
def _listify(val):
|
||||
|
|
|
@ -33,7 +33,6 @@ from VirtualDisk import VirtualDisk
|
|||
from User import User
|
||||
import OSDistro
|
||||
|
||||
from virtinst import _gettext as _
|
||||
|
||||
def _is_url(url, is_local):
|
||||
"""
|
||||
|
|
|
@ -22,7 +22,6 @@ import re
|
|||
import _util
|
||||
import XMLBuilderDomain
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
class DomainNumatune(XMLBuilderDomain.XMLBuilderDomain):
|
||||
"""
|
||||
|
|
|
@ -48,7 +48,6 @@ from DomainNumatune import DomainNumatune
|
|||
from DomainFeatures import DomainFeatures
|
||||
|
||||
import osdict
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
|
|
|
@ -28,7 +28,7 @@ import urllib2
|
|||
import urlparse
|
||||
import ftplib
|
||||
import tempfile
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
# This is a generic base class for fetching/extracting files from
|
||||
# a media source, such as CD ISO, NFS server, or HTTP/FTP server
|
||||
|
|
|
@ -24,7 +24,7 @@ import Installer
|
|||
import ImageParser
|
||||
import CapabilitiesParser as Cap
|
||||
from VirtualDisk import VirtualDisk
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
class ImageInstallerException(Exception):
|
||||
def __init__(self, msg):
|
||||
|
|
|
@ -26,7 +26,6 @@ import libxml2
|
|||
import urlgrabber
|
||||
|
||||
import CapabilitiesParser
|
||||
from virtinst import _gettext as _
|
||||
import _util
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import virtinst
|
|||
import XMLBuilderDomain
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import CapabilitiesParser
|
||||
from virtinst import _gettext as _
|
||||
from VirtualDisk import VirtualDisk
|
||||
from Boot import Boot
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import logging
|
|||
|
||||
import _util
|
||||
import support
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
class Interface(object):
|
||||
"""
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
import Installer
|
||||
from VirtualDisk import VirtualDisk
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
class LiveCDInstallerException(Exception):
|
||||
def __init__(self, msg):
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
from virtinst import _gettext as _
|
||||
import support
|
||||
import _util
|
||||
import libvirt
|
||||
|
|
|
@ -30,7 +30,6 @@ import ConfigParser
|
|||
import virtinst
|
||||
import osdict
|
||||
from virtinst import _util
|
||||
from virtinst import _gettext as _
|
||||
|
||||
from ImageFetcher import MountedImageFetcher
|
||||
from ImageFetcher import FTPImageFetcher
|
||||
|
|
|
@ -56,7 +56,6 @@ import urlgrabber
|
|||
from _util import xml_escape as escape
|
||||
import _util
|
||||
import support
|
||||
from virtinst import _gettext as _
|
||||
|
||||
|
||||
DEFAULT_DEV_TARGET = "/dev"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualAudio(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -21,7 +21,6 @@ import VirtualDevice
|
|||
from _util import xml_escape
|
||||
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
class VirtualCharDevice(VirtualDevice.VirtualDevice):
|
||||
"""
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
import VirtualDevice
|
||||
#from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import XMLBuilderDomain, _xml_property
|
||||
import logging
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
from XMLBuilderDomain import XMLBuilderDomain, _xml_property
|
||||
from virtinst import _gettext as _
|
||||
import logging
|
||||
|
||||
class VirtualDevice(XMLBuilderDomain):
|
||||
|
|
|
@ -35,7 +35,6 @@ import _util
|
|||
import Storage
|
||||
from VirtualDevice import VirtualDevice
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
def _vdisk_create(path, size, kind, sparse=True):
|
||||
force_fixed = "raw"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
import os
|
||||
|
||||
import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualFilesystem(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -24,7 +24,6 @@ import _util
|
|||
import VirtualDevice
|
||||
import support
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
def _get_mode_prop(channel_type):
|
||||
xpath = "./channel[@name='%s']/@mode" % channel_type
|
||||
|
|
|
@ -21,7 +21,6 @@ import VirtualDevice
|
|||
import NodeDeviceParser
|
||||
import logging
|
||||
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualHostDevice(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualInputDevice(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualMemballoon(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -24,7 +24,6 @@ import _util
|
|||
import VirtualDevice
|
||||
import XMLBuilderDomain
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
def _countMACaddr(vms, searchmac):
|
||||
if not searchmac:
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
import VirtualDevice
|
||||
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualRedirDevice(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
import VirtualDevice
|
||||
from XMLBuilderDomain import _xml_property
|
||||
from virtinst import _gettext as _
|
||||
|
||||
class VirtualSmartCardDevice(VirtualDevice.VirtualDevice):
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
|
||||
import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
from XMLBuilderDomain import _xml_property
|
||||
|
||||
class VirtualWatchdog(VirtualDevice.VirtualDevice):
|
||||
|
|
|
@ -27,7 +27,6 @@ import libxml2
|
|||
|
||||
import CapabilitiesParser
|
||||
import _util
|
||||
from virtinst import _gettext as _
|
||||
|
||||
_xml_refs_lock = threading.Lock()
|
||||
_xml_refs = {}
|
||||
|
|
|
@ -14,21 +14,10 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
import gettext
|
||||
import sys
|
||||
from virtcli import cliconfig, cliutils
|
||||
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
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ import libxml2
|
|||
import libvirt
|
||||
|
||||
import virtinst.util as util
|
||||
from virtinst import _gettext as _
|
||||
|
||||
try:
|
||||
import selinux
|
||||
|
|
|
@ -34,10 +34,11 @@ import itertools
|
|||
|
||||
import libvirt
|
||||
|
||||
from virtcli import cliconfig
|
||||
|
||||
import virtinst
|
||||
from virtinst import _util
|
||||
from _util import listify
|
||||
from virtinst import _gettext as _
|
||||
|
||||
from virtinst import Guest
|
||||
from virtinst import VirtualNetworkInterface
|
||||
|
@ -48,6 +49,7 @@ from virtinst import VirtualCharDevice
|
|||
from virtinst import VirtualDevice
|
||||
from virtinst import User
|
||||
|
||||
|
||||
DEFAULT_POOL_PATH = "/var/lib/libvirt/images"
|
||||
DEFAULT_POOL_NAME = "default"
|
||||
|
||||
|
@ -141,20 +143,9 @@ def setupParser(usage=None):
|
|||
|
||||
parser = parse_class(usage=usage,
|
||||
formatter=VirtHelpFormatter(),
|
||||
version=virtinst.__version__)
|
||||
version=cliconfig.__version__)
|
||||
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():
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
import support
|
||||
from VirtualDevice import VirtualDevice
|
||||
from virtinst import _gettext as _
|
||||
|
||||
HV_ALL = "all"
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
import libvirt
|
||||
import _util
|
||||
|
||||
from virtinst import _gettext as _
|
||||
|
||||
# Flags for check_conn_support
|
||||
SUPPORT_CONN_STORAGE = 0
|
||||
|
|
|
@ -36,7 +36,6 @@ import logging
|
|||
import subprocess
|
||||
|
||||
import libvirt
|
||||
from virtinst import _gettext as _
|
||||
import virtinst
|
||||
import CapabilitiesParser
|
||||
import User
|
||||
|
|
Loading…
Reference in New Issue