Only patch cwuri2eid locally, restore original function afterwards
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 24 Oct 2016 08:37:35 +0200
changeset 1951 cdc88a9ee438
parent 1950 4775f5b15412
child 1952 5e36a73d04ad
Only patch cwuri2eid locally, restore original function afterwards else it may causes problem with during tests.
dataimport.py
--- a/dataimport.py	Fri Oct 21 17:38:12 2016 +0200
+++ b/dataimport.py	Mon Oct 24 08:37:35 2016 +0200
@@ -130,6 +130,15 @@
 
 def import_seda_schemes(cnx, lcsv_import=lcsv_import):
     """Import all LCSV data files defined in LCSV_FILES."""
+    orig_cwuri2eid = post321_import.cwuri2eid
+    try:
+        _import_seda_schemes(cnx, lcsv_import)
+    finally:
+        post321_import.cwuri2eid = orig_cwuri2eid
+
+
+def _import_seda_schemes(cnx, lcsv_import=lcsv_import):
+    """Import all LCSV data files defined in LCSV_FILES."""
     feed_extid2eid_cache(cnx)
     store = get_store(cnx)
     for title, rtypes, etypes, fname in LCSV_FILES:
@@ -168,9 +177,8 @@
     global EXTID2EID_CACHE
     EXTID2EID_CACHE = orig_cwuri2eid(cnx, ('ConceptScheme', 'Label'))
     # though concepts and external URIs may come from any source
-    EXTID2EID_CACHE.update(cwuri2eid(cnx, ('Concept', 'ExternalUri')))
+    EXTID2EID_CACHE.update(patched_cwuri2eid(cnx, ('Concept', 'ExternalUri')))
 
 
-@monkeypatch(post321_import)
-def cwuri2eid(cnx, etypes, source_eid=None):
+def patched_cwuri2eid(cnx, etypes, source_eid=None):
     return EXTID2EID_CACHE