You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 lines
3.1 KiB

  1. ############################################################################
  2. # David W. Robertson, LBNL
  3. # See Copyright for copyright notice!
  4. ###########################################################################
  5. import sys, ConfigParser, unittest
  6. import StringIO
  7. from ZSI import wsdl2python
  8. #from pyGridWare import wsdl2python
  9. from ZSI.wstools.WSDLTools import WSDLReader
  10. from pyGridWare.test import utils
  11. """
  12. Unittest for the wsdl2python class
  13. """
  14. def setUpWsdl(path):
  15. if path[:7] == 'http://':
  16. wsdl = WSDLReader().loadFromURL(path)
  17. else:
  18. wsdl = WSDLReader().loadFromFile(path)
  19. return wsdl
  20. class Wsdl2pythonTest(unittest.TestCase):
  21. """Test case for wsdl2python.WriteServiceModule
  22. """
  23. def __init__(self, methodName='runTest'):
  24. global configLoader
  25. unittest.TestCase.__init__(self, methodName)
  26. def setUp(self):
  27. # not thread safe
  28. self.path = configLoader.nameGenerator.next()
  29. print self.path
  30. sys.stdout.flush()
  31. self.testdiff = utils.TestDiff(self)
  32. self.wsdl = configLoader.nameGenerator.next()
  33. def tearDown(self):
  34. if self.wsdl is not None:
  35. del self.wsdl
  36. self.testdiff.close()
  37. def __str__(self):
  38. teststr = unittest.TestCase.__str__(self)
  39. if hasattr(self, "path"):
  40. return "%s: %s" % (teststr, self.path )
  41. else:
  42. return "%s" % (teststr)
  43. def do_diffs(self, choice):
  44. self.failUnless(self.wsdl is not None, "Unable to start, load failed")
  45. codegen = wsdl2python.WriteServiceModule(self.wsdl)
  46. f_types, f_services = codegen.get_module_names()
  47. strFile = StringIO.StringIO()
  48. if choice == "service_types":
  49. self.testdiff.setDiffFile(f_types + ".py")
  50. codegen.write_service_types(f_types, strFile)
  51. else:
  52. self.testdiff.setDiffFile(f_services + ".py")
  53. codegen.write_services(f_types, f_services, strFile)
  54. self.testdiff.failUnlessEqual(strFile)
  55. strFile.close()
  56. def test_Xmethods_service_types(self):
  57. # add exception for url not found
  58. self.do_diffs("service_types")
  59. def test_Xmethods_services(self):
  60. self.do_diffs("services")
  61. def makeTestSuite(topLevel=False, config=None):
  62. global configLoader
  63. suite = unittest.TestSuite()
  64. if not hasattr(sys.modules[__name__], "configLoader"):
  65. if not config:
  66. configLoader = utils.MatchTestLoader(False, "config.py",
  67. "Wsdl2pythonTest")
  68. else:
  69. configLoader = config
  70. configLoader.testMethodPrefix = "test"
  71. suite.addTest(configLoader.loadTestsFromConfig(Wsdl2pythonTest,
  72. "services_by_http",
  73. valueFunc = setUpWsdl))
  74. return suite
  75. def main():
  76. global configLoader
  77. configLoader = utils.MatchTestLoader(False, "config.py", "makeTestSuite")
  78. unittest.main(defaultTest="makeTestSuite", testLoader=configLoader)
  79. if __name__ == "__main__" : main()