Exemple #1
0
    def _classes_from_module(self, module):

        # Test whether this module imports from a Pure python file.
        # If it isn't represented as a file, we'll need to
        # use the import method of searching for classes.
        path = get_module_path(module)

        # fixme: What about zip files.

        if (os.path.exists(path) and
            os.path.splitext(path)[1] == '.py'):
            # If it is a file, then parse the ast.
            import_method = False
        elif (os.path.exists(path) and
            os.path.isdir(path)):
            # If it is a package directory, parse the ast.
            import_method = False
        else:
            # Must be extension module or built-in, or something else...
            # Use import to handle it.
            import_method = True

        mod_and_name = find_classes(module, import_method)
        clss = [self.class_factory(module=module,name=name)
                    for module, name in mod_and_name]
        return clss
    def test_parse_error(self):
        # Because having a function checked in with a parse error creates problems
        # with the egg builder, we take an existing file and modify it.
        old_module = 'enthought.block_canvas.function_tools.tests.sample_package.error_package'
        old_filename = get_module_path(old_module)
        new_filename = old_filename[:-3] + '2.py'
        new_module = old_module+'2'
        lines = open(old_filename).readlines()
        # Strip off the colon on the end of the second line to create a syntax error
        lines[1] = lines[1][:-1]
        open(new_filename, 'w').writelines(lines)

        func = PythonFunctionInfo(module=new_module, name='badfunction')
        self.assertEqual(func.load_error, "failed to parse module '%s'" % new_module)
        os.unlink(new_filename)