From c7bec9ce4be7df71d1581b0ba0a13541951d2efe Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 13 Nov 2007 19:01:05 +0000 Subject: [PATCH] Added some tests. git-svn-id: file:///home/talex/Backups/sf.net/Subversion/zero-install/trunk/0publish@2078 9f8c893c-44ee-0310-b757-c8ca8341c71e --- tests/testvalidator.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tests/testvalidator.py diff --git a/tests/testvalidator.py b/tests/testvalidator.py new file mode 100755 index 0000000..5799143 --- /dev/null +++ b/tests/testvalidator.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python2.4 +import sys, logging +from StringIO import StringIO +from zeroinstall.injector.reader import InvalidInterface +import unittest + +sys.path.insert(0, '..') + +import validator + +header = """ + + + test + for testing + + This is for testing. + + http://0install.net + """ +footer = """ + +""" + +root_logger = logging.getLogger() + +def check(xml, expectWarnings = ""): + my_log_stream = StringIO() + my_handler = logging.StreamHandler(my_log_stream) + + root_logger.addHandler(my_handler) + old_stderr = sys.stderr + try: + sys.stderr = my_log_stream + validator.check(xml) + warnings = my_log_stream.getvalue() + finally: + sys.stderr = old_stderr + root_logger.removeHandler(my_handler) + if expectWarnings: + assert expectWarnings in warnings, "Expected warning '%s' not in '%s'" % (expectWarnings, warnings) + elif warnings: + raise Exception("Unexpected warnings '%s'" % warnings) + +class TestValidator(unittest.TestCase): + def testSimple(self): + check(header + footer) + + def testWarnings(self): + check(header + "" + footer, expectWarnings = "Unknown Zero Install element ") + check(header + "" + footer) + check(header + "" + footer, expectWarnings = "Non Zero-Install attributes should be namespaced") + + def testInvalid(self): + try: + check(header) + except InvalidInterface, ex: + assert "Invalid XML" in str(ex), ex + + try: + check(header + "" + footer) + except InvalidInterface, ex: + assert "Missing 'id' attribute" in str(ex), ex + +suite = unittest.makeSuite(TestValidator) +if __name__ == '__main__': + sys.argv.append('-v') + unittest.main() -- 2.11.4.GIT