code: def test_multipolygon(self):
      # Empty
      geom = MultiPolygon([])
      assert geom.is_empty
      assert len(geom.geoms) == 0
  
      # From coordinate tuples
      coords = [
          (
              ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
              [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))],
          )
      ]
      geom = MultiPolygon(coords)
      assert isinstance(geom, MultiPolygon)
      assert len(geom.geoms) == 1
      assert dump_coords(geom) == [
          [
              (0.0, 0.0),
              (0.0, 1.0),
              (1.0, 1.0),
              (1.0, 0.0),
              (0.0, 0.0),
              [
                  (0.25, 0.25),
                  (0.25, 0.5),
                  (0.5, 0.5),
                  (0.5, 0.25),
                  (0.25, 0.25),
              ],
          ]
      ]
  
      # Or without holes
      coords2 = [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),)]
      geom = MultiPolygon(coords2)
      assert isinstance(geom, MultiPolygon)
      assert len(geom.geoms) == 1
      assert dump_coords(geom) == [
          [
              (0.0, 0.0),
              (0.0, 1.0),
              (1.0, 1.0),
              (1.0, 0.0),
              (0.0, 0.0),
          ]
      ]
  
      # Or from polygons
      p = Polygon(
          ((0, 0), (0, 1), (1, 1), (1, 0)),
          [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))],
      )
      geom = MultiPolygon([p])
      assert len(geom.geoms) == 1
      assert dump_coords(geom) == [
          [
              (0.0, 0.0),
              (0.0, 1.0),
              (1.0, 1.0),
              (1.0, 0.0),
              (0.0, 0.0),
              [
                  (0.25, 0.25),
                  (0.25, 0.5),
                  (0.5, 0.5),
                  (0.5, 0.25),
                  (0.25, 0.25),
              ],
          ]
      ]
  
      # None and empty polygons are dropped
      geom_from_list_with_empty = MultiPolygon([p, None, Polygon()])
      assert geom_from_list_with_empty == geom
  
      # Or from a list of multiple polygons
      geom_multiple_from_list = MultiPolygon([p, p])
      assert len(geom_multiple_from_list.geoms) == 2
      assert all(
          p == geom.geoms[0] for p in geom_multiple_from_list.geoms
      )
  
      # Or from a np.array of polygons
      geom_multiple_from_array = MultiPolygon(np.array([p, p]))
      assert geom_multiple_from_array == geom_multiple_from_list
  
      # Or from another multi-polygon
      geom2 = MultiPolygon(geom)
      assert len(geom2.geoms) == 1
      assert dump_coords(geom2) == [
          [
              (0.0, 0.0),
              (0.0, 1.0),
              (1.0, 1.0),
              (1.0, 0.0),
              (0.0, 0.0),
              [
                  (0.25, 0.25),
                  (0.25, 0.5),
                  (0.5, 0.5),
                  (0.5, 0.25),
                  (0.25, 0.25),
              ],
          ]
      ]
  
      # Sub-geometry Access
      assert isinstance(geom.geoms[0], Polygon)
      assert dump_coords(geom.geoms[0]) == [
          (0.0, 0.0),
          (0.0, 1.0),
          (1.0, 1.0),
          (1.0, 0.0),
          (0.0, 0.0),
          [
              (0.25, 0.25),
              (0.25, 0.5),
              (0.5, 0.5),
              (0.5, 0.25),
              (0.25, 0.25),
          ],
      ]
      with pytest.raises(IndexError):  # index out of range
          geom.geoms[1]
  
      # Geo interface
      assert geom.__geo_interface__ == {
          "type": "MultiPolygon",
          "coordinates": [
              (
                  (
                      (0.0, 0.0),
                      (0.0, 1.0),
                      (1.0, 1.0),
                      (1.0, 0.0),
                      (0.0, 0.0),
                  ),
                  (
                      (0.25, 0.25),
                      (0.25, 0.5),
                      (0.5, 0.5),
                      (0.5, 0.25),
                      (0.25, 0.25),
                  ),
              )
          ],
      }
  
file_path: shapely/shapely/tests/geometry/test_multipolygon.py
imports: import numpy
  import pytest
  from shapely import MultiPolygon, Polygon
  from shapely.geometry.base import dump_coords
  from shapely.tests.geometry.test_multi import MultiGeometryTestCase
label_desc: Use image node_id 1 for calling the TestMultiPolygon obj's underlying member method code with example usage: obj.test_multipolygon() without return types