Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

testPippo.py 2.6KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import sys
  2. import unittest
  3. import pythoncom
  4. from win32com.client import Dispatch
  5. from win32com.client.gencache import EnsureDispatch
  6. class PippoTester(unittest.TestCase):
  7. def setUp(self):
  8. from win32com.test import pippo_server
  9. from win32com.test.util import RegisterPythonServer
  10. RegisterPythonServer(pippo_server.__file__, "Python.Test.Pippo")
  11. # create it.
  12. self.object = Dispatch("Python.Test.Pippo")
  13. def testLeaks(self):
  14. try:
  15. gtrc = sys.gettotalrefcount
  16. except AttributeError:
  17. print("Please run this with python_d for leak tests")
  18. gtrc = lambda: 0
  19. # note creating self.object() should have consumed our "one time" leaks
  20. self.object.Method1()
  21. start = gtrc()
  22. for i in range(1000):
  23. object = Dispatch("Python.Test.Pippo")
  24. object.Method1()
  25. object = None
  26. end = gtrc()
  27. if end - start > 5:
  28. self.fail("We lost %d references!" % (end - start,))
  29. def testResults(self):
  30. rc, out1 = self.object.Method2(123, 111)
  31. self.assertEqual(rc, 123)
  32. self.assertEqual(out1, 222)
  33. def testPythonArrays(self):
  34. self._testArray([-3, -2, -1, 0, 1, 2, 3])
  35. self._testArray([-3.14, -2, -0.1, 0.0, 1.1, 2.5, 3])
  36. def testNumpyArrays(self):
  37. try:
  38. import numpy
  39. except:
  40. print("Numpy test not possible because numpy module failed to import")
  41. return
  42. self._testArray(numpy.array([-3, -2, -1, 0, 1, 2, 3]))
  43. self._testArray(numpy.array([-3.14, -2, -0.1, 0.0, 1.1, 2.5, 3]))
  44. def testByteArrays(self):
  45. if "bytes" in dir(__builtins__):
  46. # Use eval to avoid compilation error in Python 2.
  47. self._testArray(eval("b'abcdef'"))
  48. self._testArray(eval("bytearray(b'abcdef')"))
  49. def _testArray(self, inArray):
  50. outArray = self.object.Method3(inArray)
  51. self.assertEqual(list(outArray), list(inArray))
  52. def testLeaksGencache(self):
  53. try:
  54. gtrc = sys.gettotalrefcount
  55. except AttributeError:
  56. print("Please run this with python_d for leak tests")
  57. gtrc = lambda: 0
  58. # note creating self.object() should have consumed our "one time" leaks
  59. object = EnsureDispatch("Python.Test.Pippo")
  60. start = gtrc()
  61. for i in range(1000):
  62. object = EnsureDispatch("Python.Test.Pippo")
  63. object.Method1()
  64. object = None
  65. end = gtrc()
  66. if end - start > 10:
  67. self.fail("We lost %d references!" % (end - start,))
  68. if __name__ == "__main__":
  69. unittest.main()