From 74a2ab5612384b2180a4b3885460db9420f07369 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 26 Sep 2013 18:32:50 -0400 Subject: [PATCH] test_urls: Fix --path option --- setup.py | 9 ++---- tests/__init__.py | 4 +++ tests/test_urls.py | 72 +++++++++++++++++++++------------------------- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/setup.py b/setup.py index 7507084b2..112488298 100755 --- a/setup.py +++ b/setup.py @@ -491,14 +491,10 @@ class TestURLFetch(TestBaseCommand): 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 = [] @@ -506,11 +502,10 @@ class TestURLFetch(TestBaseCommand): self.path = origpath.split(",") def run(self): - from tests import test_urls self._testfiles = ["tests.test_urls"] if self.path: - for p in self.path: - test_urls.LOCAL_MEDIA.append(p) + import tests + tests.URLTEST_LOCAL_MEDIA += self.path TestBaseCommand.run(self) diff --git a/tests/__init__.py b/tests/__init__.py index fb48cf2fa..967b4135f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -67,3 +67,7 @@ virtinstall = _import("virtinstall", "virt-install") virtimage = _import("virtimage", "virt-image") virtclone = _import("virtclone", "virt-clone") virtconvert = _import("virtconvert", "virt-convert") + +# Variable used to store a local iso or dir path to check for a distro +# Specified via 'python setup.py test_urls --path" +URLTEST_LOCAL_MEDIA = [] diff --git a/tests/test_urls.py b/tests/test_urls.py index 79d2a696d..774b82f98 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -22,6 +22,7 @@ import sys import urlgrabber.progress +from tests import URLTEST_LOCAL_MEDIA from tests import utils from virtinst import Guest @@ -38,10 +39,6 @@ from virtinst.urlfetcher import MandrivaDistro # pylint: disable=W0212 # Access to protected member, needed to unittest stuff -# Variable used to store a local iso or dir path to check for a distro -# Specified via 'python setup.py test_urls --path" -LOCAL_MEDIA = [] - OLD_FEDORA_URL = "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/%s/Fedora/%s/os/" DEVFEDORA_URL = "http://download.fedoraproject.org/pub/fedora/linux/development/%s/%s/os/" FEDORA_URL = "http://download.fedoraproject.org/pub/fedora/linux/releases/%s/Fedora/%s/os/" @@ -211,19 +208,6 @@ def _storeForDistro(fetcher, guest): raise -def _testLocalMedia(fetcher, path): - """ - Test a local path explicitly requested by the user - """ - print "\nChecking local path: %s" % path - arch = platform.machine() - - # Make sure we detect _a_ distro - hvmguest.os.arch = arch - hvmstore = _storeForDistro(fetcher, hvmguest) - logging.debug("Local distro detected as: %s", hvmstore) - - def _testURL(fetcher, distname, arch, distroobj): """ Test that our URL detection logic works for grabbing kernel, xen @@ -242,12 +226,14 @@ def _testURL(fetcher, distname, arch, distroobj): xenstore = _storeForDistro(fetcher, xenguest) for s in [hvmstore, xenstore]: - if s and not isinstance(s, distroobj.distroclass): + if (s and distroobj.distroclass and + not isinstance(s, distroobj.distroclass)): raise AssertionError("(%s): expected store %s, was %s" % (distname, distroobj.distroclass, s)) # Make sure the stores are reporting correct distro name/variant - if s and distroobj.detectdistro != s.os_variant: + if (s and distroobj.detectdistro and + distroobj.detectdistro != s.os_variant): raise AssertionError("Store distro/variant did not match " "expected values: store=%s, found=%s expect=%s" % (s, s.os_variant, distroobj.detectdistro)) @@ -300,9 +286,9 @@ def _fetch_wrapper(url, cb, *args): fetcher.cleanupLocation() -def _make_test_wrapper(url, cb, args): +def _make_test_wrapper(url, args): def cmdtemplate(): - return _fetch_wrapper(url, cb, *args) + return _fetch_wrapper(url, _testURL, *args) return lambda _self: cmdtemplate() @@ -313,25 +299,31 @@ class URLTests(unittest.TestCase): def _make_tests(): - if LOCAL_MEDIA: - newidx = 0 - for p in LOCAL_MEDIA: - newidx += 1 - args = (p,) - testfunc = _make_test_wrapper(p, _testLocalMedia, args) - setattr(URLTests, "testLocalMedia%s" % newidx, testfunc) - else: - keys = urls.keys() - keys.sort() - for key in keys: - distroobj = urls[key] + global urls - for arch, url in [("i686", distroobj.i686), - ("x86_64", distroobj.x86_64)]: - if not url: - continue - args = (key, arch, distroobj) - testfunc = _make_test_wrapper(url, _testURL, args) - setattr(URLTests, "testURL%s%s" % (key, arch), testfunc) + if URLTEST_LOCAL_MEDIA: + urls = {} + newidx = 0 + arch = platform.machine() + for p in URLTEST_LOCAL_MEDIA: + newidx += 1 + + d = _DistroURL(p, None, hasxen=False, hasbootiso=False, + name="path%s" % newidx) + d.distroclass = None + urls[d.name] = d + + keys = urls.keys() + keys.sort() + for key in keys: + distroobj = urls[key] + + for arch, url in [("i686", distroobj.i686), + ("x86_64", distroobj.x86_64)]: + if not url: + continue + args = (key, arch, distroobj) + testfunc = _make_test_wrapper(url, args) + setattr(URLTests, "testURL%s%s" % (key, arch), testfunc) _make_tests()