# Path: bdec/test/decoders.py
# def create_classes(name, tests, config):
#     """Return a dictionary of classes derived from unittest.TestCase.
# 
#     Each test case is named after both the name and the decoder type that
#     is under test (eg: if name is 'xml', test cases will include TestXmlC,
#     TestXmlPython, ...).
# 
#     name -- The name of the test.
#     tests -- An array of (name, spec_filename, successes, failures) tuples,
#         where name is the test name, spec_filename is the path to the
#         specification to load, and successes and failures are paths to binary
#         files that should either decode or not.
#     config_filename -- The path to the fixme config file.
#     """
#     clsname = name[0].upper() + name[1:]
#     cls = type(clsname, (object, _BaseRegressionTest,), {})
#     for test_name, spec_filename, entry, successes, failures in tests:
#         cls.add_method(test_name, '%s/%s' % (name, test_name), spec_filename, entry, successes, failures, config)
#     return create_decoder_classes([(cls, clsname)], __name__)


from collections import defaultdict
from ConfigParser import ConfigParser
from bdec.test.decoders import create_classes
import glob
import os.path
import re


def _find_regression_tests(spec_extension, regression_dir):
    # There are four file types in the regression folder.
    #
    #  1. Specifications
    #       <name>.<spec_extension>
    #  2. Data files we should successfully decoded
    #       <name>[-<entry>].<number>.<extension>
    #  3. Expected decoded xml
    #       <name>[-<entry>].<number>.expected.xml
    #  4. Data files that should fail to decode
    #       <name>[-<entry>].failure.<number>.<extension>
    class Test:
        def __init__(self):
            self.filename = None
            self.successes = []
            self.failures = []
        def __str__(self):
            return '%s: successes (%s), failures (%s)' % (self.filename, ','.join(self.successes), ','.join(self.failures))

    tests = defaultdict(Test)
    for filename in os.listdir(regression_dir):
        path = os.path.join(regression_dir, filename)
        if os.path.isfile(path):
            names = filename.split('.')
            if len(names) == 2:
                assert names[1] == spec_extension, \
                    "'%s' looks like specification, but doesn't end with '%s'!" % (filename, spec_extension)
                tests[names[0]].filename = path

# Path: bdec/test/decoders.py
# def create_classes(name, tests, config):
#     """Return a dictionary of classes derived from unittest.TestCase.
# 
#     Each test case is named after both the name and the decoder type that
#     is under test (eg: if name is 'xml', test cases will include TestXmlC,
#     TestXmlPython, ...).
# 
#     name -- The name of the test.
#     tests -- An array of (name, spec_filename, successes, failures) tuples,
#         where name is the test name, spec_filename is the path to the
#         specification to load, and successes and failures are paths to binary
#         files that should either decode or not.
#     config_filename -- The path to the fixme config file.
#     """
#     clsname = name[0].upper() + name[1:]
#     cls = type(clsname, (object, _BaseRegressionTest,), {})
#     for test_name, spec_filename, entry, successes, failures in tests:
#         cls.add_method(test_name, '%s/%s' % (name, test_name), spec_filename, entry, successes, failures, config)
#     return create_decoder_classes([(cls, clsname)], __name__)


# Path: regression/test.py
from collections import defaultdict
from ConfigParser import ConfigParser
from bdec.test.decoders import create_classes
import glob
import os.path
import re



def _find_regression_tests(spec_extension, regression_dir):
    # There are four file types in the regression folder.
    #
    #  1. Specifications
    #       <name>.<spec_extension>
    #  2. Data files we should successfully decoded
    #       <name>[-<entry>].<number>.<extension>
    #  3. Expected decoded xml
    #       <name>[-<entry>].<number>.expected.xml
    #  4. Data files that should fail to decode
    #       <name>[-<entry>].failure.<number>.<extension>
    class Test:
        def __init__(self):
            self.filename = None
            self.successes = []
            self.failures = []
        def __str__(self):
            return '%s: successes (%s), failures (%s)' % (self.filename, ','.join(self.successes), ','.join(self.failures))

    tests = defaultdict(Test)
    for filename in os.listdir(regression_dir):
        path = os.path.join(regression_dir, filename)
        if os.path.isfile(path):
            names = filename.split('.')
            if len(names) == 2:
                assert names[1] == spec_extension, \
                    "'%s' looks like specification, but doesn't end with '%s'!" % (filename, spec_extension)
                tests[names[0]].filename = path

            elif len(names) == 3: