def test_fixture_context_multiple_names_no_common_ancestors(self):
        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 2)
        wd = os.path.join(support, 'ltfn')
        l = loader.TestLoader(workingDir=wd)
        suite = l.loadTestsFromNames(
            ['test_pak1.test_mod',
             'test_pak2:test_two_two',
             'test_mod'])
        print suite
        suite(res)
        res.printErrors()
        print stream.getvalue()
        assert not res.errors, res.errors
        assert not res.failures, res.failures
        assert 'state' in sys.modules, \
               "Context not load state module"
        m = sys.modules['state']
        print "state", m.called

        expect = ['test_pak1.setup',
                  'test_pak1.test_mod.setup',
                  'test_pak1.test_mod.test_one_mod_one',
                  'test_pak1.test_mod.teardown',
                  'test_pak1.teardown',
                  'test_pak2.setup',
                  'test_pak2.test_two_two',
                  'test_pak2.teardown',
                  'test_mod.setup',
                  'test_mod.test_mod',
                  'test_mod.teardown']
        self.assertEqual(m.called, expect, diff(expect, m.called))
Exemple #2
0
	def __init__(self, testResults = None):
		stream = sys.stderr
		self.stream = unittest._WritelnDecorator(stream)
		self.descriptions = True
		self.verbosity = 1
		if not testResults:
			testResults = [unittest._TextTestResult(self.stream, self.descriptions, self.verbosity)]
		self.testResults = testResults
def test():
    import sys
    suite = unittest.makeSuite(TestPythonProperties)
    tr = unittest._TextTestResult(unittest._WritelnDecorator(sys.stderr),
                                  'DESCs', 2)
    try:
        suite(tr)
    except Exception, e:
        print "eee", e
    def test_load_nonsense_name(self):
        ctx = os.path.join(support, 'ctx')
        l = loader.TestLoader(workingDir=ctx)
        suite = l.loadTestsFromName('fred!')

        res = unittest._TextTestResult(
            stream=unittest._WritelnDecorator(sys.stdout),
            descriptions=0, verbosity=1)
        suite(res)
        print res.errors
        assert res.errors, "Expected errors but got none"
        assert not res.failures, res.failures
Exemple #5
0
 def run(self, test):
     global total_test_count
     global error_test_count
     result = unittest._TextTestResult(self.stream, True, 1)
     test(result)
     if not result.wasSuccessful():
         self.stream.write(' FAIL:')
         result.printErrors()
         failed.append(self.testname)
     else:
         self.stream.write(' ok\n')
     total_test_count += result.testsRun
     error_test_count += len(result.errors) + len(result.failures)
     return result
Exemple #6
0
 def run(self, test):
     global total_test_count
     global error_test_count
     result = unittest._TextTestResult(self.stream, True, 1)
     test(result)
     if not result.wasSuccessful():
         self.stream.write(' FAIL:')
         result.printErrors()
         failed.append(self.testname)
     else:
         self.stream.write(' ok\n')
     total_test_count += result.testsRun
     error_test_count += len(result.errors) + len(result.failures)
     return result
    def test_failed_import(self):
        ctx = os.path.join(support, 'ctx')
        l = loader.TestLoader(workingDir=ctx)
        suite = l.loadTestsFromName('no_such_module.py')

        res = unittest._TextTestResult(
            stream=unittest._WritelnDecorator(sys.stdout),
            descriptions=0, verbosity=1)
        suite(res)

        print res.errors
        res.printErrors()
        assert res.errors, "Expected errors but got none"
        assert not res.failures, res.failures
        assert res.testsRun == 1, \
               "Expected to run 1 tests but ran %s" % res.testsRun
    def test_failed_import_module_name(self):
        ctx = os.path.join(support, 'ctx')
        l = loader.TestLoader(workingDir=ctx)
        suite = l.loadTestsFromName('no_such_module')

        res = unittest._TextTestResult(
            stream=unittest._WritelnDecorator(sys.stdout),
            descriptions=0, verbosity=1)
        suite(res)
        print res.errors
        res.printErrors()
        assert res.errors, "Expected errors but got none"
        assert not res.failures, res.failures
        err = res.errors[0][0].test.exc_class
        assert err is ImportError, \
            "Expected import error, got %s" % err
    def test_generator_with_closure(self):
        """Test that a generator test can employ a closure

        Issue #3. If the generator binds early, the last value
        of the closure will be seen for each generated test and
        the tests will fail.
        """
        gen = os.path.join(support, 'gen')
        l = loader.TestLoader(workingDir=gen)
        suite = l.loadTestsFromName('test')
        res = unittest._TextTestResult(
            stream=unittest._WritelnDecorator(sys.stdout),
            descriptions=0, verbosity=1)
        suite(res)
        assert not res.errors
        self.assertEqual(res.testsRun, 5)
