testArrays.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Originally contributed by Stefan Schukat as part of this arbitrary-sized
  2. # arrays patch.
  3. from win32com.client import gencache
  4. from win32com.test import util
  5. import unittest
  6. ZeroD = 0
  7. OneDEmpty = []
  8. OneD = [1,2,3]
  9. TwoD = [
  10. [1,2,3],
  11. [1,2,3],
  12. [1,2,3]
  13. ]
  14. TwoD1 = [
  15. [
  16. [1,2,3,5],
  17. [1,2,3],
  18. [1,2,3]
  19. ],
  20. [
  21. [1,2,3],
  22. [1,2,3],
  23. [1,2,3]
  24. ]
  25. ]
  26. OneD1 = [
  27. [
  28. [1,2,3],
  29. [1,2,3],
  30. [1,2,3]
  31. ],
  32. [
  33. [1,2,3],
  34. [1,2,3]
  35. ]
  36. ]
  37. OneD2 = [
  38. [1,2,3],
  39. [1,2,3,4,5],
  40. [
  41. [1,2,3,4,5],
  42. [1,2,3,4,5],
  43. [1,2,3,4,5]
  44. ]
  45. ]
  46. ThreeD = [
  47. [
  48. [1,2,3],
  49. [1,2,3],
  50. [1,2,3]
  51. ],
  52. [
  53. [1,2,3],
  54. [1,2,3],
  55. [1,2,3]
  56. ]
  57. ]
  58. FourD = [
  59. [
  60. [[1,2,3],[1,2,3],[1,2,3]],
  61. [[1,2,3],[1,2,3],[1,2,3]],
  62. [[1,2,3],[1,2,3],[1,2,3]]
  63. ],
  64. [
  65. [[1,2,3],[1,2,3],[1,2,3]],
  66. [[1,2,3],[1,2,3],[1,2,3]],
  67. [[1,2,3],[1,2,3],[1,2,3]]
  68. ]
  69. ]
  70. LargeD = [
  71. [ [list(range(10))] * 10],
  72. ] * 512
  73. def _normalize_array(a):
  74. if type(a) != type(()):
  75. return a
  76. ret = []
  77. for i in a:
  78. ret.append(_normalize_array(i))
  79. return ret
  80. class ArrayTest(util.TestCase):
  81. def setUp(self):
  82. self.arr = gencache.EnsureDispatch("PyCOMTest.ArrayTest")
  83. def tearDown(self):
  84. self.arr = None
  85. def _doTest(self, array):
  86. self.arr.Array = array
  87. self.failUnlessEqual(_normalize_array(self.arr.Array), array)
  88. def testZeroD(self):
  89. self._doTest(ZeroD)
  90. def testOneDEmpty(self):
  91. self._doTest(OneDEmpty)
  92. def testOneD(self):
  93. self._doTest(OneD)
  94. def testTwoD(self):
  95. self._doTest(TwoD)
  96. def testThreeD(self):
  97. self._doTest(ThreeD)
  98. def testFourD(self):
  99. self._doTest(FourD)
  100. def testTwoD1(self):
  101. self._doTest(TwoD1)
  102. def testOneD1(self):
  103. self._doTest(OneD1)
  104. def testOneD2(self):
  105. self._doTest(OneD2)
  106. def testLargeD(self):
  107. self._doTest(LargeD)
  108. if __name__ == "__main__":
  109. try:
  110. util.testmain()
  111. except SystemExit as rc:
  112. if not rc:
  113. raise