1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
from __future__ import annotations
import pytest
import pyvista as pv
from pyvista.plotting.volume_property import VolumeProperty
@pytest.fixture()
def vol_prop():
return VolumeProperty()
def test_volume_lookup_table(vol_prop, skip_check_gc):
lut = pv.LookupTable(cmap='bwr')
lut.apply_opacity([1.0, 0.0, 0.0, 0.3, 0.0, 0.0, 0.0, 0.3])
orig = vol_prop.GetRGBTransferFunction()
vol_prop.apply_lookup_table(lut)
assert vol_prop.GetRGBTransferFunction() is not orig
def test_interpolation_type(vol_prop):
assert isinstance(vol_prop.interpolation_type, str)
for interpolation_type in ['nearest', 'linear']:
vol_prop.interpolation_type = interpolation_type
assert vol_prop.interpolation_type == interpolation_type
with pytest.raises(ValueError, match='must be either'):
vol_prop.interpolation_type = 'not valid'
def test_volume_property_shade(vol_prop):
assert isinstance(vol_prop.shade, bool)
vol_prop.shade = True
assert vol_prop.shade is True
vol_prop.shade = False
assert vol_prop.shade is False
def test_volume_independent_components(vol_prop):
assert isinstance(vol_prop.independent_components, bool)
vol_prop.independent_components = True
assert vol_prop.independent_components is True
vol_prop.independent_components = False
assert vol_prop.independent_components is False
def test_volume_property_ambient(vol_prop):
assert isinstance(vol_prop.ambient, float)
value = 0.45
vol_prop.ambient = value
assert vol_prop.ambient == value
def test_volume_property_diffuse(vol_prop):
assert isinstance(vol_prop.diffuse, float)
value = 0.45
vol_prop.diffuse = value
assert vol_prop.diffuse == value
def test_volume_property_specular(vol_prop):
assert isinstance(vol_prop.specular, float)
value = 0.45
vol_prop.specular = value
assert vol_prop.specular == value
def test_volume_property_specular_power(vol_prop):
assert isinstance(vol_prop.specular_power, float)
value = 0.45
vol_prop.specular_power = value
assert vol_prop.specular_power == value
def test_volume_property_copy(vol_prop):
vol_prop.ambient = 1.0
vol_prop_copy = vol_prop.copy()
assert vol_prop_copy.ambient == vol_prop.ambient
def test_volume_property_repr(vol_prop):
assert 'Interpolation type:' in repr(vol_prop)
assert "nearest" in repr(vol_prop)
|