Exemple #10
0
    def test_prepare_patches_result(self):
        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Skip()
        sk.prepareTestResult(res)
        res._orig_addError
        res._orig_printErrors
        res._orig_wasSuccessful
        res.skipped
        self.assertEqual(res.errorClasses, {SkipTest: (res.skipped, "SKIP", False)})

        # result w/out print works too
        res = unittest.TestResult()
        sk = Skip()
        sk.prepareTestResult(res)
        res._orig_addError
        res.skipped
        self.assertEqual(res.errorClasses, {SkipTest: (res.skipped, "SKIP", False)})
    def test_prepare_patches_result(self):
        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Skip()
        sk.prepareTestResult(res)
        res._orig_addError
        res._orig_printErrors
        res._orig_wasSuccessful
        res.skipped
        self.assertEqual(res.errorClasses,
                         {SkipTest: (res.skipped, 'SKIP', False)})

        # result w/out print works too
        res = unittest.TestResult()
        sk = Skip()
        sk.prepareTestResult(res)
        res._orig_addError
        res.skipped
        self.assertEqual(res.errorClasses,
                         {SkipTest: (res.skipped, 'SKIP', False)})
Exemple #12
0
    def test_skip_output(self):
        class TC(unittest.TestCase):
            def test(self):
                raise SkipTest("skip me")

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Skip()
        sk.prepareTestResult(res)

        test = TC("test")
        test(res)
        assert not res.errors, "Skip was not caught: %s" % res.errors
        assert res.skipped

        res.printErrors()
        out = stream.getvalue()
        assert out
        assert out.strip() == "S"
        assert res.wasSuccessful()
    def test_deprecated_output(self):
        class TC(unittest.TestCase):
            def test(self):
                raise DeprecatedTest('deprecated me')

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Deprecated()
        sk.prepareTestResult(res)

        test = TC('test')
        test(res)
        assert not res.errors, "Deprecated was not caught: %s" % res.errors
        assert res.deprecated            

        res.printErrors()
        out = stream.getvalue()
        assert out
        assert out.strip() == "D"
        assert res.wasSuccessful()
    def test_skip_output(self):
        class TC(unittest.TestCase):
            def test(self):
                raise SkipTest('skip me')

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Skip()
        sk.prepareTestResult(res)

        test = TC('test')
        test(res)
        assert not res.errors, "Skip was not caught: %s" % res.errors
        assert res.skipped

        res.printErrors()
        out = stream.getvalue()
        assert out
        assert out.strip() == "S"
        assert res.wasSuccessful()
Exemple #15
0
    def test_deprecated_output(self):
        class TC(unittest.TestCase):
            def test(self):
                raise DeprecatedTest('deprecated me')

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Deprecated()
        sk.prepareTestResult(res)

        test = TC('test')
        test(res)
        assert not res.errors, "Deprecated was not caught: %s" % res.errors
        assert res.deprecated

        res.printErrors()
        out = stream.getvalue()
        assert out
        assert out.strip() == "D"
        assert res.wasSuccessful()
    def test_skip_output_verbose(self):
        class TC(unittest.TestCase):
            def test(self):
                raise SkipTest('skip me too')

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, verbosity=2)
        sk = Skip()
        sk.prepareTestResult(res)
        test = TC('test')
        test(res)
        assert not res.errors, "Skip was not caught: %s" % res.errors
        assert res.skipped

        res.printErrors()
        out = stream.getvalue()
        print out
        assert out

        assert ' ... SKIP' in out
        assert 'skip me too' in out
Exemple #17
0
    def test_skip_output_verbose(self):
        class TC(unittest.TestCase):
            def test(self):
                raise SkipTest("skip me too")

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, verbosity=2)
        sk = Skip()
        sk.prepareTestResult(res)
        test = TC("test")
        test(res)
        assert not res.errors, "Skip was not caught: %s" % res.errors
        assert res.skipped

        res.printErrors()
        out = stream.getvalue()
        print out
        assert out

        assert " ... SKIP" in out
        assert "skip me too" in out
