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.
 
 
 

101 lines
2.9 KiB

  1. #!/usr/bin/env python
  2. ############################################################################
  3. # David W. Robertson, LBNL
  4. # See LBNLCopyright for copyright notice!
  5. ###########################################################################
  6. import sys, ConfigParser, unittest
  7. import StringIO
  8. from ZSI import wsdl2python
  9. from ZSI.wstools.WSDLTools import WSDLReader
  10. import utils
  11. """
  12. Unittest for the wsdl2python class
  13. """
  14. class Wsdl2pythonTest(unittest.TestCase):
  15. """Test case for wsdl2python.WriteServiceModule
  16. """
  17. def __init__(self, methodName='runTest'):
  18. unittest.TestCase.__init__(self, methodName)
  19. def setUp(self):
  20. global configLoader
  21. # not thread safe
  22. self.path = configLoader.nameGenerator.next()
  23. print self.path
  24. sys.stdout.flush()
  25. self.testdiff = utils.TestDiff(self)
  26. def tearDown(self):
  27. self.testdiff.close()
  28. def __str__(self):
  29. teststr = unittest.TestCase.__str__(self)
  30. if hasattr(self, "path"):
  31. return "%s: %s" % (teststr, self.path )
  32. else:
  33. return "%s" % (teststr)
  34. def test_Xmethods_services(self):
  35. try:
  36. wsdl = utils.setUpWsdl(self.path)
  37. except:
  38. self.path = self.path + ": load failed, unable to start"
  39. raise
  40. codegen = wsdl2python.WriteServiceModule(wsdl)
  41. f_types, f_services = codegen.get_module_names()
  42. hasSchema = len(codegen._wa.getSchemaDict())
  43. if hasSchema:
  44. strFile = StringIO.StringIO()
  45. self.testdiff.setDiffFile(f_types + ".py")
  46. try:
  47. codegen.write_service_types(f_types, strFile)
  48. except:
  49. self.path = self.path + ": write_service_types"
  50. raise
  51. if strFile.closed:
  52. print "trouble"
  53. self.testdiff.failUnlessEqual(strFile)
  54. strFile.close()
  55. strFile = StringIO.StringIO()
  56. self.testdiff.setDiffFile(f_services + ".py")
  57. try:
  58. signatures = codegen.write_services(f_types,
  59. f_services, strFile, hasSchema)
  60. except:
  61. self.path = self.path + ": write_services"
  62. raise
  63. self.testdiff.failUnlessEqual(strFile)
  64. strFile.close()
  65. def makeTestSuite(section=None):
  66. global configLoader
  67. suite = unittest.TestSuite()
  68. configLoader = utils.MatchTestLoader(False, "config.py", "Wsdl2pythonTest")
  69. if not section:
  70. found = configLoader.setSection(sys.argv)
  71. if not found:
  72. configLoader.setSection("services_by_http")
  73. else:
  74. configLoader.setSection(section)
  75. suite.addTest(configLoader.loadTestsFromConfig(Wsdl2pythonTest))
  76. return suite
  77. def foo():
  78. loader = utils.MatchTestLoader(False, "config.py", "makeTestSuite")
  79. unittest.main(defaultTest="makeTestSuite", testLoader=loader)
  80. if __name__ == "__main__" : foo()