예제 #1
0
    def testTokens(self):
        messages = []
        for mod in TestExtensions.EXTENSIONS:
            name = mod.__name__.split('.')[-1]
            objects = testing.get_parent_objects(mod, tokens.Token)

            try:
                tmod = importlib.import_module('test_{}'.format(name))
            except ImportError:
                msg = "test_{0}.py must be added to test/extensions, run './moosedocs.py devel " \
                      "--generate-extension-tests {0}'".format(name)
                messages.append(msg)
                continue

            case = None
            for case_name, case_type in testing.get_parent_objects(tmod, unittest.TestCase):
                if case_name == 'TestTokens':
                    case = case_type

            if case is None:
                msg = 'TestTokens must be created in test_{}.py'.format(name)
                messages.append(msg)
                continue

            testcases = dir(case)
            for obj in objects:
                test_case = 'test{}'.format(obj[0])
                if test_case not in testcases:
                    msg = "{} method must be added to TestTokens in test_{}.py".format(test_case, name)
                    messages.append(msg)
예제 #2
0
    def testTokens(self):
        messages = []
        for mod in TestExtensions.EXTENSIONS:
            name = mod.__name__.split('.')[-1]
            objects = testing.get_parent_objects(mod, tokens.Token)

            try:
                tmod = importlib.import_module('test_{}'.format(name))
            except ImportError:
                msg = "test_{0}.py must be added to test/extensions, run './moosedocs.py devel " \
                      "--generate-extension-tests {0}'".format(name)
                messages.append(msg)
                continue

            case = None
            for case_name, case_type in testing.get_parent_objects(tmod, unittest.TestCase):
                if case_name == 'TestTokens':
                    case = case_type

            if case is None:
                msg = 'TestTokens must be created in test_{}.py'.format(name)
                messages.append(msg)
                continue

            testcases = dir(case)
            for obj in objects:
                test_case = 'test{}'.format(obj[0])
                if test_case not in testcases:
                    msg = "{} method must be added to TestTokens in test_{}.py".format(test_case, name)
                    messages.append(msg)

        self.assertFalse(messages, '\n' + '\n'.join(messages))
예제 #3
0
    def checkTestCases(self, obj_type, required):
        messages = []
        for mod in TestExtensions.EXTENSIONS:
            mod_name = mod.__name__.split('.')[-1]
            objects = testing.get_parent_objects(mod, obj_type)

            try:
                tmod = importlib.import_module('test_{}'.format(mod_name))
            except ImportError:
                msg = "test_{0}.py must be added to test/extensions, run './moosedocs.py devel " \
                      "--generate-extension-tests {0}'".format(mod_name)
                messages.append(msg)
                continue

            testcases = [
                name for name, _ in testing.get_parent_objects(
                    tmod, unittest.TestCase)
            ]
            for req in required:
                for obj in objects:
                    test_case = req.format(obj[0])
                    if test_case not in testcases:
                        msg = "{} unittest.TestCase must be added to test_{}.py"
                        messages.append(msg.format(obj[0], mod_name))

        self.assertFalse(messages, '\n' + '\n'.join(messages))
예제 #4
0
    def checkTestCases(self, obj_type, required):
        messages = []
        for mod in TestExtensions.EXTENSIONS:
            mod_name = mod.__name__.split('.')[-1]
            objects = testing.get_parent_objects(mod, obj_type)

            try:
                tmod = importlib.import_module('test_{}'.format(mod_name))
            except ImportError:
                msg = "test_{0}.py must be added to test/extensions, run './moosedocs.py devel " \
                      "--generate-extension-tests {0}'".format(mod_name)
                messages.append(msg)
                continue

            testcases = [name for name, _ in testing.get_parent_objects(tmod, unittest.TestCase)]
            for req in required:
                for obj in objects:
                    test_case = req.format(obj[0])
                    if test_case not in testcases:
                        msg = "{} unittest.TestCase must be added to test_{}.py"
                        messages.append(msg.format(obj[0], mod_name))

        self.assertFalse(messages, '\n' + '\n'.join(messages))
