示例#1
0
 def run(self, ):
     loader = TestLoader()
     tests = loader.discover('.', 'test_*.py')
     t = XMLTestRunner(verbosity=1, output=self.TEST_RESULTS)
     res = t.run(tests)
     if not res.wasSuccessful():
         raise FailTestException()
示例#2
0
def main(useXMLRunner=True):
    # load hard-coded tests
    unitsuite = unittest.makeSuite(UnitTests)
    modelsuite = unittest.makeSuite(ModelTests)
    funsuite = unittest.makeSuite(FunctionalTests)

    # load recorded tests
    os.chdir('test/recordedtests')
    tests = glob.glob("recordedtest_*.py")  # get all the recorded tests
    for test in tests:
        mod, ext = os.path.splitext(os.path.split(test)[-1])
        m = __import__(mod)  # dynamic import magic
        testname = "testMethod" + mod[-3:]  # recover test number
        setattr(RecordedTests, testname, m.testMethod)
    os.chdir('../..')
    recsuite = unittest.makeSuite(RecordedTests)

    # combine and run tests
    alltests = unittest.TestSuite([unitsuite, modelsuite, funsuite, recsuite])
    if useXMLRunner:
        stream = file("testresults.xml", "w")
        runner = XMLTestRunner(stream)
        result = runner.run(alltests)
        stream.close()
    else:
        runner = unittest.TextTestRunner(verbosity=2)
        result = runner.run(alltests)
    return result
示例#3
0
def run_tests ():
    suite = unittest.TestSuite ()
    loader = unittest.TestLoader ()

    suite.addTest (loader.loadTestsFromModule (CsvToolTester))

    runner = XMLTestRunner(file('testoutput.xml', "w"))
    result = runner.run(suite)
示例#4
0
def main():
    # type: () -> int
    """
    Run tests given is sys.argv.

    Returns 0 if success or 1 if any tests fail.
    """
    try:
        from xmlrunner import XMLTestRunner as TestRunner
        test_args = { 'output': 'logs' }
    except ImportError:
        from unittest import TextTestRunner as TestRunner
        test_args = { }

    models = sys.argv[1:]
    if models and models[0] == '-v':
        verbosity = 2
        models = models[1:]
    else:
        verbosity = 1
    if models and models[0] == 'opencl':
        if not HAVE_OPENCL:
            print("opencl is not available")
            return 1
        loaders = ['opencl']
        models = models[1:]
    elif models and models[0] == 'dll':
        # TODO: test if compiler is available?
        loaders = ['dll']
        models = models[1:]
    elif models and models[0] == 'opencl_and_dll':
        loaders = ['opencl', 'dll']
        models = models[1:]
    else:
        loaders = ['opencl', 'dll']
    if not models:
        print("""\
usage:
  python -m sasmodels.model_test [-v] [opencl|dll] model1 model2 ...

If -v is included on the command line, then use verbose output.

If neither opencl nor dll is specified, then models will be tested with
both OpenCL and dll; the compute target is ignored for pure python models.

If model1 is 'all', then all except the remaining models will be tested.

""")

        return 1

    runner = TestRunner(verbosity=verbosity, **test_args)
    result = runner.run(make_suite(loaders, models))
    return 1 if result.failures or result.errors else 0
示例#5
0
def run_tests():
    # type: () -> None
    """Run all the tests."""

    # my-py's typeshed does not have defaultTestLoader and TestLoader type information so suppresss
    # my-py type information.
    all_tests = unittest.defaultTestLoader.discover(start_dir="tests")  # type: ignore

    runner = XMLTestRunner(verbosity=2, failfast=False, output='results')
    result = runner.run(all_tests)

    sys.exit(not result.wasSuccessful())
