[PATCH 1 of 2 eac] Extract datapath class method as a function

Frank Bessou frank.bessou at logilab.fr
Wed Sep 4 17:35:36 CEST 2019


# HG changeset patch
# User Frank Bessou <frank.bessou at logilab.fr>
# Date 1567608050 -7200
#      Wed Sep 04 16:40:50 2019 +0200
# Node ID 850a27100121faf395d73dec6436f9ad7c4f10da
# Parent  63196f5cf34086f24a4f46bd21d7185a22364863
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 850a27100121
Extract datapath class method as a function

This will be used in several classes.

diff --git a/test/test_dataimport.py b/test/test_dataimport.py
--- a/test/test_dataimport.py
+++ b/test/test_dataimport.py
@@ -64,18 +64,18 @@ def extentities2dict(entities):
     return edict
 
 
+def datapath(*fname):
+    """joins the object's datadir and `fname`"""
+    return join(dirname(__file__), 'data', *fname)
+
+
 class EACXMLParserTC(unittest.TestCase):
 
     if sys.version_info < (3, 2):
         assertCountEqual = unittest.TestCase.assertItemsEqual
 
-    @classmethod
-    def datapath(cls, *fname):
-        """joins the object's datadir and `fname`"""
-        return join(dirname(__file__), 'data', *fname)
-
     def file_extentities(self, fname):
-        fpath = self.datapath(fname)
+        fpath = datapath(fname)
         import_log = SimpleImportLog(fpath)
         # Use a predictable extid_generator.
         extid_generator = map(str, count()).next
@@ -647,7 +647,7 @@ class EACXMLParserTC(unittest.TestCase):
              ),
         ]
         expected = [ExtEntity(*vals) for vals in expected]
-        fpath = self.datapath('FRAD033_EAC_00001_simplified.xml')
+        fpath = datapath('FRAD033_EAC_00001_simplified.xml')
         import_log = SimpleImportLog(fpath)
         # Use a predictable extid_generator.
         extid_generator = map(str, count()).next
@@ -694,7 +694,7 @@ class EACXMLParserTC(unittest.TestCase):
 
     def test_values_from_functions(self):
         fname = "FRAD033_EAC_00001_simplified.xml"
-        fpath = self.datapath(fname)
+        fpath = datapath(fname)
         self.root = etree.fromstring(XML_TEST)
         import_log = SimpleImportLog(fpath)
         importer = dataimport.EACCPFImporter(fpath, import_log)
@@ -811,7 +811,7 @@ class EACXMLParserTC(unittest.TestCase):
 class EACDataImportTC(CubicWebTC):
 
     def test_FRAD033_EAC_00001(self):
-        fpath = self.datapath('FRAD033_EAC_00001_simplified.xml')
+        fpath = datapath('FRAD033_EAC_00001_simplified.xml')
         with self.admin_access.repo_cnx() as cnx:
             # create a skos concept to ensure it's used instead of a ExternalUri
             scheme = cnx.create_entity('ConceptScheme')
@@ -1012,14 +1012,14 @@ class EACDataImportTC(CubicWebTC):
             nb_records_before = count_entity(cnx, 'AuthorityRecord')
             for fname in ('FRAD033_EAC_00001.xml', 'FRAD033_EAC_00003.xml',
                           'FRAD033_EAC_00071.xml'):
-                fpath = self.datapath(fname)
+                fpath = datapath(fname)
                 created, updated = testutils.eac_import(cnx, fpath)
             nb_records_after = count_entity(cnx, 'AuthorityRecord')
             self.assertEqual(nb_records_after - nb_records_before, 3)
 
     def test_unknown_kind(self):
         with self.admin_access.repo_cnx() as cnx:
-            testutils.eac_import(cnx, self.datapath('custom_kind.xml'))
+            testutils.eac_import(cnx, datapath('custom_kind.xml'))
             self.assertRaises(NoResultError, cnx.find('AgentKind', name=u'a custom kind').one)
             self.assertEqual(cnx.find('AuthorityRecord').one().agent_kind[0].name,
                              'unknown-agent-kind')
@@ -1027,14 +1027,14 @@ class EACDataImportTC(CubicWebTC):
     def test_no_name_entry(self):
         with self.admin_access.repo_cnx() as cnx:
             with self.assertRaises(dataimport.MissingTag) as cm:
-                testutils.eac_import(cnx, self.datapath('no_name_entry.xml'))
+                testutils.eac_import(cnx, datapath('no_name_entry.xml'))
             self.assertEqual(cm.exception.tag, 'nameEntry')
             self.assertEqual(cm.exception.tag_parent, 'identity')
 
     def test_no_name_entry_part(self):
         with self.admin_access.repo_cnx() as cnx:
             with self.assertRaises(dataimport.MissingTag) as cm:
-                testutils.eac_import(cnx, self.datapath('no_name_entry_part.xml'))
+                testutils.eac_import(cnx, datapath('no_name_entry_part.xml'))
             self.assertEqual(cm.exception.tag, 'part')
             self.assertEqual(cm.exception.tag_parent, 'nameEntry')
 



More information about the saem-devel mailing list