Ejemplo n.º 1
0
    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from -dist:")
            print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secret.py-dist file over otherwise" +
                  " tests might fail")

        pre_python26 = (sys.version_info[0] == 2
                        and sys.version_info[1] < 6)
        if pre_python26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson              # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl                     # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print("Missing dependencies: " + ", ".join(missing))
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                if (sys.version_info >= (3, 2) and sys.version_info < (3, 3) or
                   sys.version_info >= (2, 5) and sys.version_info < (2, 6)) \
                   and t.find('test_local'):
                    # Lockfile doesn't work with 2.5 and 3.2. Temporary disable
                    # local_storage test until fixes have been submitted
                    # upstream
                    continue
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'), splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 2
0
 def run(self):
     tests = TestLoader().loadTestsFromName('hetzner.tests')
     for module in PYTHON_MODULES:
         try:
             doctests = DocTestSuite(module)
         except ValueError:
             continue
         tests.addTests(doctests)
     result = TextTestRunner(verbosity=1).run(tests)
     sys.exit(not result.wasSuccessful())
Ejemplo n.º 3
0
    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'test', 'secrets.py-dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from -dist:")
            print("cp test/secrets.py-dist test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secret.py-dist file over otherwise" +
                  " tests might fail")

        pre_python26 = (sys.version_info[0] == 2 and sys.version_info[1] < 6)
        if pre_python26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson  # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl  # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print("Missing dependencies: " + ", ".join(missing))
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'),
                     splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 4
