qubes/tests: fix testrunner dependency on being run in specific directory
This commit is contained in:
parent
e5d2b49fd6
commit
a13a41fbaf
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/python -O
|
||||
|
||||
import collections
|
||||
import os
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
import lxml.etree
|
||||
@ -12,6 +14,9 @@ import qubes.events
|
||||
#: :py:obj:`True` if running in dom0, :py:obj:`False` otherwise
|
||||
in_dom0 = False
|
||||
|
||||
#: :py:obj:`False` if outside of git repo, path to root of the directory otherwise
|
||||
in_git = False
|
||||
|
||||
try:
|
||||
import libvirt
|
||||
libvirt.openReadOnly(qubes.config.defaults['libvirt_uri']).close()
|
||||
@ -20,6 +25,15 @@ try:
|
||||
except libvirt.libvirtError:
|
||||
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):
|
||||
'''Decorator that skips test outside dom0.
|
||||
@ -31,6 +45,16 @@ def skipUnlessDom0(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):
|
||||
'''Dummy event emitter which records events fired on it.
|
||||
|
||||
@ -160,6 +184,15 @@ class QubesTestCase(unittest.TestCase):
|
||||
relaxng = lxml.etree.RelaxNG(relaxng)
|
||||
|
||||
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)
|
||||
|
||||
else:
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python2 -O
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@ -321,7 +322,9 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase):
|
||||
|
||||
|
||||
class TC_90_Qubes(qubes.tests.QubesTestCase):
|
||||
@qubes.tests.skipUnlessGit
|
||||
def test_900_example_xml_in_doc(self):
|
||||
self.assertXMLIsValid(
|
||||
lxml.etree.parse(open('../../doc/example.xml', 'rb')),
|
||||
'../../relaxng/qubes.rng')
|
||||
lxml.etree.parse(open(
|
||||
os.path.join(qubes.tests.in_git, 'doc/example.xml'), 'rb')),
|
||||
'qubes.rng')
|
||||
|
@ -12,7 +12,7 @@ test_order = [
|
||||
'qubes.tests.init'
|
||||
]
|
||||
|
||||
sys.path.insert(0, '../../')
|
||||
sys.path.insert(1, '../../')
|
||||
|
||||
class ANSIColor(dict):
|
||||
def __init__(self):
|
||||
|
@ -131,7 +131,7 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
|
||||
'disabledservice': False,
|
||||
})
|
||||
|
||||
self.assertXMLIsValid(vm.__xml__(), '../../relaxng/domain.rng')
|
||||
self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
|
||||
|
||||
def test_001_BaseVM_nxproperty(self):
|
||||
xml = lxml.etree.XML('''
|
||||
|
Loading…
Reference in New Issue
Block a user