Exemple #18
0
    def test_deprecated_output_verbose(self):
        class TC(unittest.TestCase):
            def test(self):
                raise DeprecatedTest('deprecated me too')

        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, verbosity=2)
        sk = Deprecated()
        sk.prepareTestResult(res)
        test = TC('test')
        test(res)
        assert not res.errors, "Deprecated was not caught: %s" % res.errors
        assert res.deprecated

        res.printErrors()
        out = stream.getvalue()
        print out
        assert out

        assert ' ... DEPRECATED' in out
        assert 'deprecated me too' in out
    def test_prepare_patches_result(self):
        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, 1)
        sk = Deprecated()
        sk.prepareTestResult(res)
        res._orig_addError
        res._orig_printErrors
        res._orig_wasSuccessful
        res.deprecated
        self.assertEqual(
            res.errorClasses,
            {DeprecatedTest: (res.deprecated, 'DEPRECATED', False)})

        # result w/out print works too
        res = unittest.TestResult()
        sk = Deprecated()
        sk.prepareTestResult(res)
        res._orig_addError
        res.deprecated
        self.assertEqual(
            res.errorClasses,
            {DeprecatedTest: (res.deprecated, 'DEPRECATED', False)})
    def test_deprecated_output_verbose(self):

        class TC(unittest.TestCase):
            def test(self):
                raise DeprecatedTest('deprecated me too')
        
        stream = unittest._WritelnDecorator(StringIO())
        res = unittest._TextTestResult(stream, 0, verbosity=2)
        sk = Deprecated()
        sk.prepareTestResult(res)
        test = TC('test')
        test(res)
        assert not res.errors, "Deprecated was not caught: %s" % res.errors
        assert res.deprecated            

        res.printErrors()
        out = stream.getvalue()
        print out
        assert out

        assert ' ... DEPRECATED' in out
        assert 'deprecated me too' in out
 def _makeResult(self):
     self.result = unittest._TextTestResult(self.stream, self.descriptions,
                                            self.verbosity)
     return self.result
Exemple #22
0
 def _makeResult(self):
     self.result = unittest._TextTestResult(
         self.stream, self.descriptions, self.verbosity)
     return self.result 
Exemple #23
0
 def _makeResult(self):
     """Create the TestResult object which will be used to store
     information about the executed tests.
     """
     return _TextTestResult(self.stream, self.descriptions, \
         self.verbosity, self.elapsed_times)
Exemple #24
0
        conf.set('dougtest', 'info-server', socket.gethostname())
        LOG.info("Set hostname to %s" % socket.gethostname())

    # try to recognise fortran compile through mpif90
    if not conf.has_option('dougtest', 'info-fc') or \
       not conf.get('dougtest', 'info-fc'):
        subp = subprocess.Popen(["mpif90","-showme"], stdout=subprocess.PIPE)
        subp.wait()
        if subp.returncode==0:
            fc = subp.communicate()[0].split(" ")[0]
            conf.set('dougtest', 'info-fc', fc)
            LOG.info("Set fc to %s" % fc)


    # create test result objects
    testResults = [unittest._TextTestResult(unittest._WritelnDecorator(sys.stderr), False, 1)]

    saveTar = conf.getboolean("testscript", "save-tar")
    saveMysql = conf.getboolean("testscript", "save-mysql")

    if saveTar:
        import doug.testtar as dougtesttar
        tarFileName = os.path.abspath(conf.get("testscript", "tar-file"))
        tarTestResult = dougtesttar.DougTarTestResult(tarFileName, conf)
        testResults.append(tarTestResult)

    if saveMysql:
        import doug.testmysql as dougtestmysql
        mysqlHost = conf.get("testscript", "mysql-host")
        mysqlUser = conf.get("testscript", "mysql-user")
        mysqlPassword = conf.get("testscript", "mysql-password")
Exemple #25
0
import foo_package.test_this
suite = foo_package.test_this.load_tests(None, None, None)

import unittest, sys
result = unittest._TextTestResult(sys.stdout, 1, 1)
suite(result)
Exemple #26
0
 def _makeResult(self):
     """Create the TestResult object which will be used to store
     information about the executed tests.
     """
     return _TextTestResult(self.stream, self.descriptions, \
         self.verbosity, self.elapsed_times)