qubes/tests: fix testrunner dependency on being run in specific directory

This commit is contained in:
Wojtek Porczyk 2015-01-13 23:17:18 +01:00
والد e5d2b49fd6
کامیت a13a41fbaf
4فایلهای تغییر یافته به همراه40 افزوده شده و 4 حذف شده

مشاهده پرونده

@ -1,6 +1,8 @@
#!/usr/bin/python -O #!/usr/bin/python -O
import collections import collections
import os
import subprocess
import unittest import unittest
import lxml.etree import lxml.etree
@ -12,6 +14,9 @@ import qubes.events
#: :py:obj:`True` if running in dom0, :py:obj:`False` otherwise #: :py:obj:`True` if running in dom0, :py:obj:`False` otherwise
in_dom0 = False in_dom0 = False
#: :py:obj:`False` if outside of git repo, path to root of the directory otherwise
in_git = False
try: try:
import libvirt import libvirt
libvirt.openReadOnly(qubes.config.defaults['libvirt_uri']).close() libvirt.openReadOnly(qubes.config.defaults['libvirt_uri']).close()
@ -20,6 +25,15 @@ try:
except libvirt.libvirtError: except libvirt.libvirtError:
pass pass
try:
in_git = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip()
except subprocess.CalledProcessError:
# git returned nonzero, we are outside git repo
pass
except OSError:
# command not found; let's assume we're outside
pass
def skipUnlessDom0(test_item): def skipUnlessDom0(test_item):
'''Decorator that skips test outside dom0. '''Decorator that skips test outside dom0.
@ -31,6 +45,16 @@ def skipUnlessDom0(test_item):
return unittest.skipUnless(in_dom0, 'outside dom0')(test_item) return unittest.skipUnless(in_dom0, 'outside dom0')(test_item)
def skipUnlessGit(test_item):
'''Decorator that skips test outside git repo.
There are very few tests that an be run only in git. One example is
correctness of example code that won't get included in RPM.
'''
return unittest.skipUnless(in_git, 'outside git tree')(test_item)
class TestEmitter(qubes.events.Emitter): class TestEmitter(qubes.events.Emitter):
'''Dummy event emitter which records events fired on it. '''Dummy event emitter which records events fired on it.
@ -160,6 +184,15 @@ class QubesTestCase(unittest.TestCase):
relaxng = lxml.etree.RelaxNG(relaxng) relaxng = lxml.etree.RelaxNG(relaxng)
elif file is not None and schema is None: elif file is not None and schema is None:
if not os.path.isabs(file):
basedirs = ['/usr/share/doc/qubes/relaxng']
if in_git:
basedirs.insert(0, os.path.join(in_git, 'relaxng'))
for basedir in basedirs:
abspath = os.path.join(basedir, file)
if os.path.exists(abspath):
file = abspath
break
relaxng = lxml.etree.RelaxNG(file=file) relaxng = lxml.etree.RelaxNG(file=file)
else: else:

مشاهده پرونده

@ -1,5 +1,6 @@
#!/usr/bin/python2 -O #!/usr/bin/python2 -O
import os
import sys import sys
import unittest import unittest
@ -321,7 +322,9 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase):
class TC_90_Qubes(qubes.tests.QubesTestCase): class TC_90_Qubes(qubes.tests.QubesTestCase):
@qubes.tests.skipUnlessGit
def test_900_example_xml_in_doc(self): def test_900_example_xml_in_doc(self):
self.assertXMLIsValid( self.assertXMLIsValid(
lxml.etree.parse(open('../../doc/example.xml', 'rb')), lxml.etree.parse(open(
'../../relaxng/qubes.rng') os.path.join(qubes.tests.in_git, 'doc/example.xml'), 'rb')),
'qubes.rng')

مشاهده پرونده

@ -12,7 +12,7 @@ test_order = [
'qubes.tests.init' 'qubes.tests.init'
] ]
sys.path.insert(0, '../../') sys.path.insert(1, '../../')
class ANSIColor(dict): class ANSIColor(dict):
def __init__(self): def __init__(self):

مشاهده پرونده

@ -131,7 +131,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
'disabledservice': False, 'disabledservice': False,
}) })
self.assertXMLIsValid(vm.__xml__(), '../../relaxng/domain.rng') self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
def test_001_BaseVM_nxproperty(self): def test_001_BaseVM_nxproperty(self):
xml = lxml.etree.XML(''' xml = lxml.etree.XML('''