MCPcopy Create free account
hub / github.com/vispy/vispy / test_Variable

Function test_Variable

vispy/visuals/shaders/tests/test_function.py:165–225  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163
164
165def test_Variable():
166
167 # Test init fail
168 assert_raises(TypeError, Variable) # no args
169 assert_raises(TypeError, Variable, 3) # wrong type
170 assert_raises(TypeError, Variable, "name", "str") # wrong type
171 assert_raises(ValueError, Variable, 'bla bla') # need correct vtype
172 assert_raises(ValueError, Variable, 'uniform b l a') # too many
173
174 # Test init success
175 var = Variable('uniform float bla') # Finally
176 assert_equal(var.name, 'bla')
177 assert_equal(var.dtype, 'float')
178 assert_equal(var.vtype, 'uniform')
179 assert var.value is None
180
181 # test assign new value
182 var.value = 10.
183 assert_equal(var.dtype, 'float') # type is locked; won't change
184
185 # test name-only init
186 var = Variable('bla') # Finally
187 assert_equal(var.name, 'bla')
188 assert_equal(var.dtype, None)
189 assert_equal(var.vtype, None)
190 assert var.value is None
191
192 # test assign new value
193 var.value = 10
194 assert_equal(var.dtype, 'int')
195 assert_equal(var.vtype, 'uniform')
196 assert_equal(var.value, 10)
197
198 # test init with value
199 var = Variable('bla', (1, 2, 3)) # Also valid
200 assert_equal(var.name, 'bla')
201 assert_equal(var.dtype, 'vec3')
202 assert_equal(var.vtype, 'uniform')
203 assert_equal(var.value, (1, 2, 3))
204
205 # Test value
206 # var = Variable('uniform float bla', data) # Also valid
207 # assert_equal(var.value, data)
208 # var.value = 3
209 # assert_equal(var.value, 3)
210
211 # Test repr
212 var = Variable('uniform float bla')
213 assert_in('uniform float bla', var.compile())
214
215 # Test injection, definition, dependencies
216 assert_equal(var.expression({var: 'xxx'}), 'xxx')
217 assert_equal(var.definition({var: 'xxx'}, ('120', ''), None),
218 'uniform float xxx;')
219 assert_in(var, var.dependencies())
220
221 # Renaming
222 var = Variable('uniform float bla')

Callers

nothing calls this directly

Calls 8

expressionMethod · 0.95
definitionMethod · 0.95
assert_raisesFunction · 0.90
VariableClass · 0.90
assert_equalFunction · 0.90
assert_inFunction · 0.90
dependenciesMethod · 0.80
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…