Package tests :: Module test_texture
[hide private]
[frames] | no frames]

Source Code for Module tests.test_texture

 1  import numpy 
 2   
 3  from glitter import Texture3D, Datatype, EnumConstant, Texture, uint8, int8, uint16, int16, uint32, int32, float32 
 4   
5 -def check_texture(shape, dtype, vrange):
6 minval, maxval = vrange 7 data = ((maxval - minval) * numpy.random.random(shape) + minval).astype(dtype.as_numpy()) 8 texture = Texture3D(data) 9 assert (texture.data == data).all(), "data is broken" 10 assert texture.shape == data.shape, "shape is broken (was %s, is %s)" % (data.shape, texture.shape) 11 assert texture.dtype == Datatype.from_numpy(data.dtype), "dtype is broken (was %s, is %s)" % (Datatype.from_numpy(data.dtype), texture.dtype)
12
13 -def test_texture_generator():
14 shapes = ((4, 4, 4, 4), (4, 4, 4, 3), (4, 16, 8, 3), (5, 4, 4, 3), (5, 5, 5, 3), (6, 6, 6, 3), (7, 13, 5, 3), (1, 1, 3, 3)) 15 dtypes = (uint8, int8, uint16, int16, uint32, int32, float32) 16 vranges = ((0, (1<<8)-1), (-1<<7, (1<<7)-1), (0, (1<<16)-1), (-1<<15, (1<<15)-1), (0, (1<<32)-1), (-1<<31, (1<<31)-1), (-10.0, 10.0)) 17 18 for shape in shapes: 19 for dtype, vrange in zip(dtypes, vranges): 20 yield check_texture, shape, dtype, vrange
21
22 -def check_property(texture, name):
23 value = getattr(texture, name) 24 if isinstance(value, EnumConstant): 25 valid_values = value._enum._reverse_dict.values() 26 for value in valid_values: 27 setattr(texture, name, value) 28 assert getattr(texture, name) == value, "property %s is broken" % name 29 else: 30 setattr(texture, name, value) 31 assert getattr(texture, name) == value, "property %s is broken" % name
32
33 -def test_property_generator():
34 texture = Texture3D(numpy.random.random((1, 1, 1, 4)).astype(numpy.float32)) 35 properties = [x for x in dir(texture) if x != "sampler" and not x.startswith("_") and type(getattr(Texture, x)) == property] 36 37 for p in properties: 38 if p in ("data", "shape", "dtype"): 39 continue 40 if getattr(Texture, p).fset is None: 41 continue 42 yield check_property, texture, p
43