Skip to content

Commit 3897ec7

Browse files
author
uri.akavia
committed
now almost all of the tests work
1 parent 074470c commit 3897ec7

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

src/cobra/io/dict.py

-49
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
"""Provide functions for cobrapy objects to generic Python objects and vice-versa."""
22
import itertools
3-
import re
43
from collections import OrderedDict, defaultdict
54
from typing import TYPE_CHECKING, Dict, List, Sequence, Set, Tuple, Union
65

76
import numpy as np
87

98
from ..core import (
10-
ConstraintComponent,
119
Gene,
1210
Group,
1311
Metabolite,
1412
Model,
1513
Reaction,
16-
UserDefinedConstraint,
1714
)
1815
from ..io.sbml import (
1916
F_GENE,
@@ -520,52 +517,6 @@ def group_from_dict(
520517
new_group.add_members(cobra_members)
521518
return new_group
522519

523-
def const_comp_to_dict(component: ConstraintComponent) -> Dict:
524-
new_const_comp = OrderedDict()
525-
for key in _REQUIRED_CONSTRAINT_COMP_ATTRIBUTES:
526-
new_const_comp[key] = _fix_type(getattr(component, key))
527-
_update_optional(
528-
component,
529-
new_const_comp,
530-
_OPTIONAL_CONSTRAINT_COMP_ATTRIBUTES,
531-
_ORDERED_OPTIONAL_CONSTRAINT_COMP_KEYS,
532-
)
533-
return new_const_comp
534-
535-
536-
def user_defined_const_to_dict(constraint: UserDefinedConstraint) -> Dict:
537-
new_const = OrderedDict()
538-
for key in _REQUIRED_CONSTRAINT_ATTRIBUTES:
539-
if key != "constraint_comps":
540-
new_const[key] = _fix_type(getattr(constraint, key))
541-
continue
542-
new_const["constraint_comps"] = list(
543-
map(const_comp_to_dict, constraint.constraint_comps)
544-
)
545-
_update_optional(
546-
constraint,
547-
new_const,
548-
_OPTIONAL_CONSTRAINT_ATTRIBUTES,
549-
_ORDERED_OPTIONAL_CONSTRAINT_KEYS,
550-
)
551-
return new_const
552-
553-
554-
def user_defined_const_from_dict(constraint: Dict) -> UserDefinedConstraint:
555-
new_user_defined_const = UserDefinedConstraint()
556-
for k, v in constraint.items():
557-
if k == "constraint_comps":
558-
for comp in v:
559-
new_comp = ConstraintComponent(**comp)
560-
new_user_defined_const.add_constraint_comps([new_comp])
561-
elif k == "annotation":
562-
continue
563-
elif k == "notes":
564-
continue
565-
else:
566-
setattr(new_user_defined_const, k, v)
567-
return new_user_defined_const
568-
569520

570521
def model_to_dict(
571522
model: Model, sort: bool = False, f_replace: dict = F_REPLACE # noqa: W0102

tests/test_core/test_udconstraints.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def test_user_defined_constraints_on_single_variable():
8888

8989

9090
def test_json_reading_writing(model, tmp_path):
91-
cc1 = Variable("FBA")
92-
cc2 = Variable('NH4t')
91+
cc1 = model.reactions.get_by_id('FBA').flux_expression
92+
cc2 = model.reactions.get_by_id('NH4t').flux_expression
9393
cc3 = Variable('difference')
9494
c1 = Constraint(cc1 - cc2 - cc3, lb=0, ub=0, name='c1')
9595

@@ -109,7 +109,7 @@ def test_json_reading_writing(model, tmp_path):
109109
variable_names = {var.name for var in const_1.variables}
110110
assert 'FBA' in variable_names
111111
solution2 = model.optimize()
112-
assert solution1 == pytest.approx(solution2)
112+
assert solution1.objective_value == pytest.approx(solution2.objective_value)
113113

114114

115115
def test_user_defined_constraints_read_write_json(data_directory, tmp_path):

0 commit comments

Comments
 (0)