Ejemplo n.º 1
0
def run_test_suite(suite):
    test_runner = nose.core.TextTestRunner(verbosity=2)

    if TEST_MODE == 'ci':
        from teamcity.unittestpy import TeamcityTestRunner
        test_runner = TeamcityTestRunner()

    return test_runner.run(suite)
Ejemplo n.º 2
0
 def _run_tests_randomly():
     unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: random.choice(
         [-1, 1])
     if is_running_under_teamcity():
         runner = TeamcityTestRunner()
     else:
         runner = unittest.TextTestRunner()
     unittest.main(testRunner=runner)
Ejemplo n.º 3
0
def run_tests(path):
    pat, paths = "test", []
    search_path_pat(path, pat, paths)
    for path in paths:
        test = unittest.TestLoader().discover(path, "test*py")
        if is_running_under_teamcity():
            TeamcityTestRunner(verbosity=2).run(test)
        else:
            unittest.TextTestRunner(verbosity=2).run(test)
Ejemplo n.º 4
0
def get_test_runner():
    import unittest
    try:
        from teamcity import is_running_under_teamcity
        from teamcity.unittestpy import TeamcityTestRunner
        from teamcity.unittestpy import TeamcityServiceMessages
        if is_running_under_teamcity():
            runner = TeamcityTestRunner()
        else:
            runner = unittest.TextTestRunner()
    except ModuleNotFoundError:
        runner = unittest.TextTestRunner()
    return runner
Ejemplo n.º 5
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """
    Run the unit tests for all the test labels in the provided list.
    Labels must be of the form:
     - app.TestClass.test_method
        Run a single specific test method
     - app.TestClass
        Run all the test methods in a given class
     - app
        Search for doctests and unittests in the named application.

    When looking for tests, the test runner will look in the models and
    tests modules for the application.

    A list of 'extra' tests may also be provided; these tests
    will be added to the test suite.

    Returns the number of tests that failed.
    """
    setup_test_environment()

    settings.DEBUG = False
    suite = unittest.TestSuite()

    if test_labels:
        for label in test_labels:
            if '.' in label:
                suite.addTest(build_test(label))
            else:
                app = get_app(label)
                suite.addTest(build_suite(app))
    else:
        for app in get_apps():
            suite.addTest(build_suite(app))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase, ))

    old_name = settings.DATABASE_NAME
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    result = TeamcityTestRunner().run(suite)
    connection.creation.destroy_test_db(old_name, verbosity)

    teardown_test_environment()

    return len(result.failures) + len(result.errors)
Ejemplo n.º 6
0
def test(teamcity, verbosity):
    loader = unittest.TestLoader()
    tests = loader.discover(TESTS_DIR, pattern='test*.py')

    if teamcity:
        runner = TeamcityTestRunner()
    else:
        runner = unittest.TextTestRunner(verbosity=verbosity)

    result = runner.run(tests)

    exit_code = 1
    if result.wasSuccessful():
        exit_code = 0

    sys.exit(exit_code)
Ejemplo n.º 7
0
def monkeypatch_teamcity_runner():
    try:
        import unittest
        from teamcity import underTeamcity
        from teamcity.unittestpy import TeamcityTestRunner
        runner = TeamcityTestRunner() if underTeamcity(
        ) else unittest.TextTestRunner()
        org_main = unittest.main

        def monkey_patch(*args, **kwargs):
            kwargs['testRunner'] = runner
            org_main(*args, **kwargs)

        unittest.main = monkey_patch
    except ImportError:
        print "Missing teamcity-messages package for running tests in Teamcity."
        print "Refusing to even try enabling it!"
Ejemplo n.º 8
0
__author__ = 'broken'
from teamcity.unittestpy import TeamcityTestRunner
import unittest
from gaetestbed import DataStoreTestCase
from Pac.DataFactory.dbUser import User
from Pac import Setup

class TestSetup(DataStoreTestCase, unittest.TestCase):
    def test_add_user(self):
        self.assertEqual(User.all().count(), 0)

        Setup.addFirstTimeUser()

        self.assertEqual(User.all().count(), 1)
        ## Rerun
        Setup.addFirstTimeUser()
        self.assertEqual(User.all().count(), 1)

    def test_get_all_users(self):
        self.assertTrue(User.all() > 0)

if __name__ == '__main__':
    unittest.main(testRunner=TeamcityTestRunner())
Ejemplo n.º 9
0
        aae(actual_libor3_df, expected_libor3_df)
        aae(actual_sonia_df, expected_sonia_df)

        risk_engine = RiskCalculator(curve_builder, build_output)
        instrument_regex = "USD/.*"
        numpy.testing.assert_equal(len(risk_engine.find_instruments(instrument_regex)), 32)
        instruments_to_bump = risk_engine.find_instruments(instrument_regex)
        bumped_curves = risk_engine.get_bumped_curvemap(instruments_to_bump, 1e-4, BumpType.FULL_REBUILD)
        bumped_curves_jacobian = risk_engine.get_bumped_curvemap(instruments_to_bump, 1e-4, BumpType.JACOBIAN_REBUILD)

        numpy.testing.assert_equal(len(bumped_curves), len(bumped_curves_jacobian))

        test_pillars = linspace(eval_date + 30, eval_date + 50 * 365, 15)
        for curve_name in sorted(bumped_curves.keys()):
            c0 = build_output.output_curvemap[curve_name]
            c1 = bumped_curves[curve_name]
            c2 = bumped_curves_jacobian[curve_name]
            zr0 = c0.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365)
            zr1 = c1.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365)
            zr2 = c2.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365)
            bumpdiff = max(abs((zr2 - zr0) / zr0))
            error = max(abs((zr2 - zr1) / zr1))
            self.assertLess(error, bumpdiff / 100.)


