Exemplo n.º 1
0
    def _do_discovery(self, argv, Loader=None):
        """Upstream _do_discovery doesn't find our load_tests() functions."""

        loader = TestLoader() if Loader is None else Loader()
        topdir = abspath(dirname(dirname(__file__)))
        tests = loader.discover(join(topdir, 'numba/tests'), '*.py', topdir)
        self.test = unittest.TestSuite(tests)
Exemplo n.º 2
0
    def _do_discovery(self, argv, Loader=None):
        """Upstream _do_discovery doesn't find our load_tests() functions."""

        loader = TestLoader() if Loader is None else Loader()
        topdir = abspath(dirname(dirname(__file__)))
        tests = loader.discover(join(topdir, 'numba/tests'), '*.py', topdir)
        self.test = unittest.TestSuite(tests)
Exemplo n.º 3
0
    def _do_discovery(self, argv, Loader=loader.TestLoader):
        # handle command line args for test discovery
        import optparse
        parser = optparse.OptionParser()
        parser.add_option('-v', '--verbose', dest='verbose', default=False,
                          help='Verbose output', action='store_true')
        parser.add_option('-s', '--start-directory', dest='start', default='.',
                          help="Directory to start discovery ('.' default)")
        parser.add_option('-p', '--pattern', dest='pattern', default='test*.py',
                          help="Pattern to match tests ('test*.py' default)")
        parser.add_option('-t', '--top-level-directory', dest='top', default=None,
                          help='Top level directory of project (defaults to start directory)')

        options, args = parser.parse_args(argv)
        if len(args) > 3:
            self.usageExit()

        for name, value in zip(('start', 'pattern', 'top'), args):
            setattr(options, name, value)

        if options.verbose:
            self.verbosity = 2

        start_dir = options.start
        pattern = options.pattern
        top_level_dir = options.top

        loader = Loader()
        self.test = loader.discover(start_dir, pattern, top_level_dir)
 def discover_path(self, directory, name):
     loader = None
     path = os.path.join(directory, name)
     if os.path.isfile(path):
         loader = self.test_loader.fileLoaderClass(self.test_loader)
     elif os.path.isdir(path):
         loader = self.test_loader.dirLoaderClass(self.test_loader)
     if loader is not None:
         return loader.discover(directory, name)
     return None
 def discover_path(self, directory, name):
     loader = None
     path = os.path.join(directory, name)
     if os.path.isfile(path):
         loader = self.test_loader.fileLoaderClass(self.test_loader)
     elif os.path.isdir(path):
         loader = self.test_loader.dirLoaderClass(self.test_loader)
     if loader is not None:
         return loader.discover(directory, name)
     return None
Exemplo n.º 6
0
    def _do_discovery(self, argv, Loader=loader.TestLoader):
        # handle command line args for test discovery
        self.progName = '%s discover' % self.progName
        import optparse
        parser = optparse.OptionParser()
        parser.prog = self.progName
        parser.add_option('-v', '--verbose', dest='verbose', default=False,
                          help='Verbose output', action='store_true')
        if self.failfast != False:
            parser.add_option('-f', '--failfast', dest='failfast', default=False,
                              help='Stop on first fail or error',
                              action='store_true')
        if self.catchbreak != False:
            parser.add_option('-c', '--catch', dest='catchbreak', default=False,
                              help='Catch ctrl-C and display results so far',
                              action='store_true')
        if self.buffer != False:
            parser.add_option('-b', '--buffer', dest='buffer', default=False,
                              help='Buffer stdout and stderr during tests',
                              action='store_true')
        parser.add_option('-s', '--start-directory', dest='start', default='.',
                          help="Directory to start discovery ('.' default)")
        parser.add_option('-p', '--pattern', dest='pattern', default='test*.py',
                          help="Pattern to match tests ('test*.py' default)")
        parser.add_option('-t', '--top-level-directory', dest='top', default=None,
                          help='Top level directory of project (defaults to start directory)')

        options, args = parser.parse_args(argv)
        if len(args) > 3:
            self.usageExit()

        for name, value in zip(('start', 'pattern', 'top'), args):
            setattr(options, name, value)

        # only set options from the parsing here
        # if they weren't set explicitly in the constructor
        if self.failfast is None:
            self.failfast = options.failfast
        if self.catchbreak is None:
            self.catchbreak = options.catchbreak
        if self.buffer is None:
            self.buffer = options.buffer

        if options.verbose:
            self.verbosity = 2

        start_dir = options.start
        pattern = options.pattern
        top_level_dir = options.top

        loader = Loader()
        self.test = loader.discover(start_dir, pattern, top_level_dir)
Exemplo n.º 7
0
def load_tests(modules, loader):
    if modules:
        log.info("Executing modules: {0}".format(modules))
        module_suites = []
        for mod_name in modules:
            # Test names like cephfs.test_auto_repair
            module_suites.append(loader.loadTestsFromName(mod_name))
        log.info("Loaded: {0}".format(list(module_suites)))
        return suite.TestSuite(module_suites)
    else:
        log.info("Executing all cephfs tests")
        return loader.discover(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), "cephfs"))