示例#6
0
    def configure(self, options):
        '''configure before testing'''
        self.test_options = options
        if options.xunit:
            try:
                from xmlrunner import XMLTestRunner
            except ImportError:
                raise Exception("unittest-xml-reporting not installed")
            self.runner = XMLTestRunner(stream=sys.stderr, \
                                        verbosity=2, output=options.xunit)
        else:
            self.runner = unittest.TextTestRunner(stream=sys.stderr, \
                                                  verbosity=2)

        if options.manifest:
            fbname, fext = os.path.splitext(os.path.basename(options.manifest))
            assert fbname == "manifest" or fext == ".manifest", \
                  "Please specify file name like xxx.manifest or manifest.xxx"
            self.tclist = self.__get_tc_from_manifest(options.manifest)

        if options.tests:
            tcs = [t[0:-3] if t.endswith(".py") else t[0:-1] \
                               if t.endswith("/") else t for t in options.tests]
            self.tclist.extend([tc.replace("/", ".") for tc in tcs])

        if options.logdir:
            logdir = self._get_log_dir(options.logdir)
            self.log_handler = LogHandler(logdir)

        try:
            self.context.def_timeout = int(options.timeout)
        except ValueError:
            print "timeout need an integer value"
            raise
示例#7
0
文件: runall.py 项目: divita/cadnano2
def main(useXMLRunner=True):
    # load hard-coded tests
    unitsuite = unittest.makeSuite(UnitTests)
    modelsuite = unittest.makeSuite(ModelTests)
    funsuite = unittest.makeSuite(FunctionalTests)

    # combine and run tests
    alltests = unittest.TestSuite([unitsuite, modelsuite, funsuite])
    if useXMLRunner:
        stream = file("testresults.xml", "w")
        runner = XMLTestRunner(stream)
        result = runner.run(alltests)
        stream.close()
    else:
        runner = unittest.TextTestRunner(verbosity=2)
        result = runner.run(alltests)
    return result
示例#8
0
def runtests():
    suite = unittest.defaultTestLoader.loadTestsFromNames(['tests.unit.avs_result_test',
                                                           'tests.unit.cvv_result_test',
                                                           'tests.unit.credit_card_tests',
                                                           'tests.unit.gateways.authorize_net_tests',
                                                           'tests.unit.gateways.bogus_tests',
                                                           'tests.unit.gateways.braintree_blue_tests',
                                                           'tests.unit.gateways.braintree_orange_tests',
                                                           'tests.unit.gateways.cybersource_tests',
                                                           'tests.unit.gateways.payflow_tests',
                                                           'tests.unit.gateways.paymentech_orbital_tests',])
    if os.environ.get('XML_OUTPUT', False):
        from xmlrunner import XMLTestRunner
        runner = XMLTestRunner()
    else:
        runner = unittest.TextTestRunner(verbosity=1, descriptions=False)
    result = runner.run(suite).wasSuccessful()
    exit_code = 0 if result else 1
    sys.exit(exit_code)
示例#9
0
    def run(self, ):

        # Perform imports in run to avoid test dependencies in setup
        from xmlrunner import XMLTestRunner
        import coverage
        from unittest import TestLoader

        loader = TestLoader()
        tests = loader.discover('.', 'test_*.py')
        t = XMLTestRunner(verbosity=1, output=self.TEST_RESULTS)

        cov = coverage.Coverage(
            omit=['*/tests/', 'test_*.py', ],
            source=self.MODULE_NAMES,
        )
        cov.start()
        t.run(tests)
        cov.stop()
        cov.save()
        cov.xml_report(outfile=self.COVERAGE_RESULTS)
