Example #1
0
def suite():
    testsuite = unittest.TestSuite()

    test_names = unittest.getTestCaseNames(TestAverage, "test")
    for test in test_names:
        testsuite.addTest(TestAverage(test))

    test_names = unittest.getTestCaseNames(TestAverageMonitorName, "test")
    for test in test_names:
        testsuite.addTest(TestAverageMonitorName(test))
    return testsuite
Example #2
0
def make_suite(vendor, testcase, factory, mask=None):
	clz = __imp__(testcase.frm, testcase.impt)
	caseNames = filter(lambda x, i=testcase.ignore: x not in i, unittest.getTestCaseNames(clz, "test"))
	if mask is not None:
		caseNames = filter(lambda x, mask=mask: x == mask, caseNames)
	tests = [clz(caseName, vendor, factory) for caseName in caseNames]
	return unittest.TestSuite(tests)
 def _add_all_tests(self):
     suite_list = [[t, unittest.getTestCaseNames(eval(t), 'test')] 
                   for t in self.ALL_TESTS]
     for sg in suite_list:
         for tc in sg[1]:
             self.suite.addTests([
                     unittest.defaultTestLoader.loadTestsFromName(sg[0]+"."+tc)])
Example #4
0
 def caseclass_count(caselist):
     print 'dir caselist',caselist
     for casename in caselist:
         module=loadcase._get_module_from_name(casename)
         for name in dir(module):
             obj = getattr(module,name)
             if isinstance(obj, type) and issubclass(obj, case.TestCase):
                 modeltestcases_list=getTestCaseNames(obj,'test')
                 caseclass_dict[obj]=len(modeltestcases_list)
     return caseclass_dict
Example #5
0
def suite():
    suite = unittest.TestSuite()
    tclasses = [
                 FindPathDirsTestCase,
                 ScannerTestCase,
                 BaseTestCase,
                 SelectorTestCase,
                 CurrentTestCase,
                 ClassicTestCase,
                 ClassicCPPTestCase,
               ]
    for tclass in tclasses:
        names = unittest.getTestCaseNames(tclass, 'test_')
        suite.addTests(list(map(tclass, names)))
    return suite
Example #6
0
def loadTestsFromTestCase(testCaseClass, *args, **kwargs):
    testCaseNames = unittest.getTestCaseNames(testCaseClass, 'test_')
    return unittest.TestSuite(map(lambda n : testCaseClass(n, *args, **kwargs), testCaseNames))