예제 #5
0
    def check(self, location):

        # List of errors
        messages = []

        # Load the test spec and create a list of PythonUnitTest files
        tested = set()
        spec = os.path.join(location, 'tests')
        if not os.path.exists(spec):
            if glob.glob(os.path.join(spec, '*.py')):
                messages.append("Missing a test spec file in '{}'".format(
                    os.path.dirname(spec)))
        else:
            node = mooseutils.hit_load(os.path.join(location, 'tests'))
            for block in node.find('Tests'):
                if block['type'] == 'PythonUnitTest':
                    tested.add(block['input'])

        # Loop through python files in this directory
        for filename in glob.glob(os.path.join(location, '*.py')):

            # Local filename
            base = os.path.basename(filename)

            # Load the module (tried this with os.chdir, but that didn't work)
            sys.path.append(location)
            mod = __import__(base[:-3])
            sys.path.remove(location)

            # Get a lit of unittest.TestCase objects, if they exist this file should be in spec
            tests = testing.get_parent_objects(mod, unittest.TestCase)
            if tests and (base not in tested):
                msg = "The test script '{}' is not included in the tests spec '{}'."
                messages.append(msg.format(base, spec))

        return messages
예제 #6
0
파일: devel.py 프로젝트: real-THU/moose-1
def main(options):
    """./moosedocs devel"""

    LOG = logging.getLogger(__name__)  #pylint: disable=invalid-name

    # Module
    name = options.gen_ext_test
    ext_dir = options.ext_dir
    mod_name = '{}.{}'.format(ext_dir, name)
    mod = importlib.import_module(mod_name)

    # Output
    output = os.path.join(os.getcwd(), 'test', 'extensions',
                          'test_{}.py'.format(name))

    # Tokens
    token_objects = testing.get_parent_objects(mod, tokens.Token)

    # Reader
    reader_objects = set(
        testing.get_parent_objects(mod, command.CommandComponent))
    reader_objects.update(
        testing.get_parent_objects(mod, components.TokenComponent))

    # Render
    render_objects = testing.get_parent_objects(mod,
                                                components.RenderComponent)

    # Exit if file exists
    if os.path.exists(output):
        LOG.error('The test file exists: %s.', output)
        sys.exit(1)

    # Open file for writing
    fid = open(output, 'w')

    # Header
    items = dict(MODULE=mod_name, EXTENSIONROOT=ext_dir, EXTENSIONNAME=name)
    func = lambda m: sub_function(m, items)
    fid.write(SUB_RE.sub(func, HEAD))

    # Tokens
    func = lambda m: sub_function(m, dict(MODULE=mod_name))
    fid.write(SUB_RE.sub(func, TOKEN_HEAD))
    for obj in token_objects:
        func = lambda m: sub_function(m, dict(NAME=obj[0], MODULE=mod_name))
        fid.write(SUB_RE.sub(func, TOKEN_TEST))

    # Tokenize Tests
    fid.write("\n# TOKENIZE TESTS")
    for obj in reader_objects:
        func = lambda m: sub_function(
            m,
            dict(NAME=obj[0],
                 EXTENSIONNAME=name,
                 MODULE=mod_name,
                 BASE="testing.MooseDocsTestCase"))
        fid.write(SUB_RE.sub(func, TOKENIZE))

    # Render Tests
    fid.write("\n# RENDERER TESTS")
    for obj in render_objects:
        func = lambda m: sub_function(
            m,
            dict(NAME=obj[0],
                 EXTENSIONNAME=name,
                 MODULE=mod_name,
                 RENDERER="HTMLRenderer"))
        fid.write(SUB_RE.sub(func, HTML))

        func = lambda m: sub_function(
            m,
            dict(NAME=obj[0],
                 EXTENSIONNAME=name,
                 MODULE=mod_name,
                 RENDERER="MaterializeRenderer"))
        fid.write(SUB_RE.sub(func, MATERIALIZE))

        func = lambda m: sub_function(
            m,
            dict(NAME=obj[0],
                 EXTENSIONNAME=name,
                 MODULE=mod_name,
                 RENDERER="LatexRenderer"))
        fid.write(SUB_RE.sub(func, LATEX))

    # Finish
    fid.write(FOOT)
    fid.close()