0
    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from -dist:")
            print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secrets.py-dist file over otherwise" +
                  " tests might fail")

        if pre_python26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson              # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl                     # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print("Missing dependencies: " + ", ".join(missing))
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'), splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 5
0
    def run(self):
        '''
        Finds all the tests modules in tests/, and runs them.
        '''
        testfiles = []
        for t in glob(pjoin(self._dir, 'tests', '*.py')):
            if not t.endswith('__init__.py'):
                testfiles.append('.'.join(['tests', splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)
        import eopayment
        tests.addTests(doctest.DocTestSuite(eopayment))
        t = TextTestRunner(verbosity=4)
        t.run(tests)
Ejemplo n.º 6
0
    def run(self):
        '''
        Finds all the tests modules in tests/, and runs them.
        '''
        testfiles = []
        for t in glob(pjoin(self._dir, 'tests', '*.py')):
            if not t.endswith('__init__.py'):
                testfiles.append('.'.join(
                    ['tests', splitext(basename(t))[0]])
                )

        tests = TestLoader().loadTestsFromNames(testfiles)
        import eopayment
        tests.addTests(doctest.DocTestSuite(eopayment))
        t = TextTestRunner(verbosity=4)
        t.run(tests)
Ejemplo n.º 7
0
    def _run_tests(self):
        secrets = pjoin(self._dir, 'test', 'secrets.py')
        if not os.path.isfile(secrets):
            print "Missing %s" % (secrets)
            print "Maybe you forgot to copy it from -dist:"
            print "  cp test/secrets.py-dist test/secrets.py"
            sys.exit(1)

        pre_python26 = (sys.version_info[0] == 2 and sys.version_info[1] < 6)
        if pre_python26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson  # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl  # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print "Missing dependencies: %s" % ", ".join(missing)
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'),
                     splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 8
0
    def _run_tests(self):
        secrets = pjoin(self._dir, 'test', 'secrets.py')
        if not os.path.isfile(secrets):
            print "Missing %s" % (secrets)
            print "Maybe you forgot to copy it from -dist:"
            print "  cp test/secrets.py-dist test/secrets.py"
            sys.exit(1)

        pre_python26 = (sys.version_info[0] == 2
                        and sys.version_info[1] < 6)
        if pre_python26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson              # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl                     # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print "Missing dependencies: %s" % ", ".join(missing)
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'), splitext(basename(t))[0]]))

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity = 2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 9
0
def discover_tests(start_dir, labels=[], pattern='test*.py'):
    """Discovers tests in a given module filtered by labels.  Supports
    short-cut labels as defined in :func:`find_shortcut_labels`.

    :param start_dir:
        Name of directory to begin looking in
    :param labels:
        Optional list of labels to filter the tests by
    :returns:
        :class:`TestSuite` with tests
    """
    shortcut_labels = []
    full_labels = []
    for label in labels:
        if label.startswith('='):
            shortcut_labels.append(label)
        else:
            full_labels.append(label)

    if not full_labels and not shortcut_labels:
        # no labels, get everything
        return TestLoader().discover(start_dir, pattern=pattern)

    shortcut_tests = []
    if shortcut_labels:
        suite = TestLoader().discover(start_dir, pattern=pattern)
        shortcut_tests = find_shortcut_tests(suite, shortcut_labels)

    if full_labels:
        suite = TestLoader().loadTestsFromNames(full_labels)
        suite.addTests(shortcut_tests)
    else:
        # only have shortcut labels
        suite = TestSuite(shortcut_tests)

    return suite
Ejemplo n.º 10
0
def discover_tests(start_dir, labels=[], pattern='test*.py'):
    """Discovers tests in a given module filtered by labels.  Supports
    short-cut labels as defined in :func:`find_shortcut_labels`.

    :param start_dir:
        Name of directory to begin looking in
    :param labels:
        Optional list of labels to filter the tests by
    :returns:
        :class:`TestSuite` with tests
    """
    shortcut_labels = []
    full_labels = []
    for label in labels:
        if label.startswith('='):
            shortcut_labels.append(label)
        else:
            full_labels.append(label)

    if not full_labels and not shortcut_labels:
        # no labels, get everything
        return TestLoader().discover(start_dir, pattern=pattern)

    shortcut_tests = []
    if shortcut_labels:
        suite = TestLoader().discover(start_dir, pattern=pattern)
        shortcut_tests = find_shortcut_tests(suite, shortcut_labels)

    if full_labels:
        suite = TestLoader().loadTestsFromNames(full_labels)
        suite.addTests(shortcut_tests)
    else:
        # only have shortcut labels
        suite = TestSuite(shortcut_tests)

    return suite
Ejemplo n.º 11
0
    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from -dist:")
            print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secrets.py-dist file over otherwise" +
                  " tests might fail")

        if PY2_pre_26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson  # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl  # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print("Missing dependencies: " + ", ".join(missing))
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'),
                     splitext(basename(t))[0]]))

        # Test loader simply throws "'module' object has no attribute" error
        # if there is an issue with the test module so we manually try to
        # import each module so we get a better and more friendly error message
        for test_file in testfiles:
            try:
                __import__(test_file)
            except Exception:
                e = sys.exc_info()[1]
                print('Failed to import test module "%s": %s' %
                      (test_file, str(e)))
                raise e

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
Ejemplo n.º 12
0
import unittest
from unittest import TestLoader
suite = TestLoader().discover('base')
suite.addTests(TestLoader().discover('sdl'))
suite.addTests(TestLoader().discover('shapes'))
suite.addTests(TestLoader().discover('renderer'))
unittest.TextTestRunner(verbosity=5).run(suite)
Ejemplo n.º 13
0
import unittest
from unittest import TestLoader
suite = TestLoader().discover('base')
suite.addTests(TestLoader().discover('sdl'))
unittest.TextTestRunner(verbosity=5).run(suite)
Ejemplo n.º 14
0
    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from -dist:")
            print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secrets.py-dist file over otherwise" +
                  " tests might fail")

        if PY2_pre_26:
            missing = []
            # test for dependencies
            try:
                import simplejson
                simplejson              # silence pyflakes
            except ImportError:
                missing.append("simplejson")

            try:
                import ssl
                ssl                     # silence pyflakes
            except ImportError:
                missing.append("ssl")

            if missing:
                print("Missing dependencies: " + ", ".join(missing))
                sys.exit(1)

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'), splitext(basename(t))[0]]))

        # Test loader simply throws "'module' object has no attribute" error
        # if there is an issue with the test module so we manually try to
        # import each module so we get a better and more friendly error message
        for test_file in testfiles:
            try:
                __import__(test_file)
            except Exception:
                e = sys.exc_info()[1]
                print('Failed to import test module "%s": %s' % (test_file,
                                                                 str(e)))
                raise e

        tests = TestLoader().loadTestsFromNames(testfiles)

        for test_module in DOC_TEST_MODULES:
            tests.addTests(doctest.DocTestSuite(test_module))

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()