Repository: unt-libraries/edtf-validate

Issue:
Support checking level conformance and level is-a-feature-of
To facilitate the work on changes to the edtf-service described at: https://github.com/unt-libraries/django-edtf/issues/15, we will probably need to replace `isLevel0`, `isLevel1`, `isLevel2` with functionality that distinguishes if the date conforms to a specific level or is a feature of a specific level.

Comments:

Patch:
diff --git a/edtf_validate/valid_edtf.py b/edtf_validate/valid_edtf.py
index a4e0cdc..6648d02 100644
--- a/edtf_validate/valid_edtf.py
+++ b/edtf_validate/valid_edtf.py
@@ -529,7 +529,7 @@ def is_valid_interval(edtf_candidate):
 
 
 def isLevel0(edtf_candidate):
-    """Checks to see if the date is level 0 valid"""
+    """Check if the date is of a feature introduced in level 0."""
 
     if " " not in edtf_candidate:
         result = edtf_candidate == level0Expression
@@ -539,7 +539,7 @@ def isLevel0(edtf_candidate):
 
 
 def isLevel1(edtf_candidate):
-    """Checks to see if the date is level 1 valid"""
+    """Check if the date is of a feature introduced in level 1."""
 
     if " " not in edtf_candidate:
         result = edtf_candidate == level1Expression
@@ -549,7 +549,7 @@ def isLevel1(edtf_candidate):
 
 
 def isLevel2(edtf_candidate):
-    """Checks to see if the date is level 2 valid"""
+    """Check if the date is of a feature introduced in level 2."""
 
     if "[" in edtf_candidate or "{" in edtf_candidate:
         result = edtf_candidate == level2Expression
@@ -560,6 +560,25 @@ def isLevel2(edtf_candidate):
     return result
 
 
+def conformsLevel0(edtf_candidate):
+    """Check if the date is supported at level 0."""
+    return isLevel0(edtf_candidate)
+
+
+def conformsLevel1(edtf_candidate):
+    """Check if the date is supported at level 1."""
+    return isLevel0(edtf_candidate) or isLevel1(edtf_candidate)
+
+
+def conformsLevel2(edtf_candidate):
+    """Check if the date is supported at level 2."""
+    return(
+        isLevel0(edtf_candidate)
+        or isLevel1(edtf_candidate)
+        or isLevel2(edtf_candidate)
+    )
+
+
 def is_valid(edtf_candidate):
     """isValid takes a candidate date and returns if it is valid or not"""
     if (


Test patch:
diff --git a/tests/test_valid_edtf.py b/tests/test_valid_edtf.py
index 6d7dd17..003c098 100644
--- a/tests/test_valid_edtf.py
+++ b/tests/test_valid_edtf.py
@@ -1,7 +1,7 @@
 import pytest
 
-from edtf_validate.valid_edtf import (is_valid_interval, is_valid, isLevel0,
-                                      isLevel1, isLevel2)
+from edtf_validate.valid_edtf import (is_valid_interval, is_valid, isLevel0, isLevel1,
+                                      isLevel2, conformsLevel0, conformsLevel1, conformsLevel2)
 
 
 class TestIsValidInterval(object):
@@ -307,3 +307,69 @@ class TestLevel2(object):
     ])
     def test_invalid_level_2(self, date):
         assert not isLevel2(date)
+
+    @pytest.mark.parametrize('date', [
+        '1985',
+        '2004/2005',
+        '1985-04-12',
+        '1985-04-12T23:20:30Z',
+        '1985-04-12T23:20:30+04:30'
+    ])
+    def test_valid_conformsLevel0(self, date):
+        assert conformsLevel0(date)
+
+    @pytest.mark.parametrize('date', [
+        '-1984',
+        '19XX',
+        'Y-170000002',
+        '2001-21',
+        '1984?',
+        '1985-04/..',
+        '1985/',
+    ])
+    def test_invalid_conformsLevel0(self, date):
+        assert not conformsLevel0(date)
+
+    @pytest.mark.parametrize('date', [
+        '-1985',
+        '/1985-04-12',
+        '../1985-04-12',
+        '2004-XX',
+        '2004-06~',
+        '2001-21',
+        'Y-170000002',
+        '1985-04-12T23:20:30Z',
+        '2004-06/2006-08',
+        '1985-04'
+    ])
+    def test_valid_conformsLevel1(self, date):
+        assert conformsLevel1(date)
+
+    @pytest.mark.parametrize('date', [
+        'Y-17E7',
+        '2001-34',
+        '156X-12-25'
+    ])
+    def test_invalid_conformsLevel1(self, date):
+        assert not conformsLevel1(date)
+
+    @pytest.mark.parametrize('date', [
+        '-1985',
+        '/1985-04-12',
+        '../1985-04-12',
+        '2004-XX',
+        '2004-06~',
+        '2001-21',
+        'Y-170000002',
+        '1985-04-12T23:20:30Z',
+        '2004-06/2006-08',
+        '1985-04',
+        '156X-12-25',
+        '{1667,1668,1670..1672}',
+        '[1667,1668,1670..1672]',
+    ])
+    def test_valid_conformsLevel2(self, date):
+        assert conformsLevel2(date)
+
+    def test_invalid_conformsLevel2(self):
+        assert not conformsLevel2('[1667,1668, 1670..1672]')