def test_merge(self): model = native.NativeModel() model.compounds.update([ entry.DictCompoundEntry({ 'id': 'g6p_c', 'name': 'G6P' }), entry.DictCompoundEntry({ 'id': 'g6p_e', 'name': 'G6P' }) ]) model.reactions.update([ entry.DictReactionEntry({ 'id': 'TP_g6p', 'equation': parse_reaction('g6p_c[c] <=> g6p_e[e]') }) ]) exchange_compound = Compound('g6p_e', 'e') model.exchange[exchange_compound] = (exchange_compound, 'EX_g6p_e', -10, 0) sbml.merge_equivalent_compounds(model) self.assertEqual({entry.id for entry in model.compounds}, {'g6p'}) self.assertEqual(model.reactions['TP_g6p'].equation, parse_reaction('g6p[c] <=> g6p[e]')) new_exchange_compound = Compound('g6p', 'e') self.assertEqual(model.exchange[new_exchange_compound], (new_exchange_compound, 'EX_g6p_e', -10, 0))
def test_write_compounds(self): stream = StringIO() compounds = [ entry.DictCompoundEntry({ 'id': 'c1', 'name': 'Compound 1', 'charge': 2, 'custom': 34.5 }), entry.DictCompoundEntry({ 'id': 'c2', 'name': 'Compound 2', 'formula': Formula.parse('H2O') }) ] self.writer.write_compounds(stream, compounds) self.assertEqual(yaml.safe_load(stream.getvalue()), [{ 'id': 'c1', 'name': 'Compound 1', 'charge': 2, 'custom': 34.5 }, { 'id': 'c2', 'name': 'Compound 2', 'formula': 'H2O' }])
def test_create_compound_dict_entry_copy(self): props = {'id': 'test_compound', 'name': 'Test compound'} e = entry.DictCompoundEntry(props) e2 = entry.DictCompoundEntry(e) self.assertIsInstance(e2, entry.CompoundEntry) self.assertEqual(e2.id, 'test_compound') self.assertEqual(e2.name, 'Test compound')
def test_use_compound_dict_entry_setters(self): e = entry.DictCompoundEntry({}, id='new_id') e.formula = 'CO2' e.name = 'Compound 1' e.charge = 5 self.assertEqual(e.formula, 'CO2') self.assertEqual(e.properties['formula'], 'CO2') self.assertEqual(e.name, 'Compound 1') self.assertEqual(e.charge, 5)
def test_write_compounds_with_properties(self): stream = StringIO() compounds = [ entry.DictCompoundEntry({ 'id': 'c1', 'name': 'Compound 1', 'charge': 2 }), entry.DictCompoundEntry({ 'id': 'c2', 'name': 'Compound 2', 'formula': 'H2O' }) ] self.writer.write_compounds(stream, compounds, properties={'name'}) self.assertEqual(yaml.safe_load(stream.getvalue()), [{ 'id': 'c1', 'name': 'Compound 1' }, { 'id': 'c2', 'name': 'Compound 2' }])
def test_convert_compound_entry(self): compound = entry.DictCompoundEntry({ 'id': 'c1', 'name': 'Compound 1', 'charge': 2, 'formula': None, 'custom': 'ABC' }) d = self.writer.convert_compound_entry(compound) self.assertIsInstance(d, OrderedDict) self.assertEqual(d['id'], 'c1') self.assertEqual(d['name'], 'Compound 1') self.assertEqual(d['charge'], 2) self.assertEqual(d['custom'], 'ABC') self.assertNotIn('formula', d)
def test_create_compound_dict_entry(self): props = { 'id': 'test_compound', 'name': 'Test compound', 'formula': 'H2O', 'charge': 1, 'custom': 'ABC' } e = entry.DictCompoundEntry(props) self.assertIsInstance(e, entry.CompoundEntry) self.assertEqual(e.id, 'test_compound') self.assertEqual(e.name, 'Test compound') self.assertEqual(e.formula, 'H2O') self.assertEqual(e.charge, 1) self.assertEqual(e.properties.get('custom'), 'ABC')
def test_create_reaction_entry_from_compound_entry(self): e = entry.DictCompoundEntry({'id': 'compound_1', 'name': 'Compound 1'}) with self.assertRaises(ValueError): e2 = entry.DictReactionEntry(e)
def test_create_compound_dict_entry_with_id_override(self): props = {'id': 'old_id', 'name': 'Compound 1', 'formula': 'CO2'} e = entry.DictCompoundEntry(props, id='new_id') self.assertEqual(e.id, 'new_id') self.assertEqual(e.properties['id'], 'new_id')
def test_create_compound_dict_entry_without_id(self): props = {'name': 'Compound 1', 'formula': 'CO2'} with self.assertRaises(ValueError): e = entry.DictCompoundEntry(props)