예제 #1
0
    def step_module_filename(self, module_name):
        """The file name corresponding to the steps module."""

        Importer().importFromDir('.', module_name)
        module = getsourcefile(sys.modules[module_name])
        del sys.modules[module_name]
        return module
예제 #2
0
 def setUp(self):
     self.dir = os.path.normpath(os.path.join(os.path.dirname(__file__),
                                              'support'))
     self.imp = Importer()
     self._mods = sys.modules.copy()
     self._path = sys.path[:]
     sys.modules.pop('mod', None)
     sys.modules.pop('pak', None)
     sys.modules.pop('pak.mod', None)
     sys.modules.pop('pak.sub', None)
예제 #3
0
class FeatureLoader(object):
    """Loader class responsible for findind features and step
    definitions along a given path on filesystem"""

    importer = Importer()

    @classmethod
    def find_and_load_step_definitions(cls, dir_):
        """
        Load the steps from the specified directory.
        """

        for path, _, files in os.walk(dir_):
            for filename in fnmatch.filter(files, '*.py'):
                # Import the module using its fully qualified name
                filename = os.path.relpath(os.path.join(path, filename))
                module_name = path_to_module_name(filename)

                try:
                    cls.importer.importFromPath(filename, module_name)
                except ImportError as exc:
                    raise_from(
                        StepDiscoveryError(
                            "Cannot load step definition file: '%s'" %
                            filename), exc)

    @classmethod
    def find_feature_directories(cls, dir_):
        """
        Locate directories to load features from.

        The directories must be named 'features'; they must either reside
        directly in the specified directory, or otherwise all their parents
        must be packages (have __init__.py files).
        """

        # A set of package directories discovered
        packages = set()

        for path, dirs, files in os.walk(dir_, followlinks=True):
            # Is this a package?
            if '__init__.py' in files:
                packages.add(path)

            if path == dir_ or path in packages:
                # Does this package have a feature directory?
                if 'features' in dirs:
                    yield os.path.join(path, 'features')

            else:
                # This is not a package, prune search
                dirs[:] = []
예제 #4
0
 def setUp(self):
     self.dir = os.path.normpath(
         os.path.join(os.path.dirname(__file__), 'support'))
     self.imp = Importer()
     self._mods = sys.modules.copy()
     self._path = sys.path[:]
     sys.modules.pop('mod', None)
     sys.modules.pop('pak', None)
     sys.modules.pop('pak.mod', None)
     sys.modules.pop('pak.sub', None)
     try:
         os.symlink(os.path.abspath(os.path.join(self.dir, 'dir1', 'pak')),
                    os.path.join(self.dir, 'dir3', 'pak'))
     except (AttributeError, NotImplementedError):
         self.has_symlinks = False
     else:
         self.has_symlinks = True
예제 #5
0
파일: loader.py 프로젝트: yiwei011/CrossMap
    def __init__(self,
                 config=None,
                 importer=None,
                 workingDir=None,
                 selector=None):
        """Initialize a test loader.

        Parameters (all optional):

        * config: provide a `nose.config.Config`_ or other config class
          instance; if not provided a `nose.config.Config`_ with
          default values is used.
        * importer: provide an importer instance that implements
          `importFromPath`. If not provided, a
          `nose.importer.Importer`_ is used.
        * workingDir: the directory to which file and module names are
          relative. If not provided, assumed to be the current working
          directory.
        * selector: a selector class or instance. If a class is
          provided, it will be instantiated with one argument, the
          current config. If not provided, a `nose.selector.Selector`_
          is used.
        """
        if config is None:
            config = Config()
        if importer is None:
            importer = Importer(config=config)
        if workingDir is None:
            workingDir = config.workingDir
        if selector is None:
            selector = defaultSelector(config)
        elif isclass(selector):
            selector = selector(config)
        self.config = config
        self.importer = importer
        self.workingDir = op_normpath(op_abspath(workingDir))
        self.selector = selector
        if config.addPaths:
            add_path(workingDir, config)
        self.suiteClass = ContextSuiteFactory(config=config)

        self._visitedPaths = set([])

        unittest.TestLoader.__init__(self)
예제 #6
0
import os
from os.path import dirname
from nose.importer import Importer
bin_dir = os.path.split(__file__)[0]
component_dir = os.path.join(bin_dir, "..", "..", "..")
importer = Importer()

# Load the 'core' module as though this script were being run from
# the parent component (either circulation or metadata).
importer.importFromDir(component_dir, 'core')