Details | self = <test_fba.FbaModelAnalysisTestCase testMethod=test_path_bounds_analysis>
def test_path_bounds_analysis(self):
# read a wc model
> self.model = wc_lang.io.Reader().run(self.MODEL_FILENAME)[wc_lang.Model][0]
tests/model/test_fba.py:263:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <wc_lang.io.Reader object at 0x7f6ecc599450>
path = '/root/project/tests/model/../fixtures/test_model.xlsx'
models = (<class 'wc_lang.core.Model'>, <class 'wc_lang.core.Taxon'>, <class 'wc_lang.core.Environment'>, <class 'wc_lang.core.Submodel'>, <class 'wc_lang.core.Compartment'>, <class 'wc_lang.core.SpeciesType'>, ...)
ignore_missing_models = False, ignore_extra_models = False
ignore_sheet_order = False, include_all_attributes = False
ignore_missing_attributes = False, ignore_extra_attributes = False
ignore_attribute_order = False, validate = None
def run(self, path, models=None,
ignore_missing_models=None, ignore_extra_models=None, ignore_sheet_order=None,
include_all_attributes=False, ignore_missing_attributes=None, ignore_extra_attributes=None,
ignore_attribute_order=None, validate=None):
""" Read a list of model objects from file(s) and, optionally, validate them
Args:
path (:obj:`str`): path to file(s)
models (:obj:`types.TypeType` or :obj:`list` of :obj:`types.TypeType`, optional): type
of object to read or list of types of objects to read
ignore_missing_models (:obj:`bool`, optional): if :obj:`False`, report an error if a worksheet/
file is missing for one or more models
ignore_extra_models (:obj:`bool`, optional): if :obj:`True` and all `models` are found, ignore
other worksheets or files
ignore_sheet_order (:obj:`bool`, optional): if :obj:`True`, do not require the sheets to be provided
in the canonical order
include_all_attributes (:obj:`bool`, optional): if :obj:`True`, export all attributes including those
not explictly included in `Model.Meta.attribute_order`
ignore_missing_attributes (:obj:`bool`, optional): if :obj:`False`, report an error if a
worksheet/file doesn't contain all of attributes in a model in `models`
ignore_extra_attributes (:obj:`bool`, optional): if :obj:`True`, do not report errors if
attributes in the data are not in the model
ignore_attribute_order (:obj:`bool`): if :obj:`True`, do not require the attributes to be provided
in the canonical order
validate (:obj:`bool`, optional): if :obj:`True`, validate the data
Returns:
:obj:`dict`: model objects grouped by `obj_tables.Model` class
Raises:
:obj:`ValueError`: if the file defines zero or multiple models or the model defined in the file(s) is
invalid
"""
if models is None:
models = self.MODELS
root_model = get_root_model(models)
if issubclass(self.get_reader(path), obj_tables.io.WorkbookReader):
Writer.validate_implicit_relationships(root_model)
config = wc_lang.config.core.get_config()['wc_lang']['io']
if ignore_missing_models is None:
ignore_missing_models = not config['strict']
if ignore_extra_models is None:
ignore_extra_models = not config['strict']
if ignore_sheet_order is None:
ignore_sheet_order = not config['strict']
if ignore_missing_attributes is None:
ignore_missing_attributes = not config['strict']
if ignore_extra_attributes is None:
ignore_extra_attributes = not config['strict']
if ignore_attribute_order is None:
ignore_attribute_order = not config['strict']
objects = super(Reader, self).run(path, schema_name='wc_lang', models=models,
ignore_missing_models=ignore_missing_models,
ignore_extra_models=ignore_extra_models,
ignore_sheet_order=ignore_sheet_order,
include_all_attributes=include_all_attributes,
ignore_missing_attributes=ignore_missing_attributes,
ignore_extra_attributes=ignore_extra_attributes,
ignore_attribute_order=ignore_attribute_order,
group_objects_by_model=True,
validate=False)
# check that file only has 1 wc_lang Model instance
root_model = get_root_model(objects)
if len(objects[root_model]) != 1:
raise ValueError('"{}" should define one model'.format(path))
model = objects[root_model][0]
# add implicit relationships to `Model`
if issubclass(self.get_reader(path), obj_tables.io.WorkbookReader):
for cls, cls_objects in objects.items():
for attr in cls.Meta.attributes.values():
if isinstance(attr, obj_tables.RelatedAttribute) and \
attr.related_class == root_model:
for cls_obj in cls_objects:
setattr(cls_obj, attr.name, model)
# validate
config = wc_lang.config.core.get_config()['wc_lang']['io']
if (validate is not None and validate) or (validate is None and config['validate']):
objs = []
for cls_objs in objects.values():
objs.extend(cls_objs)
errors = obj_tables.Validator().validate(objs)
if errors:
raise ValueError(
> indent_forest(['The model cannot be loaded because it fails to validate:', [errors]]))
E ValueError: The model cannot be loaded because it fails to validate:
E DfbaObjSpecies:
E dfba-net-species-Metabolism_biomass-specie_1[c]:
E 'units':
E Value must be in `choices`: {'molecule / gDCW', 'mole / gDCW', 'molecule / cell'}
E dfba-net-species-Metabolism_biomass-specie_2[c]:
E 'units':
E Value must be in `choices`: {'molecule / gDCW', 'mole / gDCW', 'molecule / cell'}
E dfba-net-species-Metabolism_biomass-specie_3[c]:
E 'units':
E Value must be in `choices`: {'molecule / gDCW', 'mole / gDCW', 'molecule / cell'}
E dfba-net-species-Metabolism_biomass-specie_4[c]:
E 'units':
E Value must be in `choices`: {'molecule / gDCW', 'mole / gDCW', 'molecule / cell'}
/usr/local/lib/python3.7/site-packages/wc_lang/io.py:260: ValueError |