def __init__(self,stream=None): if not stream: file_prefix = os.path.basename(sys.argv[0]).split(".")[0].replace("test_", "") filename = timestamp("%s_results.txt" % file_prefix) self.stream = _WritelnDecorator(open(filename, "a+")) else: self.stream = _WritelnDecorator(stream) self.descriptions = 0 self.verbosity = 2
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))
def prepareTestResult(self, result): result.__failures = [] result.__errors = [] result.__tests_run = 0 result.__start_time = time.time() result.stream = unittest._WritelnDecorator(open(os.devnull, 'w')) self._result = result
def __init__(self, stream=sys.stderr, resultsFileName=None, descriptions=1, verbosity=1): self.stream = _WritelnDecorator(stream) self.descriptions = descriptions self.verbosity = verbosity if resultsFileName is None: self.resultWriter = _SharpDevelopNullTestResultWriter() else: self.resultWriter = _SharpDevelopTestResultWriter(resultsFileName)
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 makeResult(): stream = unittest._WritelnDecorator(StringIO()) result = resultClass(stream, descriptions=1, verbosity=config.verbosity, config=config) plug_result = config.plugins.prepareTestResult(result) if plug_result: return plug_result return result
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1, timeit=False): self.stream = unittest._WritelnDecorator(stream) # @UndefinedVariable self.descriptions = descriptions self.verbosity = verbosity self.timeit = timeit
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1, test_status=None): self.stream = unittest._WritelnDecorator(stream) self.descriptions = descriptions self.verbosity = verbosity self.test_status = test_status
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
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)
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_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_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_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_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()
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_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
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
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 __init__(self, stream=sys.stderr, descriptions=True, verbosity=1, summary=True, dstream=None): """ Parameters: stream -- (file) File to write test progress information to. Default is sys.stderr. descriptions -- (boolean) If true, identity tests by description if available. If not true, or description not available, use tests class and method name. verbosity -- (int) Control display of test progress display 0 -- No progress output. 1 -- As each test is executed, print successive ".", "F", or "E" charcters on a line for sucessful, failed, or errored tests respectively. Output is written to 'stream'. summary -- (boolean) Print a summary line (to 'stream') after full test suite has been executed, giving the number of successful tests, failed tests, errored tests, and time taken. dstream -- (file) File to write error details of failing or erroring tests to. If not given or None, 'stream' will be used. Returns: A unittest._TextTestResult object that contains all the test results for the suite. """ unittest.TextTestRunner.__init__(self, stream, descriptions, verbosity) if not dstream: self.dstream = self.stream else: self.dstream = unittest._WritelnDecorator(dstream) self.summary = summary
def __init__(self, testname, stream=sys.stderr): self.testname = testname self.stream = unittest._WritelnDecorator(stream)
def __init__(self, listview, progress, stream=sys.stderr, descriptions=1, verbosity=2): self.listview = listview self.progress = progress self.stream = unittest._WritelnDecorator(stream) self.descriptions = descriptions self.verbosity = verbosity
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1): stream = unittest._WritelnDecorator(stream) unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
def __init__(self, opts, stream=sys.stderr, descriptions=0, verbosity=1): self.stream = unittest._WritelnDecorator(stream) self.descriptions = 0 self.verbosity = 0
def __init__(self, stream=None): if not stream: stream = sys.stderr strm = unittest._WritelnDecorator(stream) unittest._TextTestResult.__init__(self, strm, True, 1)
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")
def __init__(self, stream = sys.stderr, descriptions=1, verbosity=1): stream = unittest._WritelnDecorator(stream) unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
def __init__(self, xmlstream=sys.stdout): unittest.TestResult.__init__(self) self.stream = unittest._WritelnDecorator(xmlstream) self.successes = [] # unittest.TestResult does not store successes