diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index 770d4e1a..e3bac8d6 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -42,7 +42,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): @classmethod def _create_content_test(cls, base): - """Return a function that `base.source` produces the correct file list""" + """Return a function that tests that `base.source` produces the correct file list""" def test_content(self): """Test that `base.source` produces the correct file list""" diff --git a/test/test_index/__init__.py b/test/test_index/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/test_index/test_index.py b/test/test_index/test_index.py new file mode 100644 index 00000000..94748fc4 --- /dev/null +++ b/test/test_index/test_index.py @@ -0,0 +1,46 @@ +"""Tests for the index generation.""" + +import codecs +import glob +import os +import unittest + +from patacrep.index import process_sxd + +from .. import dynamic # pylint: disable=unused-import + + +class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): + """Test of the index generation. + + For any given `foo.sxd`, it generates the index. + It controls that the generated file is equal to the one in `foo.sbx`. + """ + + @classmethod + def _iter_testmethods(cls): + """Iterate over dynamically generated test methods""" + for source in sorted(glob.glob(os.path.join( + os.path.dirname(__file__), + '*.sxd', + ))): + base = source[:-len(".sxd")] + yield ( + "test_index_{}".format(os.path.basename(base)), + cls._create_index_test(base), + ) + + @classmethod + def _create_index_test(cls, base): + """Return a function that tests that `foo.sxd` produces the sbx file""" + + def test_index(self): + """Test that `foo.sxd` produces the correct sbx file""" + generated_index = process_sxd(base + ".sxd").entries_to_str() + with codecs.open(base + ".sbx", "r", "utf-8") as control_index: + self.assertEqual(control_index.read(), generated_index, ) + + test_index.__doc__ = ( + "Test that '{base}.sxd' produces the correct sbx file""" + ).format(base=os.path.basename(base)) + return test_index