[PATCH 04 of 16 eac] [py3] Work around __next__ vs next in extid generator

Denis Laxalde denis.laxalde at logilab.fr
Tue Oct 1 12:36:30 CEST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1569918994 -7200
#      Tue Oct 01 10:36:34 2019 +0200
# Node ID 9df1fd6261a8d22b4ebc76ed51f0957a5038fcc2
# Parent  42c46223a5cb7763976f3fc2d2e3d0c74297c416
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 9df1fd6261a8
[py3] Work around __next__ vs next in extid generator

diff --git a/test/test_dataimport.py b/test/test_dataimport.py
index 9077d74..1f5b37e 100644
--- a/test/test_dataimport.py
+++ b/test/test_dataimport.py
@@ -23,7 +23,7 @@ from os.path import join, dirname
 import sys
 import unittest
 
-from six import reraise
+from six import PY2, reraise
 from six.moves import map
 
 from cubicweb import NoResultError
@@ -53,6 +53,15 @@ def extentities2dict(entities):
     return edict
 
 
+def mk_extid_generator():
+    """Predicate extid_generator."""
+    gen = map(str, count())
+    if PY2:
+        return gen.next
+    else:
+        return gen.__next__
+
+
 class EACXMLParserTC(unittest.TestCase):
 
     if sys.version_info < (3, 2):
@@ -66,14 +75,15 @@ class EACXMLParserTC(unittest.TestCase):
     def file_extentities(self, fname):
         fpath = self.datapath(fname)
         import_log = SimpleImportLog(fpath)
-        # Use a predictable extid_generator.
-        extid_generator = map(str, count()).next
         importer = dataimport.EACCPFImporter(fpath, import_log, mock_,
-                                             extid_generator=extid_generator)
+                                             extid_generator=mk_extid_generator())
         return importer.external_entities()
 
     def test_parse_FRAD033_EAC_00001(self):
-        _gen_extid = map(str, (x for x in count() if x != 2)).next
+        if PY2:
+            _gen_extid = map(str, (x for x in count() if x != 2)).next
+        else:
+            _gen_extid = map(str, (x for x in count() if x != 2)).__next__
         expected = [
             ('AuthorityRecord', 'FRAD033_EAC_00001',
              {'isni': set([u'22330001300016']),
@@ -343,10 +353,8 @@ class EACXMLParserTC(unittest.TestCase):
         expected = [ExtEntity(*vals) for vals in expected]
         fpath = self.datapath('FRAD033_EAC_00001_simplified.xml')
         import_log = SimpleImportLog(fpath)
-        # Use a predictable extid_generator.
-        extid_generator = map(str, count()).next
         importer = dataimport.EACCPFImporter(fpath, import_log, mock_,
-                                             extid_generator=extid_generator)
+                                             extid_generator=mk_extid_generator())
         entities = list(importer.external_entities())
         self.check_external_entities(entities, expected)
         visited = set([])



More information about the saem-devel mailing list