def test_7_different_origins(self): my_id = uuid4() f_ref_1 = CatalogRef('fictitious.origin.v1', my_id, entity_type='flow') f_ref_2 = CatalogRef('fictitious.origin.v2', my_id, entity_type='flow') self.fg.add(f_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(f_ref_2) self.assertIs(self.fg[f_ref_2.link], f_ref_2)
def test_hash_equiv(self): f = LcFlow('dummy flow', referenceQuantity=q, origin=q.origin) fref = CatalogRef(f.origin, f.external_ref, entity_type='flow') s = set() s.add(f) s.add(fref) self.assertEqual(len(s), 1) d = dict() d[f] = 42 self.assertIn(fref, d) self.assertEqual(d[fref], 42)
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)
def make_ref(self, query): if self._query_ref is None: d = dict() 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, uuid=self.uuid, **d) return self._query_ref
def make_ref(self, query): if self._query_ref is None: d = dict() 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, uuid=self.uuid, **d) self._query_ref.context = self.context for k, v in self._chars_seen.items(): self._query_ref.see_char(*k, v) return self._query_ref
def catalog_ref(self, origin, external_ref, entity_type=None, **kwargs): """ 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: """ try: q = self.query(origin) ref = q.get(external_ref) except UnknownOrigin: ref = CatalogRef(origin, external_ref, entity_type=entity_type, **kwargs) return ref
def _make_ref(self, external_ref, entity_type, **kwargs): if entity_type == 'fragment': return FragmentRef(external_ref, self.query, **kwargs) r = CatalogRef.from_query(external_ref, self.query, entity_type, **kwargs) return r
import unittest from .. import LcFlow, LcQuantity from antelope import CatalogRef q = LcQuantity.new('Dummy quantity', 'dum', origin='test.origin') qref = CatalogRef(q.origin, q.external_ref, entity_type='quantity') class EntityRefTest(unittest.TestCase): def test_equality(self): self.assertEqual(q, qref) self.assertEqual(qref, q) def test_hash(self): self.assertEqual(hash(q), hash(qref)) def test_hash_equiv(self): f = LcFlow('dummy flow', referenceQuantity=q, origin=q.origin) fref = CatalogRef(f.origin, f.external_ref, entity_type='flow') s = set() s.add(f) s.add(fref) self.assertEqual(len(s), 1) d = dict() d[f] = 42 self.assertIn(fref, d) self.assertEqual(d[fref], 42) if __name__ == '__main__': unittest.main()
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)