Source

audrid / tests / test_validators.py

Diff from to

tests/test_validators.py

     multiple_choice,
     mapping,
     pool,
+    trial,
 )
 import unittest
 import json
     return open(os.path.join(os.path.abspath(
         os.path.dirname(__file__)), filename))
 
-class TaskValidatorTests(unittest.TestCase):
-
+class FilelistMixin(unittest.TestCase):
+    """
+    Provide ``should_pass_on`` and ``should_fail_on``
+    methods. 
+    """
     def should_pass_on(self, filenames, schema=None):
+        """
+        Loads each filename in ``filenames`` and validates against ``schema``.
+        """
         for fn in filenames:
             with openrel(fn) as handle:
                 content = json.load(handle)
                 self.assertEqual(content, schema(content))
 
     def should_fail_on(self, filename_exc_tuples, schema=None):
+        """
+        Takes a list of (filename, exception) tuples and ensures,
+        that the exceptions are actually raised while validating against ``schema``.
+        """
         for fn, exc in filename_exc_tuples:
             with self.assertRaises(exc):
                 with openrel(fn) as handle:
                     schema(json.load(handle))
 
+class TaskValidatorTests(FilelistMixin):
+
     def test_cloze(self):
         valid_files = [
             "documents/cloze0.json",
         self.should_pass_on(valid_files, schema=multiple_choice)
         self.should_fail_on(invalid_files, schema=multiple_choice)
 
-class PoolValidatorTests(unittest.TestCase):
-
-    def should_pass_on(self, filenames, schema=None):
-        for fn in filenames:
-            with openrel(fn) as handle:
-                content = json.load(handle)
-                self.assertEqual(content, schema(content))
-
-    def should_fail_on(self, filename_exc_tuples, schema=None):
-        for fn, exc in filename_exc_tuples:
-            with self.assertRaises(exc):
-                with openrel(fn) as handle:
-                    schema(json.load(handle))
+class PoolValidatorTests(FilelistMixin):
 
     def test_pool(self):
         valid_files = [
 
         self.should_pass_on(valid_files, schema=pool)
         self.should_fail_on(invalid_files, schema=pool)
+
+class AuditValidatorTests(FilelistMixin):
+
+    def test_audit(self):
+        valid_files = [
+            "documents/audit0.json",
+        ]
+        invalid_files = [
+            ("documents/empty.json", ValueError),
+        ]
+
+        self.should_pass_on(valid_files, schema=trial)
+        self.should_fail_on(invalid_files, schema=trial)