Exemplo n.º 8
0
def load_tests(modules, loader):
    if modules:
        log.info("Executing modules: {0}".format(modules))
        module_suites = []
        for mod_name in modules:
            # Test names like cephfs.test_auto_repair
            module_suites.append(loader.loadTestsFromName(mod_name))
        log.info("Loaded: {0}".format(list(module_suites)))
        return suite.TestSuite(module_suites)
    else:
        log.info("Executing all cephfs tests")
        return loader.discover(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), "cephfs")
        )
Exemplo n.º 9
0
def load_testsuite(loader, dir):
    """Find tests in 'dir'."""

    suite = unittest.TestSuite()
    files = []
    for f in os.listdir(dir):
        path = join(dir, f)
        if os.path.isfile(path) and fnmatch(f, 'test_*.py'):
            files.append(f)
        elif os.path.isfile(join(path, '__init__.py')):
            suite.addTests(loader.discover(path))
    for f in files:
        # turn 'f' into a filename relative to the toplevel dir...
        f = relpath(join(dir, f), loader._top_level_dir)
        # ...and translate it to a module name.
        f = os.path.splitext(os.path.normpath(f.replace(os.path.sep, '.')))[0]
        suite.addTests(loader.loadTestsFromName(f))
    return suite
Exemplo n.º 10
0
def load_testsuite(loader, dir):
    """Find tests in 'dir'."""

    suite = unittest.TestSuite()
    files = []
    for f in os.listdir(dir):
        path = join(dir, f)
        if os.path.isfile(path) and fnmatch(f, 'test_*.py'):
            files.append(f)
        elif os.path.isfile(join(path, '__init__.py')):
            suite.addTests(loader.discover(path))
    for f in files:
        # turn 'f' into a filename relative to the toplevel dir...
        f = relpath(join(dir, f), loader._top_level_dir)
        # ...and translate it to a module name.
        f = os.path.splitext(os.path.normpath(f.replace(os.path.sep, '.')))[0]
        suite.addTests(loader.loadTestsFromName(f))
    return suite
Exemplo n.º 11
0
    def _do_discovery(self, argv, Loader=loader.TestLoader):
        # handle command line args for test discovery
        import optparse
        parser = optparse.OptionParser()
        parser.add_option('-v',
                          '--verbose',
                          dest='verbose',
                          default=False,
                          help='Verbose output',
                          action='store_true')
        parser.add_option('-s',
                          '--start-directory',
                          dest='start',
                          default='.',
                          help="Directory to start discovery ('.' default)")
        parser.add_option('-p',
                          '--pattern',
                          dest='pattern',
                          default='test*.py',
                          help="Pattern to match tests ('test*.py' default)")
        parser.add_option(
            '-t',
            '--top-level-directory',
            dest='top',
            default=None,
            help='Top level directory of project (defaults to start directory)'
        )

        options, args = parser.parse_args(argv)
        if len(args) > 3:
            self.usageExit()

        for name, value in zip(('start', 'pattern', 'top'), args):
            setattr(options, name, value)

        if options.verbose:
            self.verbosity = 2

        start_dir = options.start
        pattern = options.pattern
        top_level_dir = options.top

        loader = Loader()
        self.test = loader.discover(start_dir, pattern, top_level_dir)
 def discover_path(self, directory, name):
     # MISSINGTEST: The behavior is unclear when a module cannot be imported
     # because sys.path is incomplete. This makes it hard for the user to
     # understand it should update sys.path -- vila 2013-05-05
     path = os.path.join(directory, name)
     if (os.path.isdir(path) and os.path.isfile(
             os.path.join(path, '__init__.py'))):
         # Hold on, we need to respect users wishes here (if it has some)
         loader = PackageLoader(self.test_loader)
         try:
             return loader.discover(directory, name)
         except ImportError:
             # FIXME: Nah, didn't work, should we report it to the user ?
             # (yes see MISSINGTEST above) How ? (By re-raising with a
             # proper message: if there is an __init__.py file here, it
             # should be importable, that's what we should explain to the
             # user) vila 2013-05-04
             pass
     return super(ScriptDirLoader, self).discover_path(directory, name)
 def discover_path(self, directory, name):
     # MISSINGTEST: The behavior is unclear when a module cannot be imported
     # because sys.path is incomplete. This makes it hard for the user to
     # understand it should update sys.path -- vila 2013-05-05
     path = os.path.join(directory, name)
     if (os.path.isdir(path)
             and os.path.isfile(os.path.join(path, '__init__.py'))):
         # Hold on, we need to respect users wishes here (if it has some)
         loader = PackageLoader(self.test_loader)
         try:
             return loader.discover(directory, name)
         except ImportError:
             # FIXME: Nah, didn't work, should we report it to the user ?
             # (yes see MISSINGTEST above) How ? (By re-raising with a
             # proper message: if there is an __init__.py file here, it
             # should be importable, that's what we should explain to the
             # user) vila 2013-05-04
             pass
     return super(ScriptDirLoader, self).discover_path(directory, name)