test_decimal.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. from decimal import Decimal
  2. import pytest
  3. from shapely import (
  4. GeometryCollection,
  5. LinearRing,
  6. LineString,
  7. MultiLineString,
  8. MultiPoint,
  9. MultiPolygon,
  10. Point,
  11. Polygon,
  12. )
  13. items2d = [
  14. [(0.0, 0.0), (70.0, 120.0), (140.0, 0.0), (0.0, 0.0)],
  15. [(60.0, 80.0), (80.0, 80.0), (70.0, 60.0), (60.0, 80.0)],
  16. ]
  17. items2d_mixed = [
  18. [
  19. (Decimal("0.0"), Decimal("0.0")),
  20. (Decimal("70.0"), 120.0),
  21. (140.0, Decimal("0.0")),
  22. (0.0, 0.0),
  23. ],
  24. [
  25. (Decimal("60.0"), Decimal("80.0")),
  26. (Decimal("80.0"), 80.0),
  27. (70.0, Decimal("60.0")),
  28. (60.0, 80.0),
  29. ],
  30. ]
  31. items2d_decimal = [
  32. [
  33. (Decimal("0.0"), Decimal("0.0")),
  34. (Decimal("70.0"), Decimal("120.0")),
  35. (Decimal("140.0"), Decimal("0.0")),
  36. (Decimal("0.0"), Decimal("0.0")),
  37. ],
  38. [
  39. (Decimal("60.0"), Decimal("80.0")),
  40. (Decimal("80.0"), Decimal("80.0")),
  41. (Decimal("70.0"), Decimal("60.0")),
  42. (Decimal("60.0"), Decimal("80.0")),
  43. ],
  44. ]
  45. items3d = [
  46. [(0.0, 0.0, 1), (70.0, 120.0, 2), (140.0, 0.0, 3), (0.0, 0.0, 1)],
  47. [(60.0, 80.0, 1), (80.0, 80.0, 2), (70.0, 60.0, 3), (60.0, 80.0, 1)],
  48. ]
  49. items3d_mixed = [
  50. [
  51. (Decimal("0.0"), Decimal("0.0"), Decimal(1)),
  52. (Decimal("70.0"), 120.0, Decimal(2)),
  53. (140.0, Decimal("0.0"), 3),
  54. (0.0, 0.0, 1),
  55. ],
  56. [
  57. (Decimal("60.0"), Decimal("80.0"), Decimal(1)),
  58. (Decimal("80.0"), 80.0, 2),
  59. (70.0, Decimal("60.0"), Decimal(3)),
  60. (60.0, 80.0, 1),
  61. ],
  62. ]
  63. items3d_decimal = [
  64. [
  65. (Decimal("0.0"), Decimal("0.0"), Decimal(1)),
  66. (Decimal("70.0"), Decimal("120.0"), Decimal(2)),
  67. (Decimal("140.0"), Decimal("0.0"), Decimal(3)),
  68. (Decimal("0.0"), Decimal("0.0"), Decimal(1)),
  69. ],
  70. [
  71. (Decimal("60.0"), Decimal("80.0"), Decimal(1)),
  72. (Decimal("80.0"), Decimal("80.0"), Decimal(2)),
  73. (Decimal("70.0"), Decimal("60.0"), Decimal(3)),
  74. (Decimal("60.0"), Decimal("80.0"), Decimal(1)),
  75. ],
  76. ]
  77. all_geoms = [
  78. [
  79. Point(items[0][0]),
  80. Point(*items[0][0]),
  81. MultiPoint(items[0]),
  82. LinearRing(items[0]),
  83. LineString(items[0]),
  84. MultiLineString(items),
  85. Polygon(items[0]),
  86. MultiPolygon(
  87. [
  88. Polygon(items[1]),
  89. Polygon(items[0], holes=items[1:]),
  90. ]
  91. ),
  92. GeometryCollection([Point(items[0][0]), Polygon(items[0])]),
  93. ]
  94. for items in [
  95. items2d,
  96. items2d_mixed,
  97. items2d_decimal,
  98. items3d,
  99. items3d_mixed,
  100. items3d_decimal,
  101. ]
  102. ]
  103. @pytest.mark.parametrize("geoms", list(zip(*all_geoms)))
  104. def test_decimal(geoms):
  105. assert geoms[0] == geoms[1] == geoms[2]
  106. assert geoms[3] == geoms[4] == geoms[5]