Ejemplo n.º 1
0
 def test_custom_suite_without_sort_tests_works(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):pass
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([b, a], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Ejemplo n.º 2
0
 def test_custom_suite_without_sort_tests_works(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):pass
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([b, a], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Ejemplo n.º 3
0
 def test_sorts_custom_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):
         def sort_tests(self):
             self._tests = sorted_tests(self, True)
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([a, b], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Ejemplo n.º 4
0
 def test_sorts_custom_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):
         def sort_tests(self):
             self._tests = sorted_tests(self, True)
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([a, b], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Ejemplo n.º 5
0
 def test_sorts_simple_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     suite = sorted_tests(unittest.TestSuite([b, a]))
     self.assertEqual([a, b], list(iterate_tests(suite)))
Ejemplo n.º 6
0
 def sort_tests(self):
     self._tests = sorted_tests(self, True)
Ejemplo n.º 7
0
    def _do_discovery(self, argv, Loader=defaultTestLoaderCls):
        # handle command line args for test discovery
        if not have_discover:
            raise AssertionError(
                "Unable to use discovery, must use python 2.7 "
                "or greater, or install the discover package.")
        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)'
        )
        parser.add_option('-l',
                          '--list',
                          dest='listtests',
                          default=False,
                          action="store_true",
                          help='List tests rather than running them.')
        parser.add_option(
            '--load-list',
            dest='load_list',
            default=None,
            help='Specify a filename containing the test ids to use.')

        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
        self.listtests = options.listtests
        self.load_list = options.load_list

        if options.verbose:
            self.verbosity = 2

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

        loader = Loader()
        # See http://bugs.python.org/issue16709
        # While sorting here is intrusive, its better than being random.
        # Rules for the sort:
        # - standard suites are flattened, and the resulting tests sorted by
        #   id.
        # - non-standard suites are preserved as-is, and sorted into position
        #   by the first test found by iterating the suite.
        # We do this by a DSU process: flatten and grab a key, sort, strip the
        # keys.
        loaded = loader.discover(start_dir, pattern, top_level_dir)
        self.test = sorted_tests(loaded)
Ejemplo n.º 8
0
 def _do_discovery(self, argv, Loader=None):
     super()._do_discovery(argv, Loader=Loader)
     # XXX: Local edit (see http://bugs.python.org/issue22860)
     self.test = sorted_tests(self.test)
Ejemplo n.º 9
0
 def _do_discovery(self, argv, Loader=None):
     super(TestProgram, self)._do_discovery(argv, Loader=Loader)
     # XXX: Local edit (see http://bugs.python.org/issue22860)
     self.test = sorted_tests(self.test)
 def test_sorts_simple_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     suite = sorted_tests(unittest.TestSuite([b, a]))
     self.assertEqual([a, b], list(iterate_tests(suite)))
 def sort_tests(self):
     self._tests = sorted_tests(self, True)
Ejemplo n.º 12
0
    def _do_discovery(self, argv, Loader=defaultTestLoaderCls):
        # handle command line args for test discovery
        if not have_discover:
            raise AssertionError("Unable to use discovery, must use python 2.7 "
                    "or greater, or install the discover package.")
        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)')
        parser.add_option('-l', '--list', dest='listtests', default=False, action="store_true",
                          help='List tests rather than running them.')
        parser.add_option('--load-list', dest='load_list', default=None,
                          help='Specify a filename containing the test ids to use.')

        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
        self.listtests = options.listtests
        self.load_list = options.load_list

        if options.verbose:
            self.verbosity = 2

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

        loader = Loader()
        # See http://bugs.python.org/issue16709
        # While sorting here is intrusive, its better than being random.
        # Rules for the sort:
        # - standard suites are flattened, and the resulting tests sorted by
        #   id.
        # - non-standard suites are preserved as-is, and sorted into position
        #   by the first test found by iterating the suite.
        # We do this by a DSU process: flatten and grab a key, sort, strip the
        # keys.
        loaded = loader.discover(start_dir, pattern, top_level_dir)
        self.test = sorted_tests(loaded)