示例#10
0
    def run(self):
        # Installing required packages, running egg_info and build_ext are
        # part of normal operation for setuptools.command.test.test
        if self.distribution.install_requires:
            self.distribution.fetch_build_eggs(
                self.distribution.install_requires)
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)
        if self.xunit_output:
            if sys.version_info[:2] == (2, 6):
                self.distribution.fetch_build_eggs(
                    ["unittest-xml-reporting>=1.14.0,<2.0.0a0"])
            else:
                self.distribution.fetch_build_eggs(["unittest-xml-reporting"])
        self.run_command('egg_info')
        build_ext_cmd = self.reinitialize_command('build_ext')
        build_ext_cmd.inplace = 1
        self.run_command('build_ext')

        # Construct a TextTestRunner directly from the unittest imported from
        # test (this will be unittest2 under Python 2.6), which creates a
        # TestResult that supports the 'addSkip' method. setuptools will by
        # default create a TextTestRunner that uses the old TestResult class,
        # resulting in DeprecationWarnings instead of skipping tests under 2.6.
        from test import unittest, PymongoTestRunner, test_cases
        if self.test_suite is None:
            all_tests = unittest.defaultTestLoader.discover(self.test_module)
            suite = unittest.TestSuite()
            suite.addTests(sorted(test_cases(all_tests),
                                  key=lambda x: x.__module__))
        else:
            suite = unittest.defaultTestLoader.loadTestsFromName(
                self.test_suite)
        if self.xunit_output:
            from xmlrunner import XMLTestRunner
            runner = XMLTestRunner(verbosity=2, failfast=self.failfast,
                                   output=self.xunit_output)
        else:
            runner = PymongoTestRunner(verbosity=2, failfast=self.failfast)
        result = runner.run(suite)
        sys.exit(not result.wasSuccessful())
示例#11
0
 def runTest(self, isSilent=False):
     '''
     if isSilent is False then sys.stderr will be used as output of result.
     Otherwise output will be saved to the file.
     Read documentation of TextTestRunner for more information.
     '''
     paramDic = {'stream': None, 'verbosity': 2, 'output': 'test-reports'}
     if isSilent:
        paramDic['stream'] = open(self.outLogFile, 'w')
     suite = unittest.TestLoader().loadTestsFromTestCase(self.cTest)
     self.result = XMLTestRunner(**paramDic).run(suite)
     if paramDic['stream']:
        paramDic['stream'].close()
     self.checkResult(isSilent)
示例#12
0
class testResult(object):
    def __init__(self, testClass):
        self.cTest = testClass
        self.outLogFile = self.cTest.get_out_path('test_result.log')

    def runTest(self, isSilent=False):
        '''
        if isSilent is False then sys.stderr will be used as output of result.
        Otherwise output will be saved to the file.
        Read documentation of TextTestRunner for more information.
        '''
        paramDic = {'stream': None, 'verbosity': 2, 'output': 'test-reports'}
        if isSilent:
           paramDic['stream'] = open(self.outLogFile, 'w')
        suite = unittest.TestLoader().loadTestsFromTestCase(self.cTest)
        self.result = XMLTestRunner(**paramDic).run(suite)
        if paramDic['stream']:
           paramDic['stream'].close()
        self.checkResult(isSilent)

    def checkResult(self, isSilent=False):
        '''
        Value of isSilent is processed conversely to the runTest method.
        if isSilent is False then output will be saved to the file.
        Otherwise output will be printed to the sys.stderr.
        '''
        if self.result.wasSuccessful():
           return

        myOutFile = sys.stderr
        if not isSilent:
           myOutFile = open(self.outLogFile, 'w')

        if self.result.errors:
           print('ERRORS:', sep='\n', end='\n', file=myOutFile)
        for r in self.result.errors:
           print(*r, sep='\n', end='\n', file=myOutFile)

        if self.result.failures:
           print('FAILURES:', sep='\n', end='\n', file=myOutFile)
        for r in self.result.failures:
           print(*r, sep='\n', end='\n', file=myOutFile)
        myOutFile.close()
        return runner.run(self_test_suite).wasSuccessful()

    if not self_valid():
        print("Check OPI format test script failed own tests. Aborting")
        sys.exit(1)

    return_values = []
    xml_parser = etree.XMLParser(remove_blank_text=True)

    # Add test suite a dynamic number of times with an argument.
    # unittest's test loader is unable to take arguments to test classes by default so have
    # to use the getTestCaseNames() syntax and explicitly add the argument ourselves.
    for filename in file_iterator(root_dir, single_file):

        print("Testing '{}'".format(filename))

        suite = unittest.TestSuite()

        try:
            root = etree.parse(filename, xml_parser)
        except LxmlError as e:
            print("XML failed to parse {}".format(e))
            return_values.append(False)
            continue

        suite.addTests([CheckOpiFormat(test, root) for test in loader.getTestCaseNames(CheckOpiFormat)])
        runner = XMLTestRunner(output=os.path.join(logs_dir, filename), stream=sys.stdout)
        return_values.append(runner.run(suite).wasSuccessful())

    sys.exit(False in return_values)
