Repository: matplotlib/matplotlib
File: lib/matplotlib/tests/test_path.py (Python)

Code before:
                       [data])
    assert_array_equal(p.to_polygons(), [])
    assert_array_equal(p.to_polygons(closed_only=False), [data])

    data = [[10, 10], [20, 20], [30, 30]]
    closed_data = [[10, 10], [20, 20], [30, 30], [10, 10]]
    p = Path(data)

    assert_array_equal(p.to_polygons(width=40, height=40), [closed_data])
    assert_array_equal(p.to_polygons(width=40, height=40, closed_only=False),
                       [data])
    assert_array_equal(p.to_polygons(), [closed_data])
    assert_array_equal(p.to_polygons(closed_only=False), [data])


def test_path_deepcopy():
    # Should not raise any error
    verts = [[0, 0], [1, 1]]
    codes = [Path.MOVETO, Path.LINETO]
    path1 = Path(verts, readonly=True)
    path2 = Path(verts, codes, readonly=True)
    path1_copy = path1.deepcopy()
    path2_copy = path2.deepcopy()
    assert path1 is not path1_copy
    assert path1.vertices is not path1_copy.vertices
    assert np.all(path1.vertices == path1_copy.vertices)
    assert path1.readonly
    assert not path1_copy.readonly
    assert path2 is not path2_copy
    assert path2.vertices is not path2_copy.vertices
    assert np.all(path2.vertices == path2_copy.vertices)
    assert path2.codes is not path2_copy.codes
    assert all(path2.codes == path2_copy.codes)
    assert path2.readonly
    assert not path2_copy.readonly


def test_path_deepcopy_cycle():
    class PathWithCycle(Path):
        def __init__(self, x, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.x = self

    p = PathWithCycle(1, [[0, 0], [1, 1]], readonly=True)
    p_copy = p.deepcopy()
    assert p_copy is not p
    assert p.readonly
    assert not p_copy.readonly
    assert p_copy.x is p_copy

    class PathWithCycle2(Path):

Review comment (suggestion):
```suggestion
    assert_array_equal(path1.vertices, path1_copy.vertices)
```

Code after:
                       [data])
    assert_array_equal(p.to_polygons(), [])
    assert_array_equal(p.to_polygons(closed_only=False), [data])

    data = [[10, 10], [20, 20], [30, 30]]
    closed_data = [[10, 10], [20, 20], [30, 30], [10, 10]]
    p = Path(data)

    assert_array_equal(p.to_polygons(width=40, height=40), [closed_data])
    assert_array_equal(p.to_polygons(width=40, height=40, closed_only=False),
                       [data])
    assert_array_equal(p.to_polygons(), [closed_data])
    assert_array_equal(p.to_polygons(closed_only=False), [data])


def test_path_deepcopy():
    # Should not raise any error
    verts = [[0, 0], [1, 1]]
    codes = [Path.MOVETO, Path.LINETO]
    path1 = Path(verts, readonly=True)
    path2 = Path(verts, codes, readonly=True)
    path1_copy = path1.deepcopy()
    path2_copy = path2.deepcopy()
    assert path1 is not path1_copy
    assert path1.vertices is not path1_copy.vertices
    assert_array_equal(path1.vertices, path1_copy.vertices)
    assert path1.readonly
    assert not path1_copy.readonly
    assert path2 is not path2_copy
    assert path2.vertices is not path2_copy.vertices
    assert_array_equal(path2.vertices, path2_copy.vertices)
    assert path2.codes is not path2_copy.codes
    assert_array_equal(path2.codes, path2_copy.codes)
    assert path2.readonly
    assert not path2_copy.readonly


def test_path_deepcopy_cycle():
    class PathWithCycle(Path):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.x = self

    p = PathWithCycle([[0, 0], [1, 1]], readonly=True)
    p_copy = p.deepcopy()
    assert p_copy is not p
    assert p.readonly
    assert not p_copy.readonly
    assert p_copy.x is p_copy

    class PathWithCycle2(Path):