Esempio n. 1
0
def test_internal_cpp_api():
    # Following github issue 8197.
    import matplotlib._tri as _tri

    # C++ Triangulation.
    with pytest.raises(TypeError) as excinfo:
        triang = _tri.Triangulation()
    excinfo.match(r'function takes exactly 7 arguments \(0 given\)')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation([], [1], [[]], None, None, None, False)
    excinfo.match(r'x and y must be 1D arrays of the same length')

    x = [0, 1, 1]
    y = [0, 0, 1]
    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, [[0, 1]], None, None, None, False)
    excinfo.match(r'triangles must be a 2D array of shape \(\?,3\)')

    tris = [[0, 1, 2]]
    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, [0, 1], None, None, False)
    excinfo.match(r'mask must be a 1D array with the same length as the ' +
                  r'triangles array')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, None, [[1]], None, False)
    excinfo.match(r'edges must be a 2D array with shape \(\?,2\)')

    with pytest.raises(ValueError) as excinfo:
        triang = _tri.Triangulation(x, y, tris, None, None, [[-1]], False)
    excinfo.match(r'neighbors must be a 2D array with the same shape as the ' +
                  r'triangles array')

    triang = _tri.Triangulation(x, y, tris, None, None, None, False)

    with pytest.raises(ValueError) as excinfo:
        triang.calculate_plane_coefficients([])
    excinfo.match(r'z array must have same length as triangulation x and y ' +
                  r'arrays')

    with pytest.raises(ValueError) as excinfo:
        triang.set_mask([0, 1])
    excinfo.match(r'mask must be a 1D array with the same length as the ' +
                  r'triangles array')

    # C++ TriContourGenerator.
    with pytest.raises(TypeError) as excinfo:
        tcg = _tri.TriContourGenerator()
    excinfo.match(r'function takes exactly 2 arguments \(0 given\)')

    with pytest.raises(ValueError) as excinfo:
        tcg = _tri.TriContourGenerator(triang, [1])
    excinfo.match(r'z must be a 1D array with the same length as the x and ' +
                  r'y arrays')

    z = [0, 1, 2]
    tcg = _tri.TriContourGenerator(triang, z)

    with pytest.raises(ValueError) as excinfo:
        tcg.create_filled_contour(1, 0)
    excinfo.match(r'filled contour levels must be increasing')

    # C++ TrapezoidMapTriFinder.
    with pytest.raises(TypeError) as excinfo:
        trifinder = _tri.TrapezoidMapTriFinder()
    excinfo.match(r'function takes exactly 1 argument \(0 given\)')

    trifinder = _tri.TrapezoidMapTriFinder(triang)

    with pytest.raises(ValueError) as excinfo:
        trifinder.find_many([0], [0, 1])
    excinfo.match(r'x and y must be array_like with same shape')
Esempio n. 2
0
 def __init__(self, triangulation):
     TriFinder.__init__(self, triangulation)
     self._cpp_trifinder = _tri.TrapezoidMapTriFinder(
         triangulation.get_cpp_triangulation())
     self._initialize()
 def __init__(self, triangulation):
     from matplotlib import _tri
     TriFinder.__init__(self, triangulation)
     self._cpp_trifinder = _tri.TrapezoidMapTriFinder(
         triangulation.get_cpp_triangulation())
     self._initialize()