示例#1
0
 def test_7_different_origins(self):
     my_id = uuid4()
     q_ref_1 = CatalogRef('fictitious.origin.v1', my_id, entity_type='quantity')
     q_ref_2 = CatalogRef('fictitious.origin.v2', my_id, entity_type='quantity')
     self.fg.add(q_ref_1)
     '''
     with self.assertRaises(EntityRefMergeError):
         # this will give an error that CatalogRefs can't merge
         self.fg.add(q_ref_2)
     '''
     self.fg.add(q_ref_2)
     self.assertIs(self.fg[q_ref_2.link], q_ref_2)
示例#2
0
 def test_catalog_ref(self):
     """
     Create an LCIA result using a catalog ref as quantity
     :return:
     """
     qty = CatalogRef('fictitious.origin', 'dummy_ext_ref', entity_type='quantity', Name='Test Quantity')
     res = LciaResult(qty)
     self.assertEqual(res.total(), 0.0)
示例#3
0
 def _qty_ref_from_json(self, e, uid):
     origin = e.pop('origin')
     external_ref = e.pop('externalId')
     unitstring = e.pop('referenceUnit')
     return CatalogRef.from_query(external_ref,
                                  self._catalog.query(origin),
                                  'quantity',
                                  unitstring,
                                  uuid=uid,
                                  **e)
示例#4
0
 def _flow_ref_from_json(self, e, uid):
     origin = e.pop('origin')
     external_ref = e.pop('externalId')
     c = e.pop('characterizations')
     ref_qty_uu = next(cf['quantity'] for cf in c
                       if 'isReference' in cf and cf['isReference'] is True)
     return CatalogRef.from_query(external_ref,
                                  self._catalog.query(origin),
                                  'flow',
                                  self[ref_qty_uu],
                                  uuid=uid,
                                  **e)
示例#5
0
 def make_ref(self, query):
     if self._query_ref is None:
         d = dict()
         reference_entity = self._make_ref_ref(query)
         for k in self.signature_fields():
             if k == self._ref_field:
                 continue
             if k in self._d:
                 d[k] = self._d[k]
         self._query_ref = CatalogRef.from_query(self.external_ref, query, self.entity_type, reference_entity,
                                                 uuid=self.uuid, **d)
     return self._query_ref
示例#6
0
 def catalog_ref(self, origin, external_ref, entity_type=None):
     """
     TODO: make foreground-generated CatalogRefs lazy-loading. This mainly requires removing the expectation of a
     locally-defined reference entity, and properly implementing and using a reference-retrieval process in the
     basic interface.
     :param origin:
     :param external_ref:
     :param entity_type:
     :return:
     """
     # TODO: catalog.fetch is costly because it loads the entire target object
     ref = self._catalog.fetch(origin, external_ref)
     if ref is None:
         ref = CatalogRef(origin, external_ref, entity_type=entity_type)
     return ref
示例#7
0
 def test_catalog_ref(self):
     my_id = str(uuid4())
     self.ar.add(CatalogRef('bogus.origin', my_id, entity_type='flow'))
     self.assertEqual(self.ar[my_id].uuid, my_id)
示例#8
0
 def _make_ref(self, external_ref, entity_type, reference_entity, **kwargs):
     return CatalogRef.from_query(external_ref, self._query, entity_type,
                                  reference_entity, **kwargs)