Ejemplo n.º 1
0
def main(testGroup=['test']):
    '''Run all tests. Group can be test and external

    >>> print(None)
    None
    '''    

    # in case there are any tests here, get a suite to load up later
    s1 = doctest.DocTestSuite(__name__, 
        optionflags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE))

    modGather = ModuleGather()
    modules = modGather.load()

    environLocal.printDebug('looking for Test classes...\n')

    for module in common.sortModules(modules):
        #print _MOD, timeStr, module
        unitTestCases = []
    
        if not hasattr(module, 'Test'):
            environLocal.printDebug('%s has no Test class' % module)
        else:
            if 'test' in testGroup:
                unitTestCases.append(module.Test)

        if not hasattr(module, 'TestExternal'):
            pass
            #environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if 'external' in testGroup or 'testExternal' in testGroup:
                unitTestCases.append(module.TestExternal)

        # get unittest test
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)

        try:
            s3 = doctest.DocTestSuite(module, 
                optionflags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE))
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug('%s cannot load Doctests' % module)
            continue
    
    environLocal.printDebug('running Tests...\n')
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(s1)  
Ejemplo n.º 2
0
def main(testGroup=["test"], restoreEnvironmentDefaults=False):
    """Run all tests. Group can be test and external

    >>> print(None)
    None
    """
    docTestOptions = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
    # in case there are any tests here, get a suite to load up later
    s1 = doctest.DocTestSuite(__name__, optionflags=docTestOptions)

    modGather = ModuleGather()
    modules = modGather.load(restoreEnvironmentDefaults)

    verbosity = 2
    if "verbose" in sys.argv:
        verbosity = 1  # this seems to hide most display

    environLocal.printDebug("looking for Test classes...\n")
    # look over each module and gather doc tests and unittests
    for module in common.sortModules(modules):
        unitTestCases = []

        # get Test classes in module
        if not hasattr(module, "Test"):
            environLocal.printDebug("%s has no Test class" % module)
        else:
            if "test" in testGroup:
                unitTestCases.append(module.Test)
        if not hasattr(module, "TestExternal"):
            pass
            # environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if "external" in testGroup or "testExternal" in testGroup:
                unitTestCases.append(module.TestExternal)

        # for each Test class, load this into a suite
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)
        try:
            s3 = doctest.DocTestSuite(module, optionflags=docTestOptions)
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug("%s cannot load Doctests" % module)
            continue

    environLocal.printDebug("running Tests...\n")
    runner = unittest.TextTestRunner(verbosity=verbosity)
    testResult = runner.run(s1)
Ejemplo n.º 3
0
def main(testGroup=['test'], restoreEnvironmentDefaults=False, limit=None):
    '''Run all tests. Group can be test and external

    >>> print(None)
    None
    '''
    globs = __import__('music21').__dict__.copy()
    docTestOptions = (doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
    # in case there are any tests here, get a suite to load up later
    s1 = doctest.DocTestSuite(
        __name__,
        globs=globs,
        optionflags=docTestOptions
        )

    modGather = ModuleGather()
    modules = modGather.load(restoreEnvironmentDefaults)

    verbosity = 2
    if 'verbose' in sys.argv:
        verbosity = 1 # this seems to hide most display

    environLocal.printDebug('looking for Test classes...\n')
    # look over each module and gather doc tests and unittests
    totalModules = 0
    
    for module in common.sortModules(modules):
        unitTestCases = []
        if limit is not None:
            if totalModules > limit:
                break
        totalModules += 1
        # get Test classes in module
        if not hasattr(module, 'Test'):
            environLocal.printDebug('%s has no Test class' % module)
        else:
            if 'test' in testGroup:
                unitTestCases.append(module.Test)
        if not hasattr(module, 'TestExternal'):
            pass
            #environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if 'external' in testGroup or 'testExternal' in testGroup:
                unitTestCases.append(module.TestExternal)

        # for each Test class, load this into a suite
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)
        try:
            globs = __import__('music21').__dict__.copy()
            s3 = doctest.DocTestSuite(
                module,
                globs=globs,
                optionflags=docTestOptions,
                )
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug('%s cannot load Doctests' % module)
            continue
        
        allLocals = [getattr(module, x) for x in dir(module)]
        testRunner.addDocAttrTestsToSuite(s1, allLocals, outerFilename=module.__file__, globs=globs, optionflags=docTestOptions)
    
    testRunner.fixTestsForPy2and3(s1)
    
    environLocal.printDebug('running Tests...\n')
            
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', RuntimeWarning)  # import modules...
        runner = unittest.TextTestRunner(verbosity=verbosity)
        finalTestResults = runner.run(s1)  
    
    if cov is not None:
        cov.stop()
        cov.save()
    
    if (len(finalTestResults.errors) > 0 or
        len(finalTestResults.failures) > 0 or
        len(finalTestResults.unexpectedSuccesses) > 0):
            exit(1)
    else:
        exit(0)