示例#14
0
import sys
import unittest

from os.path import dirname
from xmlrunner import XMLTestRunner

from mycroft.configuration import ConfigurationManager

__author__ = 'seanfitz, jdorleans'
if __name__ == "__main__":
    fail_on_error = "--fail-on-error" in sys.argv
    ConfigurationManager.load_local(['mycroft.ini'])

    tests = unittest.TestLoader().discover(dirname(__file__), "*.py")
    runner = XMLTestRunner("./build/report/tests")
    result = runner.run(tests)

    if fail_on_error and len(result.failures + result.errors) > 0:
        sys.exit(1)
示例#15
0
  # setting up logging
  log_opt = args['logging']
  logger = logging.getLogger(globals.LOGGER_NAME)
  if log_opt == 'INFO':
    logger.level = logging.INFO
  elif log_opt == 'DEBUG':
    logger.level = logging.DEBUG

  test_context = TestContext(
      ENGINE_DIRECTORY, DATA_DIRECTORY,
      args['eventserver_ip'], int(args['eventserver_port']))

  tests_dict = get_tests(test_context)
  test_names = args['tests']
  tests = []
  if test_names is not None:
    tests = [t for name, t in tests_dict.items() if name in test_names]
  else:
    tests = tests_dict.values()

  # Actual tests execution
  event_server_process = srun_bg('pio eventserver --ip {} --port {}'
      .format(test_context.es_ip, test_context.es_port))
  time.sleep(5)
  result = XMLTestRunner(verbosity=2, output='test-reports').run(
                unittest.TestSuite(tests))
  event_server_process.kill()

  if not result.wasSuccessful():
    sys.exit(1)
示例#16
0
#!/usr/bin/env python

import sys
import unittest
from xmlrunner import XMLTestRunner


if __name__ == "__main__":
    py_version = "v{0}{1}".format(*sys.version_info[:2])
    test_suite = unittest.TestLoader().discover("djcopybook")
    runner = XMLTestRunner(verbosity=2, output="jenkins_reports", outsuffix=py_version)
    result = runner.run(test_suite)

    sys.exit(not result.wasSuccessful)
示例#17
0
#!/usr/bin/env python
"Defines the unit tests for the application."
from  xmlrunner import XMLTestRunner
import testsuite
import sys


if __name__ == '__main__': 
    runner = XMLTestRunner(sys.stdout)
    runner.run(testsuite.suite)
 def self_valid():
     self_test_suite = unittest.TestSuite()
     self_test_suite.addTests(loader.loadTestsFromTestCase(TestCheckOpiFormatMethods))
     runner = XMLTestRunner(output=os.path.join(logs_dir, "check_opi_format"), stream=sys.stdout)
     return runner.run(self_test_suite).wasSuccessful()
