From a6cbad2a61e8c62fcd56a61887c1af9d64ee5542 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 26 Jan 2004 06:38:35 +0000 Subject: [PATCH] Brought README up to date, made changes having to do with moving of ZSI-specific material to zsi/test/wsdlpy, removed dependencies on utils.py. --- test/README | 32 ++++++---------------- test/__init__.py | 2 +- test/test_wsdl.py | 58 +++++++++++++++++++++++++--------------- test/test_wstools.py | 6 ++--- test/test_wstools_net.py | 6 ++--- 5 files changed, 50 insertions(+), 54 deletions(-) diff --git a/test/README b/test/README index 93dc21c..7c1097a 100644 --- a/test/README +++ b/test/README @@ -1,25 +1,23 @@ -Two top level modules have been provided to run the tests. "test_wstools.py" is used -to run all of the local tests. "test_wstools_net.py" is used to run all of the -tests that require network access. +Two top level modules have been provided to run the tests. "test_wstools.py" +is used to run all of the local tests. "test_wstools_net.py" is used to run +all of the tests that require network access. -TESTS: - test_t1 -- Basic test, just checks that wsdl and xsd objects are in the - right places. +Add the -v option for more informative feedback. ADDING TESTS: 1. For Stand-Alone tests add WSDL FILE to appropriate archive file Need to add a NEW Archive?: - config.py [files] "archive" -- tuple of all archive files, + config.txt [files] "archive" -- tuple of all archive files, if you need to create a new archive append the archive name to the 'archive' tuple. - 2. Edit config.py section(s): + 2. Edit config.txt section(s): option -- name by which service will be referenced in test case. Need an entry under appropriate section(s), this name must be unique within each section it appears but it may appear in multiple sections. - config.py "test" sections: + config.txt "test" sections: Stand-Alone -- add "option" under [services_by_file] eg. amazon = exports/AmazonWebServices.wsdl @@ -28,21 +26,7 @@ ADDING TESTS: Broken -- add "option" under [broken] - 3. In test module(s) - a. Add test case: - - #eg. test_t1.py - class AmazonTestCase(WSDLToolsTestCase): - def test(self): - self.option = 'amazon' - self.loadFromConfig(CONFIG) - - b. Add class name of test case to CASES list. - CASES = [AirportTestCase, - AmazonTestCase, - .... etc - - 4. Done + 3. Done CONTENTS OF SAMPLE WSDL/XSD: diff --git a/test/__init__.py b/test/__init__.py index 9eaf692..d5a5350 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,5 +1,5 @@ #! /usr/bin/env python -"""wsdl2python and wstools.WSDLTools.WSDLReader tests directory.""" +"""wstools.WSDLTools.WSDLReader tests directory.""" import utils diff --git a/test/test_wsdl.py b/test/test_wsdl.py index 6af855b..90b0c4d 100644 --- a/test/test_wsdl.py +++ b/test/test_wsdl.py @@ -6,8 +6,10 @@ ########################################################################### import sys, unittest +import ConfigParser from ZSI.wstools.Utility import DOM -import utils +from ZSI.wstools.WSDLTools import WSDLReader +from ZSI.wstools.TimeoutSocket import TimeoutError class WSDLToolsTestCase(unittest.TestCase): @@ -15,10 +17,7 @@ class WSDLToolsTestCase(unittest.TestCase): unittest.TestCase.__init__(self, methodName) def setUp(self): - global configLoader - - # not thread safe - self.path = configLoader.nameGenerator.next() + self.path = nameGenerator.next() print self.path sys.stdout.flush() @@ -45,9 +44,17 @@ class WSDLToolsTestCase(unittest.TestCase): name = DOM.getAttr(cnode, key) component[name] - def wsdlTestAll(self): + def test_all(self): try: - self.wsdl = utils.setUpWsdl(self.path) + if self.path[:7] == 'http://': + self.wsdl = WSDLReader().loadFromURL(self.path) + else: + self.wsdl = WSDLReader().loadFromFile(self.path) + + except TimeoutError: + print "connection timed out" + sys.stdout.flush() + return except: self.path = self.path + ": load failed, unable to start" raise @@ -120,25 +127,34 @@ class WSDLToolsTestCase(unittest.TestCase): self.checkXSDCollection('simpleType', schema.types, node) -def makeTestSuite(section=None): - global configLoader - +def setUpOptions(section): + cp = ConfigParser.ConfigParser() + cp.read('config.txt') + if not cp.sections(): + print 'fatal error: configuration file config.txt not present' + sys.exit(0) + if not cp.has_section(section): + print '%s section not present in configuration file, exiting' % section + sys.exit(0) + return cp, len(cp.options(section)) + +def getOption(cp, section): + for name, value in cp.items(section): + yield value + +def makeTestSuite(section='services_by_file'): + global nameGenerator + + cp, numTests = setUpOptions(section) + nameGenerator = getOption(cp, section) suite = unittest.TestSuite() - configLoader = utils.MatchTestLoader(False, "config.py", "WSDLToolsTestCase") - if not section: - found = configLoader.setSection(sys.argv) - if not found: - configLoader.setSection("services_by_http") - else: - configLoader.setSection(section) - configLoader.testMethodPrefix = "wsdlTest" - suite.addTest(configLoader.loadTestsFromConfig(WSDLToolsTestCase)) + for i in range(0, numTests): + suite.addTest(unittest.makeSuite(WSDLToolsTestCase, 'test_')) return suite def main(): - loader = utils.MatchTestLoader(False, None, "makeTestSuite") - unittest.main(defaultTest="makeTestSuite", testLoader=loader) + unittest.main(defaultTest="makeTestSuite") if __name__ == "__main__" : main() diff --git a/test/test_wstools.py b/test/test_wstools.py index 76c4a53..0e0f958 100644 --- a/test/test_wstools.py +++ b/test/test_wstools.py @@ -7,11 +7,10 @@ import unittest, tarfile, os, ConfigParser import test_wsdl -import utils SECTION='files' -CONFIG_FILE = 'config.py' +CONFIG_FILE = 'config.txt' def extractFiles(section, option): config = ConfigParser.ConfigParser() @@ -31,8 +30,7 @@ def makeTestSuite(): def main(): extractFiles(SECTION, 'archives') - loader = utils.MatchTestLoader(True, None, "makeTestSuite") - unittest.main(defaultTest="makeTestSuite", testLoader=loader) + unittest.main(defaultTest="makeTestSuite") if __name__ == "__main__" : main() diff --git a/test/test_wstools_net.py b/test/test_wstools_net.py index 85145a2..880cff3 100644 --- a/test/test_wstools_net.py +++ b/test/test_wstools_net.py @@ -6,16 +6,14 @@ ########################################################################### import unittest import test_wsdl -import utils def makeTestSuite(): suite = unittest.TestSuite() - suite.addTest(test_wsdl.makeTestSuite(("no_schemas", "simpleTypes", "services_by_http"))) + suite.addTest(test_wsdl.makeTestSuite("services_by_http")) return suite def main(): - loader = utils.MatchTestLoader(True, None, "makeTestSuite") - unittest.main(defaultTest="makeTestSuite", testLoader=loader) + unittest.main(defaultTest="makeTestSuite") if __name__ == "__main__" : main()