Ejemplo n.º 4
0
def main(testGroup=('test',), restoreEnvironmentDefaults=False, limit=None):
    '''Run all tests. Group can be test and external

    >>> print(None)
    None
    '''
    s1 = commonTest.defaultDoctestSuite(__name__)

    modGather = commonTest.ModuleGather()
    modules = modGather.load(restoreEnvironmentDefaults)

    verbosity = 2
    if 'verbose' in sys.argv:
        verbosity = 1 # this seems to hide most display

    environLocal.printDebug('looking for Test classes...\n')
    # look over each module and gather doc tests and unittests
    totalModules = 0

    for moduleObject in common.sortModules(modules):
        unitTestCases = []
        if limit is not None:
            if totalModules > limit:
                break
        totalModules += 1
        # get Test classes in module
        if not hasattr(moduleObject, 'Test'):
            environLocal.printDebug('%s has no Test class' % moduleObject)
        else:
            if 'test' in testGroup:
                unitTestCases.append(moduleObject.Test)
        if not hasattr(moduleObject, 'TestExternal'):
            pass
            #environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if 'external' in testGroup or 'testExternal' in testGroup:
                unitTestCases.append(moduleObject.TestExternal)

        # for each Test class, load this into a suite
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)
        try:
            s3 = commonTest.defaultDoctestSuite(moduleObject)
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug('%s cannot load Doctests' % moduleObject)
            continue

        allLocals = [getattr(moduleObject, x) for x in dir(moduleObject)]

        globs = __import__('music21').__dict__.copy()
        docTestOptions = (doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
        testRunner.addDocAttrTestsToSuite(s1,
                                          allLocals,
                                          outerFilename=moduleObject.__file__,
                                          globs=globs,
                                          optionflags=docTestOptions,
                                          # no checker here
                                          )

    testRunner.fixTestsForPy2and3(s1)

    environLocal.printDebug('running Tests...\n')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore', RuntimeWarning)  # import modules...
        runner = unittest.TextTestRunner(verbosity=verbosity)
        finalTestResults = runner.run(s1)

    coverageM21.stopCoverage(cov)

    if (finalTestResults.errors or
            finalTestResults.failures or
            finalTestResults.unexpectedSuccesses):
        returnCode = 1
    else:
        returnCode = 0

    return returnCode
Ejemplo n.º 5
0
def main(testGroup=['test'], restoreEnvironmentDefaults=False, limit=None):
    '''Run all tests. Group can be test and external

    >>> print(None)
    None
    '''
    globs = __import__('music21').__dict__.copy()
    docTestOptions = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
    # in case there are any tests here, get a suite to load up later
    s1 = doctest.DocTestSuite(__name__,
                              globs=globs,
                              optionflags=docTestOptions)

    modGather = ModuleGather()
    modules = modGather.load(restoreEnvironmentDefaults)

    verbosity = 2
    if 'verbose' in sys.argv:
        verbosity = 1  # this seems to hide most display

    environLocal.printDebug('looking for Test classes...\n')
    # look over each module and gather doc tests and unittests
    totalModules = 0

    for module in common.sortModules(modules):
        unitTestCases = []
        if limit is not None:
            if totalModules > limit:
                break
        totalModules += 1
        # get Test classes in module
        if not hasattr(module, 'Test'):
            environLocal.printDebug('%s has no Test class' % module)
        else:
            if 'test' in testGroup:
                unitTestCases.append(module.Test)
        if not hasattr(module, 'TestExternal'):
            pass
            #environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if 'external' in testGroup or 'testExternal' in testGroup:
                unitTestCases.append(module.TestExternal)

        # for each Test class, load this into a suite
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)
        try:
            globs = __import__('music21').__dict__.copy()
            s3 = doctest.DocTestSuite(
                module,
                globs=globs,
                optionflags=docTestOptions,
            )
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug('%s cannot load Doctests' % module)
            continue

    environLocal.printDebug('running Tests...\n')
    runner = unittest.TextTestRunner(verbosity=verbosity)
    unused_testResult = runner.run(s1)
Ejemplo n.º 6
0
def main(testGroup=['test'], restoreEnvironmentDefaults=False, limit=None):
    '''Run all tests. Group can be test and external

    >>> print(None)
    None
    '''
    globs = __import__('music21').__dict__.copy()
    docTestOptions = (doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
    # in case there are any tests here, get a suite to load up later
    s1 = doctest.DocTestSuite(
        __name__,
        globs=globs,
        optionflags=docTestOptions
        )

    modGather = ModuleGather()
    modules = modGather.load(restoreEnvironmentDefaults)

    verbosity = 2
    if 'verbose' in sys.argv:
        verbosity = 1 # this seems to hide most display

    environLocal.printDebug('looking for Test classes...\n')
    # look over each module and gather doc tests and unittests
    totalModules = 0
    
    for module in common.sortModules(modules):
        unitTestCases = []
        if limit is not None:
            if totalModules > limit:
                break
        totalModules += 1
        # get Test classes in module
        if not hasattr(module, 'Test'):
            environLocal.printDebug('%s has no Test class' % module)
        else:
            if 'test' in testGroup:
                unitTestCases.append(module.Test)
        if not hasattr(module, 'TestExternal'):
            pass
            #environLocal.printDebug('%s has no TestExternal class\n' % module)
        else:
            if 'external' in testGroup or 'testExternal' in testGroup:
                unitTestCases.append(module.TestExternal)

        # for each Test class, load this into a suite
        for testCase in unitTestCases:
            s2 = unittest.defaultTestLoader.loadTestsFromTestCase(testCase)
            s1.addTests(s2)
        try:
            globs = __import__('music21').__dict__.copy()
            s3 = doctest.DocTestSuite(
                module,
                globs=globs,
                optionflags=docTestOptions,
                )
            s1.addTests(s3)
        except ValueError:
            environLocal.printDebug('%s cannot load Doctests' % module)
            continue
    
    environLocal.printDebug('running Tests...\n')
    runner = unittest.TextTestRunner(verbosity=verbosity)
    unused_testResult = runner.run(s1)