Beispiel #1
0
    def test_parse_units(self):
        self.sbml_model.setTimeUnits('second')
        self.sbml_model.setSubstanceUnits('mole')
        self.sbml_model.setExtentUnits('mole')
        self.sbml_model.setVolumeUnits('litre')
        units = [
            unit_registry.parse_units('g'),
            unit_registry.parse_units('l'),
            unit_registry.parse_units('molecule'),
            unit_registry.parse_units('g/l'),
            unit_registry.parse_units('g/s'),
            unit_registry.parse_units('g/s**2'),
            unit_registry.parse_units('g/(l * ms)^2'),
            unit_registry.parse_units('gDCW / s'),
        ]
        for unit in units:
            LibSbmlInterface.create_unit(unit, self.sbml_model)

        exp_units = {
            'second': unit_registry.parse_units('second'),
            'mole': unit_registry.parse_units('molecule'),
            'litre': unit_registry.parse_units('liter'),
            'unit_gram_per_liter': units[3],
            'unit_gram_per_second': units[4],
            'unit_gram_per_second_pow_2': units[5],
            'unit_gram_per_liter_pow_2_per_millisecond_pow_2': units[6],
            'unit_gDCW_per_second': units[7],
        }
        parsed_units = LibSbmlInterface.parse_units(self.sbml_model)
        self.assertEqual(parsed_units.keys(), exp_units.keys())
        for key in exp_units:
            self.assertTrue(
                are_units_equivalent(parsed_units[key], exp_units[key]),
                '{} != {}'.format(str(parsed_units[key]), str(exp_units[key])))
Beispiel #2
0
 def test_parse_units_error(self):
     with self.assertRaisesRegex(LibSbmlError, 'units must be set'):
         LibSbmlInterface.parse_units(self.sbml_model)