if __name__ == '__main__':
    if is_running_under_teamcity():
        runner = TeamcityTestRunner()
    else:
        runner = unittest.TextTestRunner()
    unittest.main(testRunner=runner)
Ejemplo n.º 10
0
import unittest

from teamcity import is_running_under_teamcity
from teamcity.unittestpy import TeamcityTestRunner

if __name__ == "__main__":
    all_tests = unittest.TestLoader().discover(start_dir='githubcommit', pattern='*_test.py')
    if is_running_under_teamcity():
        TeamcityTestRunner().run(all_tests)
    else:
        unittest.TextTestRunner().run(all_tests)
Ejemplo n.º 11
0
import unittest

from teamcity.unittestpy import TeamcityTestRunner


class TestXXX(unittest.TestCase):
    def runTest(self):
        self.fail("Grr")


TeamcityTestRunner().run(TestXXX())
Ejemplo n.º 12
0
    Factorials of floats are OK, but the float must be an exact integer:
    >>> factorial(30.1)
    Traceback (most recent call last):
        ...
    ValueError: n must be exact integer

    It must also not be ridiculously large:
    >>> factorial(1e100)
    Traceback (most recent call last):
        ...
    OverflowError: n too large
    """

    import math
    if not n >= 0:
        raise ValueError("n must be >= 0")
    if math.floor(n) != n:
        raise ValueError("n must be exact integer")
    if n+1 == n:  # catch a value like 1e300
        raise OverflowError("n too large")
    result = 1
    factor = 2
    while factor <= n:
        result *= factor
        factor += 1
    return result


TeamcityTestRunner().run(doctest.DocTestSuite(sys.modules[__name__]))
Ejemplo n.º 13
0
# coding=utf-8
import sys

from teamcity.unittestpy import TeamcityTestRunner

from unittest import TestCase, main


class SpamTest(TestCase):
    @classmethod
    def setUpClass(cls):
        print("1")

    def test_test(self):
        print("stdout_test1")
        print("stdout_test2")
        sys.stderr.write("stderr_")
        sys.stderr.write("test1")
        sys.stderr.flush()

        sys.stderr.write("stderr_test2")
        raise Exception("A")

    @classmethod
    def tearDownClass(cls):
        print("3")


main(testRunner=TeamcityTestRunner(buffer=True))
Ejemplo n.º 14
0
def run(suite):
    if is_running_under_teamcity():
        runner = TeamcityTestRunner()
    else:
        runner = unittest.TextTestRunner()
    runner.run(suite)
Ejemplo n.º 15
0
                    continue
                    
                # Import the test file and find all TestClass clases inside it.
                module_name = '%s.%s' % (module, filename[:-3])
                # logging.critical('adding %s' % module_name)
                # test_suite.addTest(unittest.TestLoader().loadTestsFromName(module_name))
                test_module = __import__(module_name, {}, {}, filename[:-3])
                test_suite.addTest(unittest.TestLoader().loadTestsFromModule(test_module))

        return test_suite

    except Exception:
        logging.critical("Error loading tests.", exc_info=1)
        raise SystemExit("Error loading tests.")

if __name__ == "__main__":

    sys.path.insert(0, os.path.join(os.environ['APPENGINEDIR'], 'lib', 'django'))
    os.environ['SERVER_SOFTWARE'] = 'Development/unittest' # to ensure correct reloading of config/FSM

    import sys
    if len(sys.argv) > 1:
        # tests specified
        test_suite = unittest.TestLoader().loadTestsFromNames(sys.argv[1:])
    else:
        test_suite = suite()
    if teamcity.underTeamcity():
        TeamcityTestRunner().run(test_suite)
    else:
        unittest.TextTestRunner(verbosity=int(os.environ.get('UNITTEST_VERBOSITY', 1))).run(test_suite)
Ejemplo n.º 16
0
from simple_tests import SimpleTests
from nose.loader import TestLoader
from teamcity.unittestpy import TeamcityTestRunner

if __name__ == '__main__':
    test_loader = TestLoader().loadTestsFromTestClass(SimpleTests)
    TeamcityTestRunner().run(test_loader)
Ejemplo n.º 17
0
 def run_suite(self, suite, **kwargs):
     return TeamcityTestRunner().run(suite)
 def run_suite(self, suite, **kwargs):
     if is_running_under_teamcity():
         return TeamcityTestRunner().run(suite)
     else:
         return unittest.TextTestRunner(verbosity=self.verbosity,
                                        failfast=self.failfast).run(suite)