[PATCH 5 of 6 saem_ref] [rdf] Prefetch ORM cache for activities when exporting ConceptScheme

Denis Laxalde denis.laxalde at logilab.fr
Thu Mar 16 17:54:49 CET 2017


Sylvain Thénault a écrit :
>>> diff --git a/test/test_entities_rdf.py b/test/test_entities_rdf.py
>>> --- a/test/test_entities_rdf.py
>>> +++ b/test/test_entities_rdf.py
>>> @@ -15,15 +15,18 @@
>>>  # with this program. If not, see <http://www.gnu.org/licenses/>.
>>>  """Tests for agent entities"""
>>>
>>>  import datetime
>>>
>>> +from logilab.common.decorators import monkeypatch
>>> +
>>>  from cubicweb.devtools.testlib import CubicWebTC
>>>
>>>  from cubes.skos.rdfio import RDFLibRDFGraph, RDFRegistry
>>>
>>>  from cubicweb_saem_ref import permanent_url
>>> +from cubicweb_saem_ref.entities import rdf
>>>
>>>  import testutils
>>>
>>>
>>>  class RDFExportTC(testutils.XmlTestMixin, CubicWebTC):
>>> @@ -227,11 +230,22 @@ class RDFExportTC(testutils.XmlTestMixin
>>>          with self.admin_access.client_cnx() as cnx:
>>>              scheme = testutils.setup_scheme(cnx, u'some vocab')
>>>              cnx.commit()
>>>              concept = scheme.add_concept(u'some concept')
>>>              cnx.commit()
>>> -            scheme.cw_clear_all_caches()
>>> +
>>> +        with self.admin_access.client_cnx() as cnx:
>>> +            scheme = cnx.entity_from_eid(scheme.eid)
>>> +            concept = cnx.entity_from_eid(concept.eid)
>>> +
>>> +            orig_warm_caches =
>>> rdf.ConceptSchemeRDFPrimaryAdapter.warm_caches
>>> +
>>> +            @monkeypatch(rdf.ConceptSchemeRDFPrimaryAdapter)
>>> +            def warm_caches(self):
>>> +                orig_warm_caches(self)
>>> +                # ensure no RQL further query is done
>>> +                self._cw.execute = lambda rql, args=None: 1 / 0
>>>
>> Could you explain this change in the commit message? If the intent is to
>> make sure some function is not called, a mock seems like the way to go.
>>
> will send a V2 with this enhanced, though I don't know how to do this
> using mock.

I'm not sure it's doable with mock but I think it's worth trying. The
reason why I'm not sure is because it's not so clear to me what you're
trying to achieve and this is an issue in itself. As a start, I don't
get why you open a new cnx and redefine scheme and concept names. In
general, I think we should avoid @monkeypatch when mock does the job in
tests because it's more standard and we can expect people to be more
familiar with it.



More information about the saem-devel mailing list