From 7e5f81e2e5c9c1c9716cb1c495f0085fab374190 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 4 Jul 2016 10:45:19 +0200 Subject: [PATCH] Test index generation --- test/test_content/test_content.py | 2 +- test/test_index/__init__.py | 0 test/test_index/test_index.py | 46 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/test_index/__init__.py create mode 100644 test/test_index/test_index.py 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