Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_init():
with pytest.raises(ValueError):
mesh = pyvista.PolyData(np.array([1]))
with pytest.raises(TypeError):
mesh = pyvista.PolyData(np.array([1]), 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa', 'woa')
def test_invalid_init():
with pytest.raises(ValueError):
mesh = pyvista.PolyData(np.array([1]))
with pytest.raises(TypeError):
mesh = pyvista.PolyData(np.array([1]), 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa', 'woa')
def test_background_plotting_orbit(qtbot):
plotter = pyvista.BackgroundPlotter(show=False, title='Testing Window')
plotter.add_mesh(pyvista.Sphere())
# perfrom the orbit:
plotter.orbit_on_path(bkg=False, step=0.0)
plotter.close()
def test_table_init(tmpdir):
"""Save some delimited text to a file and read it"""
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % 'csv'))
nr, nc = 50, 3
arrays = np.random.rand(nr, nc)
# Create from 2D array
table = pyvista.Table(arrays)
assert table.n_rows == nr
assert table.n_columns == nc
assert table.n_arrays == nc
assert len(table.row_arrays) == nc
for i in range(nc):
assert np.allclose(arrays[:,i], table[i])
# create from dictionary
array_dict = {}
for i in range(nc):
array_dict['foo{}'.format(i)] = arrays[:, i].copy()
table = pyvista.Table(array_dict)
assert table.n_rows == nr
assert table.n_columns == nc
def test_volume_rendering():
# Really just making sure no errors are thrown
vol = examples.load_uniform()
vol.plot(off_screen=OFF_SCREEN, volume=True, opacity='linear')
plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
plotter.add_volume(vol, opacity='sigmoid', cmap='jet', n_colors=15)
plotter.show()
# Now test MultiBlock rendering
data = pyvista.MultiBlock(dict(a=examples.load_uniform(),
b=examples.load_uniform(),
c=examples.load_uniform(),
d=examples.load_uniform(),))
data['a'].rename_array('Spatial Point Data', 'a')
data['b'].rename_array('Spatial Point Data', 'b')
data['c'].rename_array('Spatial Point Data', 'c')
data['d'].rename_array('Spatial Point Data', 'd')
data.plot(off_screen=OFF_SCREEN, volume=True, multi_colors=True, )
def test_plot_label_fmt():
plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
plotter.add_mesh(sphere)
plotter.show_bounds(xlabel='My X', fmt=r'%.3f')
plotter.show()
def test_plot_invalid_add_scalar_bar():
with pytest.raises(Exception):
plotter = pyvista.Plotter()
plotter.add_scalar_bar()
def test_download_office():
data = examples.download_office()
assert data.n_cells
def test_download_tri_quadratic_hexahedron():
data = examples.download_tri_quadratic_hexahedron()
assert data.n_cells
def test_hanlde_array_with_null_name():
poly = pyvista.PolyData()
# Add point array with no name
poly.GetPointData().AddArray(pyvista.convert_array(np.array([])))
html = poly._repr_html_()
assert html is not None
pdata = poly.point_arrays
assert pdata is not None
assert len(pdata) == 1
# Add cell array with no name
poly.GetCellData().AddArray(pyvista.convert_array(np.array([])))
html = poly._repr_html_()
assert html is not None
cdata = poly.cell_arrays
assert cdata is not None
assert len(cdata) == 1
# Add field array with no name
poly.GetFieldData().AddArray(pyvista.convert_array(np.array([5, 6])))