示例#19
0
class TestRunnerBase(object):
    '''test runner base '''
    def __init__(self, context=None):
        self.tclist = []
        self.runner = None
        self.context = context if context else TestContext()
        self.test_options = None
        self.log_handler = None
        self.test_result = None
        self.run_time = None
        self.option_list = [
            make_option("-f", "--manifest", dest="manifest",
                        help="The test list file"),
            make_option("-x", "--xunit", dest="xunit",
                        help="Output result path of in xUnit XML format"),
            make_option("-l", "--log-dir", dest="logdir",
                        help="Set log dir."),
            make_option("-a", "--tag-expression", dest="tag",
                        help="Set tag expression to filter test cases."),
            make_option("-T", "--timeout", dest="timeout", default=60,
                        help="Set timeout for each test case."),
            make_option("-e", "--tests", dest="tests", action="append",
                        help="Run tests by dot separated module path")
        ]

    def __del__(self):
        """
        Because unittest.TestCase is a class object, it will exist as long as the python virtual machine process.
        So tc can't be released if we don't release them explicitly.
        """
        if hasattr(unittest.TestCase, "tc"):
            delattr(unittest.TestCase, "tc")

    @staticmethod
    def __get_tc_from_manifest(fname):
        '''get tc list from manifest format '''
        with open(fname, "r") as f:
            tclist = [n.strip() for n in f.readlines() \
                                if n.strip() and not n.strip().startswith('#')]
        return tclist

    @staticmethod
    def _get_log_dir(logdir):
        '''get the log directory'''
        if os.path.exists(logdir):
            shutil.rmtree(logdir)
        os.makedirs(logdir)
        return logdir

    def get_options(self, default=False):
        '''handle testrunner options'''
        parser = OptionParser(option_list=self.option_list, \
                                usage="usage: %prog [options]")
        if default:
            return parser.parse_args(args=[])[0]
        return parser.parse_args()[0]

    def configure(self, options):
        '''configure before testing'''
        self.test_options = options
        if options.xunit:
            try:
                from xmlrunner import XMLTestRunner
            except ImportError:
                raise Exception("unittest-xml-reporting not installed")
            self.runner = XMLTestRunner(stream=sys.stderr, \
                                        verbosity=2, output=options.xunit)
        else:
            self.runner = unittest.TextTestRunner(stream=sys.stderr, \
                                                  verbosity=2)

        if options.manifest:
            fbname, fext = os.path.splitext(os.path.basename(options.manifest))
            assert fbname == "manifest" or fext == ".manifest", \
                  "Please specify file name like xxx.manifest or manifest.xxx"
            self.tclist = self.__get_tc_from_manifest(options.manifest)

        if options.tests:
            tcs = [t[0:-3] if t.endswith(".py") else t[0:-1] \
                               if t.endswith("/") else t for t in options.tests]
            self.tclist.extend([tc.replace("/", ".") for tc in tcs])

        if options.logdir:
            logdir = self._get_log_dir(options.logdir)
            self.log_handler = LogHandler(logdir)

        try:
            self.context.def_timeout = int(options.timeout)
        except ValueError:
            print "timeout need an integer value"
            raise

    def result(self):
        '''output test result '''
        print "output test result..."

    def loadtest(self, names=None):
        '''load test suite'''
        if not names:
            names = self.tclist
        testloader = unittest.TestLoader()
        tclist = []
        for name in names:
            tset = testloader.loadTestsFromName(name)
            if tset.countTestCases() > 0:
                tclist.append(tset)
            elif tset._tests == []:
                tclist.append(testloader.discover(name, "[!_]*.py", os.path.curdir))
        return testloader.suiteClass(tclist)

    def filtertest(self, testsuite):
        '''filter test set'''
        if self.test_options.tag:
            return filter_tagexp(testsuite, self.test_options.tag)
        return testsuite

    def runtest(self, testsuite):
        '''run test suite'''
        starttime = time.time()
        self.test_result = self.runner.run(testsuite)
        self.run_time = time.time() - starttime

    def start(self, testsuite):
        '''start testing'''
        if self.log_handler:
            self.log_handler.start()
        set_timeout(testsuite, self.context.def_timeout)
        setattr(unittest.TestCase, "tc", self.context)
        self.runtest(testsuite)
        self.result()
        if self.log_handler:
            self.log_handler.end()
示例#20
0
import optparse
import os
import sys
from xmlrunner import XMLTestRunner

try:
    from unittest2 import TestLoader, TextTestRunner
except ImportError:
    from unittest import TestLoader, TextTestRunner

base_path = os.path.dirname(__file__)

parser = optparse.OptionParser()
parser.add_option("-x", "--xml-prefix",
                  dest="xml_prefix",
                  help="generate XML test report in given directory",
                  default=None)
(options, args) = parser.parse_args()

loader = TestLoader()
tests  = loader.discover(os.path.join(base_path, 'cvmfs/test'),
                         pattern='*_test.py')

runner = None
if options.xml_prefix:
  runner = XMLTestRunner(output=options.xml_prefix, verbosity=2)
else:
  runner = TextTestRunner(verbosity=2)

runner.run(tests)