Example #7
0
        """
        foo = Foo()
        foo.parent = foo
        foo.constructor = foo.__init__

        def leak_frame():
            frame = inspect.currentframe()

        leak_frame()
        del foo

        g = GarbageGraph()
        try:
            g.render("garbage.eps")
            g.render("garbage.eps", unflatten=True)
        except OSError:
            # Graphviz not installed.
            pass
        else:
            os.unlink("garbage.eps")


if __name__ == "__main__":
    suite = unittest.TestSuite()
    tclasses = [GarbageTestCase]
    for tclass in tclasses:
        names = unittest.getTestCaseNames(tclass, "test_")
        suite.addTests(map(tclass, names))
    if not unittest.TextTestRunner().run(suite).wasSuccessful():
        sys.exit(1)
Example #8
0
        r = obj.value()
        assert r == 1, r
        r = obj.value()
        assert r == 1, r

        assert fv1.calls == 1, fv1.calls
        assert fv2.calls == 0, fv2.calls

        c = obj.get_memoizer_counter('value')

        assert c.hit == 3, c.hit
        assert c.miss == 1, c.miss


if __name__ == "__main__":
    suite = unittest.TestSuite()
    tclasses = [
        CountDictTestCase,
        CountValueTestCase,
    ]
    for tclass in tclasses:
        names = unittest.getTestCaseNames(tclass, 'test_')
        suite.addTests(list(map(tclass, names)))
    TestUnit.run(suite)

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
Example #9
0
    def __init__(self, include="", exclude="", tests=""):
        # error checking
        if include != "" and exclude != "":
            raise ValueError("include and exclude arguments are mutually exclusive")
        # TODO: could this become a simple os.listdir(".")?
        _rootdir = os.path.abspath(sys.path[0])
        if not os.path.isdir(_rootdir):
            _rootdir = os.path.dirname(_rootdir)
        self.rootdir = _rootdir # to come in handy later
        # a dict of all possible test modules that could be run
        # ASSUME: each module name is unique not solely because of case
        _module_names = {}
        for _name in [ n[:-3] for n in os.listdir(self.rootdir)
                    if n.startswith("test") and n.endswith(".py") ]:
            _module_names[ _name.lower() ] = _name
        # make the include/exclude/tests lists
        _module_specs = None
        _spec_type    = None
        _test_specs   = None
        if include != "":
            _module_specs = self._clean_listify(include)
            _spec_type    = "include"
        elif exclude != "":
            _module_specs = self._clean_listify(exclude)
            _spec_type    = "exclude"

        if tests != "":
            _test_specs = self._clean_listify(tests, False)

        # make sure they all exist
        if _module_specs != None: # TODO: got to be a better place to put this
            for _mod in _module_specs:
                if not _module_names.has_key(_mod.lower()):
                    parser.error("Module %s not found under test" % (_mod))

        # now import the modules
        if _module_specs == None:
            self.modules = [ __import__(name) for name in _module_names.values() ]
        elif _spec_type == "include":
            self.modules = [ __import__(name) for name in _module_specs ]
        elif _spec_type == "exclude":
            self.modules = [ __import__(name) for name in _module_names.values()
                                            if name not in _module_specs ]
        # convert modules into suites
        self.suites = []
        for module in self.modules:
            _classname = module.__name__[4:] + "Test"
            _class = module.__getattribute__(_classname)
            # build test suite (whether or not --tests are specified)
            if _test_specs == None:
                _suite = unittest.makeSuite(_class)
            else:
                _suite = unittest.TestSuite()
                for _test_name in unittest.getTestCaseNames(_class,"test"):
                    for _test in _test_specs:
                        _docstr = getattr(_class, _test_name).__doc__
                        if _test_name.lower().find(_test.lower()) != -1 or \
                               _docstr != None and _docstr.lower().find(_test.lower()) != -1:
                            _suite.addTest(_class(_test_name))
                        break

            # filter out tests that shouldn't be run in subclasses
            _tests = _suite._tests
            for _t in _tests:
                # TODO: pull logic into wxtest
                # or use the version of unittest instead
                if sys.version_info[0:2] >= (2,5):
                    _mname = _t._testMethodName
                else:
                    _mname = _t._TestCase__testMethodName
                
                if _mname.find('_wx') != -1:
                    # grab the class: everything between '_wx' and 'Only' at the end
                    restriction = _mname[_mname.find('_wx')+3:-4]
                    if not _class.__name__.startswith(restriction):
                        #print "filtered: %s (class=%s)" % (mname,_class.__name__)
                        _tests.remove(_t)

            # if suite is non-empty...
            if _suite.countTestCases() > 0:
                # add it to the list of suites :-)
                self.suites.append(_suite)
Example #10
0
def _getTestCaseNames(testCase):
    import operator
    return reduce(operator.add, [unittest.getTestCaseNames(testCase, prefix) for prefix in testPrefixes])
Example #11
0
 def suite():
     testsuite = unittest.TestSuite()
     test_names = unittest.getTestCaseNames(TestAIWidget, "test")
     for test in test_names:
         testsuite.addTest(TestAIWidget(test))
     return testsuite
Example #12
0
def suite():
    testsuite = unittest.TestSuite()
    test_names = unittest.getTestCaseNames(TestUtilShell, "test")
    for test in test_names:
        testsuite.addTest(TestUtilShell(test))
    return testsuite
Example #13
0
            built_it = None

            r = f8.retrieve_from_cache()
            assert r == 1, r
            assert self.retrieved == [f8], self.retrieved
            assert built_it is None, built_it

            SCons.CacheDir.CacheRetrieveSilent = self.retrieve_fail
            self.retrieved = []
            built_it = None

            r = f8.retrieve_from_cache()
            assert r is False, r
            assert self.retrieved == [f8], self.retrieved
            assert built_it is None, built_it
        finally:
            SCons.CacheDir.CacheRetrieveSilent = save_CacheRetrieveSilent


if __name__ == "__main__":
    suite = unittest.TestSuite()
    tclasses = [
        CacheDirTestCase,
        FileTestCase,
    ]
    for tclass in tclasses:
        names = unittest.getTestCaseNames(tclass, 'test_')
        suite.addTests(map(tclass, names))
    if not unittest.TextTestRunner().run(suite).wasSuccessful():
        sys.exit(1)
Example #14
0
    def __init__(self, include="", exclude="", tests=""):
        # error checking
        if include != "" and exclude != "":
            raise ValueError(
                "include and exclude arguments are mutually exclusive")
        # TODO: could this become a simple os.listdir(".")?
        _rootdir = os.path.abspath(sys.path[0])
        if not os.path.isdir(_rootdir):
            _rootdir = os.path.dirname(_rootdir)
        self.rootdir = _rootdir  # to come in handy later
        # a dict of all possible test modules that could be run
        # ASSUME: each module name is unique not solely because of case
        _module_names = {}
        for _name in [
                n[:-3] for n in os.listdir(self.rootdir)
                if n.startswith("test") and n.endswith(".py")
        ]:
            _module_names[_name.lower()] = _name
        # make the include/exclude/tests lists
        _module_specs = None
        _spec_type = None
        _test_specs = None
        if include != "":
            _module_specs = self._clean_listify(include)
            _spec_type = "include"
        elif exclude != "":
            _module_specs = self._clean_listify(exclude)
            _spec_type = "exclude"

        if tests != "":
            _test_specs = self._clean_listify(tests, False)

        # make sure they all exist
        if _module_specs != None:  # TODO: got to be a better place to put this
            for _mod in _module_specs:
                if not _module_names.has_key(_mod.lower()):
                    parser.error("Module %s not found under test" % (_mod))

        # now import the modules
        if _module_specs == None:
            self.modules = [
                __import__(name) for name in _module_names.values()
            ]
        elif _spec_type == "include":
            self.modules = [__import__(name) for name in _module_specs]
        elif _spec_type == "exclude":
            self.modules = [
                __import__(name) for name in _module_names.values()
                if name not in _module_specs
            ]
        # convert modules into suites
        self.suites = []
        for module in self.modules:
            _classname = module.__name__[4:] + "Test"
            _class = module.__getattribute__(_classname)
            # build test suite (whether or not --tests are specified)
            if _test_specs == None:
                _suite = unittest.makeSuite(_class)
            else:
                _suite = unittest.TestSuite()
                for _test_name in unittest.getTestCaseNames(_class, "test"):
                    for _test in _test_specs:
                        _docstr = getattr(_class, _test_name).__doc__
                        if _test_name.lower().find(_test.lower()) != -1 or \
                               _docstr != None and _docstr.lower().find(_test.lower()) != -1:
                            _suite.addTest(_class(_test_name))
                        break

            # filter out tests that shouldn't be run in subclasses
            _tests = _suite._tests
            for _t in _tests:
                # TODO: pull logic into wxtest
                # or use the version of unittest instead
                if sys.version_info[0:2] >= (2, 5):
                    _mname = _t._testMethodName
                else:
                    _mname = _t._TestCase__testMethodName

                if _mname.find('_wx') != -1:
                    # grab the class: everything between '_wx' and 'Only' at the end
                    restriction = _mname[_mname.find('_wx') + 3:-4]
                    if not _class.__name__.startswith(restriction):
                        #print "filtered: %s (class=%s)" % (mname,_class.__name__)
                        _tests.remove(_t)

            # if suite is non-empty...
            if _suite.countTestCases() > 0:
                # add it to the list of suites :-)
                self.suites.append(_suite)
Example #15
0
def main():
    unit_tests_dbg.dbgprint(unittest.getTestCaseNames(UnitTests01, 'test'))
    unittest.main()
Example #16
0
def suite():
    testsuite = unittest.TestSuite()
    test_names = unittest.getTestCaseNames(TestUtilsString, "test")
    for test in test_names:
        testsuite.addTest(TestUtilsString(test))
    return testsuite