Browse Source

Test index generation

pull/231/head
Oliverpool 9 years ago
parent
commit
7e5f81e2e5
  1. 2
      test/test_content/test_content.py
  2. 0
      test/test_index/__init__.py
  3. 46
      test/test_index/test_index.py

2
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"""

0
test/test_index/__init__.py

46
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
Loading…
Cancel
Save