From d8cb5b1e37d6b21ecbbca0a8519fb50633221060 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 17 Nov 2007 15:21:48 +0000 Subject: [PATCH] Added self-test attribute to validator. Added testall.py to run all 0publish tests at once. --- 0publish.xml | 2 +- tests/testall.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/testlocal.py | 6 +++--- tests/testvalidator.py | 2 ++ validator.py | 6 ++++-- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100755 tests/testall.py diff --git a/0publish.xml b/0publish.xml index 179d7ff..cb9c7be 100644 --- a/0publish.xml +++ b/0publish.xml @@ -21,7 +21,7 @@ - + diff --git a/tests/testall.py b/tests/testall.py new file mode 100755 index 0000000..7da6c30 --- /dev/null +++ b/tests/testall.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python2.4 +import unittest, os, sys +try: + import coverage + coverage.erase() + coverage.start() +except ImportError: + coverage = None + +my_dir = os.path.dirname(sys.argv[0]) +if not my_dir: + my_dir = os.getcwd() + +sys.argv.append('-v') + +suite_names = [f[:-3] for f in os.listdir(my_dir) + if f.startswith('test') and f.endswith('.py')] +suite_names.remove('testall') +suite_names.sort() + +alltests = unittest.TestSuite() + +for name in suite_names: + m = __import__(name, globals(), locals(), []) + alltests.addTest(m.suite) + +a = unittest.TextTestRunner(verbosity=2).run(alltests) + +if coverage: + coverage.stop() +else: + print "Coverage module not found. Skipping coverage report." + +print "\nResult", a +if not a.wasSuccessful(): + sys.exit(1) + +if coverage: + all_sources = [] + def incl(d): + for x in os.listdir(d): + if x.endswith('.py'): + all_sources.append(os.path.join(d, x)) + incl('..') + coverage.report(all_sources + ['../0publish']) diff --git a/tests/testlocal.py b/tests/testlocal.py index 171b5de..92d7055 100755 --- a/tests/testlocal.py +++ b/tests/testlocal.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2.4 -import sys, logging, os, tempfile +import sys, os, tempfile from zeroinstall.injector.namespaces import XMLNS_IFACE from zeroinstall.injector.reader import InvalidInterface from zeroinstall.injector import model, reader @@ -43,7 +43,7 @@ def tap(s): #print s return s -class TestValidator(unittest.TestCase): +class TestLocal(unittest.TestCase): def testCreate(self): master = parse(create.create_from_local(local_file)) assert master.uri == 'http://test/hello.xml', master @@ -151,7 +151,7 @@ class TestValidator(unittest.TestCase): assert ctx.attribs[(None, 'x')] == '1' assert ctx.attribs[('foo', 'z')] == '2' -suite = unittest.makeSuite(TestValidator) +suite = unittest.makeSuite(TestLocal) if __name__ == '__main__': sys.argv.append('-v') unittest.main() diff --git a/tests/testvalidator.py b/tests/testvalidator.py index 5799143..412a8cb 100755 --- a/tests/testvalidator.py +++ b/tests/testvalidator.py @@ -28,6 +28,8 @@ def check(xml, expectWarnings = ""): my_log_stream = StringIO() my_handler = logging.StreamHandler(my_log_stream) + root_logger.handlers = [] + root_logger.addHandler(my_handler) old_stderr = sys.stderr try: diff --git a/validator.py b/validator.py index 3fb8735..535a908 100644 --- a/validator.py +++ b/validator.py @@ -5,6 +5,8 @@ from xml.dom import minidom, Node, XMLNS_NAMESPACE import tempfile from logging import warn, info, debug +group_impl_attribs = ['version', 'version-modifier', 'released', 'main', 'stability', 'arch', 'license', 'doc-dir', 'self-test'] + known_elements = { 'interface' : ['uri', 'min-injector-version', 'main'], # (main is deprecated) 'name' : [], @@ -17,8 +19,8 @@ known_elements = { 'feed' : ['src', 'arch'], 'feed-for' : ['interface'], - 'group' : ['version', 'released', 'main', 'stability', 'arch', 'license', 'doc-dir'], - 'implementation' : ['id', 'version', 'released', 'main', 'stability', 'arch', 'version-modifier', 'license', 'doc-dir'], + 'group' : group_impl_attribs, + 'implementation' : ['id'] + group_impl_attribs, 'package-implementation' : ['package'], 'archive' : ['href', 'size', 'extract', 'type', 'start-offset'], -- 2.11.4.GIT