MCPcopy Create free account
hub / github.com/Cantera/cantera / test_set_quantity

Method test_set_quantity

test/python/test_utils.py:300–326  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

298 assert self.data['group2'].convert('x', 'J/kg') == 1300 * 1e6
299
300 def test_set_quantity(self):
301 params = ct.AnyMap()
302 params.set_quantity('spam', [2, 3, 4], 'Gg')
303 params.set_quantity('eggs', 10, ct.Units('kg/m^3'))
304 params.set_activation_energy('beans', 5, 'K')
305
306 converted = _py_to_anymap_to_py(params)
307 assert converted['spam'] == [2e6, 3e6, 4e6]
308 assert converted['eggs'] == approx(10)
309 assert converted['beans'] == approx(5 * ct.gas_constant)
310
311 # Unit conversions are deferred
312 outer = ct.AnyMap()
313 outer['units'] = {'mass': 'g', 'activation-energy': 'K'}
314 outer['inner'] = params
315 converted = _py_to_anymap_to_py(outer)
316 assert converted['inner']['spam'] == approx([2e9, 3e9, 4e9])
317 assert converted['inner']['eggs'] == approx(10e3)
318 assert converted['inner']['beans'] == approx(5)
319
320 outer.set_quantity('cheese', {'gouda': 5.5}, 'J/kg')
321 with pytest.raises(ct.CanteraError):
322 _py_to_anymap_to_py(outer)
323
324 outer.set_activation_energy('cheese', 12, 'V/m')
325 with pytest.raises(ct.CanteraError):
326 _py_to_anymap_to_py(outer)
327
328class TestListDataFiles:
329

Callers

nothing calls this directly

Calls 2

AnyMapMethod · 0.80
UnitsMethod · 0.80

Tested by

no test coverage detected