Skip to content

Commit

Permalink
fix: reset variable cache (#507)
Browse files Browse the repository at this point in the history
reset variable cache for reaction after reverting the change
  • Loading branch information
pstjohn authored and hredestig committed May 11, 2017
1 parent 4e796e0 commit f79f44d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions cobra/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def remove_reactions(self, reactions, delete=True,
reaction._model = None

if context:
context(reaction._reset_var_cache)
context(partial(setattr, reaction, '_model', self))
context(partial(self.reactions.add, reaction))

Expand Down
18 changes: 12 additions & 6 deletions cobra/test/test_solver_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,18 @@ def test_add_metabolites_combine_false(self, model):
# ).as_coefficients_dict()

def test_remove_from_model(self, model):
pgi = model.reactions.PGI
pgi.remove_from_model()
assert pgi.model is None
assert not ("PGI" in model.reactions)
assert not (pgi.id in model.variables)
assert not (pgi.reverse_id in model.variables)
with model:
pgi = model.reactions.PGI
pgi.remove_from_model()
assert pgi.model is None
assert not ("PGI" in model.reactions)
assert not (pgi.id in model.variables)
assert not (pgi.reverse_id in model.variables)

assert ("PGI" in model.reactions)
assert (pgi.id in model.variables)
assert (pgi.reverse_id in model.variables)
assert pgi.forward_variable.problem is model.solver

def test_delete(self, model):
pgi = model.reactions.PGI
Expand Down

0 comments on commit f79f44d

Please sign in to comment.