[PATCH 3 of 7 saem_ref] [ark] Let ARK_RGX also match the qualifier

Denis Laxalde denis.laxalde at logilab.fr
Wed Feb 21 12:03:28 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1519200067 -3600
#      Wed Feb 21 09:01:07 2018 +0100
# Node ID b8dd5a269fd5d090c7f371fe74b4d87be9185355
# Parent  fe9c0e8928682ddfc5c4c862df00a7bf0bc08f40
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r b8dd5a269fd5
# EXP-Topic ark/unique-overall
[ark] Let ARK_RGX also match the qualifier

diff --git a/cubicweb_saem_ref/ark.py b/cubicweb_saem_ref/ark.py
--- a/cubicweb_saem_ref/ark.py
+++ b/cubicweb_saem_ref/ark.py
@@ -24,10 +24,13 @@ ARK_NAME_LENGTH = 10
 ARK_QUALIFIER_LENGTH = 10
 
 ARK_RGX = re.compile(
-    r'^(ark:/)?(?P<naan>\d+)/(?P<name>{prefix}\w{{{length}}}{controlchar})$'.format(
+    (r'^(ark:/)?(?P<naan>\d+)'
+     r'/(?P<name>{prefix}\w{{{length}}}{controlchar})'
+     r'(/(?P<qualifier>.{{{qualifier_length}}}))?$').format(
         prefix=ARK_PREFIX,
         length=ARK_NAME_LENGTH - len(ARK_PREFIX) - len(ARK_CONTROLCHAR),
         controlchar=ARK_CONTROLCHAR,
+        qualifier_length=ARK_QUALIFIER_LENGTH,
     ),
 )
 
diff --git a/test/test_ark.py b/test/test_ark.py
--- a/test/test_ark.py
+++ b/test/test_ark.py
@@ -41,7 +41,7 @@ class ArkRgxTC(TestCase):
         """Make string interpolation is correct."""
         self.assertEqual(
             ARK_RGX.pattern,
-            r'^(ark:/)?(?P<naan>\d+)/(?P<name>rf\w{7}g)$',
+            r'^(ark:/)?(?P<naan>\d+)/(?P<name>rf\w{7}g)(/(?P<qualifier>.{10}))?$',
         )
 
     def test(self):
@@ -56,6 +56,14 @@ class ArkRgxTC(TestCase):
         self.assertEqual(match.group('naan'), '12345')
         self.assertEqual(match.group('name'), 'rfqqqqqqqg')
 
+    def test_qualified(self):
+        ark = '0/rfr8hps6ng/h4050n4j02'
+        match = ark_match(ark)
+        self.assertTrue(match)
+        self.assertEqual(match.group('naan'), '0')
+        self.assertEqual(match.group('name'), 'rfr8hps6ng')
+        self.assertEqual(match.group('qualifier'), 'h4050n4j02')
+
     def test_tesutils_match_ark_qualified(self):
         ark = '0/rfr8hps6ng/h4050n4j02'
 



More information about the saem-devel mailing list