From 1a6bca654bf7a619fd9d712f4ea11e74b4f565c6 Mon Sep 17 00:00:00 2001 From: "uri.akavia" Date: Wed, 29 Jun 2022 22:11:33 -0400 Subject: [PATCH] now almost all of the tests work --- src/cobra/io/dict.py | 49 --------------------------- tests/test_core/test_udconstraints.py | 6 ++-- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/src/cobra/io/dict.py b/src/cobra/io/dict.py index fc5241605..0c0a47a15 100644 --- a/src/cobra/io/dict.py +++ b/src/cobra/io/dict.py @@ -1,19 +1,16 @@ """Provide functions for cobrapy objects to generic Python objects and vice-versa.""" import itertools -import re from collections import OrderedDict, defaultdict from typing import TYPE_CHECKING, Dict, List, Sequence, Set, Tuple, Union import numpy as np from ..core import ( - ConstraintComponent, Gene, Group, Metabolite, Model, Reaction, - UserDefinedConstraint, ) from ..io.sbml import ( F_GENE, @@ -520,52 +517,6 @@ def group_from_dict( new_group.add_members(cobra_members) return new_group -def const_comp_to_dict(component: ConstraintComponent) -> Dict: - new_const_comp = OrderedDict() - for key in _REQUIRED_CONSTRAINT_COMP_ATTRIBUTES: - new_const_comp[key] = _fix_type(getattr(component, key)) - _update_optional( - component, - new_const_comp, - _OPTIONAL_CONSTRAINT_COMP_ATTRIBUTES, - _ORDERED_OPTIONAL_CONSTRAINT_COMP_KEYS, - ) - return new_const_comp - - -def user_defined_const_to_dict(constraint: UserDefinedConstraint) -> Dict: - new_const = OrderedDict() - for key in _REQUIRED_CONSTRAINT_ATTRIBUTES: - if key != "constraint_comps": - new_const[key] = _fix_type(getattr(constraint, key)) - continue - new_const["constraint_comps"] = list( - map(const_comp_to_dict, constraint.constraint_comps) - ) - _update_optional( - constraint, - new_const, - _OPTIONAL_CONSTRAINT_ATTRIBUTES, - _ORDERED_OPTIONAL_CONSTRAINT_KEYS, - ) - return new_const - - -def user_defined_const_from_dict(constraint: Dict) -> UserDefinedConstraint: - new_user_defined_const = UserDefinedConstraint() - for k, v in constraint.items(): - if k == "constraint_comps": - for comp in v: - new_comp = ConstraintComponent(**comp) - new_user_defined_const.add_constraint_comps([new_comp]) - elif k == "annotation": - continue - elif k == "notes": - continue - else: - setattr(new_user_defined_const, k, v) - return new_user_defined_const - def model_to_dict( model: Model, sort: bool = False, f_replace: dict = F_REPLACE # noqa: W0102 diff --git a/tests/test_core/test_udconstraints.py b/tests/test_core/test_udconstraints.py index 496f0f77f..0156bf717 100644 --- a/tests/test_core/test_udconstraints.py +++ b/tests/test_core/test_udconstraints.py @@ -88,8 +88,8 @@ def test_user_defined_constraints_on_single_variable(): def test_json_reading_writing(model, tmp_path): - cc1 = Variable("FBA") - cc2 = Variable('NH4t') + cc1 = model.reactions.get_by_id('FBA').flux_expression + cc2 = model.reactions.get_by_id('NH4t').flux_expression cc3 = Variable('difference') c1 = Constraint(cc1 - cc2 - cc3, lb=0, ub=0, name='c1') @@ -109,7 +109,7 @@ def test_json_reading_writing(model, tmp_path): variable_names = {var.name for var in const_1.variables} assert 'FBA' in variable_names solution2 = model.optimize() - assert solution1 == pytest.approx(solution2) + assert solution1.objective_value == pytest.approx(solution2.objective_value) def test_user_defined_constraints_read_write_json(data_directory, tmp_path):