Python test.support.TestFailed() Examples
The following are 30
code examples of test.support.TestFailed().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.support
, or try the search function
.
Example #1
Source File: test_format.py From android_universal with MIT License | 6 votes |
def test_exc(formatstr, args, exception, excmsg): try: testformat(formatstr, args) except exception as exc: if str(exc) == excmsg: if verbose: print("yes") else: if verbose: print('no') print('Unexpected ', exception, ':', repr(str(exc))) except: if verbose: print('no') print('Unexpected exception') raise else: raise TestFailed('did not get expected exception: %s' % excmsg)
Example #2
Source File: test_xml_etree.py From ironpython3 with Apache License 2.0 | 6 votes |
def pickleRoundTrip(self, obj, name, dumper, loader, proto): save_m = sys.modules[name] try: sys.modules[name] = dumper temp = pickle.dumps(obj, proto) sys.modules[name] = loader result = pickle.loads(temp) except pickle.PicklingError as pe: # pyET must be second, because pyET may be (equal to) ET. human = dict([(ET, "cET"), (pyET, "pyET")]) raise support.TestFailed("Failed to round-trip %r from %r to %r" % (obj, human.get(dumper, dumper), human.get(loader, loader))) from pe finally: sys.modules[name] = save_m return result
Example #3
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_nameprep(self): from encodings.idna import nameprep for pos, (orig, prepped) in enumerate(nameprep_tests): if orig is None: # Skipped continue # The Unicode strings are given in UTF-8 orig = str(orig, "utf-8", "surrogatepass") if prepped is None: # Input contains prohibited characters self.assertRaises(UnicodeError, nameprep, orig) else: prepped = str(prepped, "utf-8", "surrogatepass") try: self.assertEqual(nameprep(orig), prepped) except Exception as e: raise support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
Example #4
Source File: test_xml_etree.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def pickleRoundTrip(self, obj, name, dumper, loader, proto): save_m = sys.modules[name] try: sys.modules[name] = dumper temp = pickle.dumps(obj, proto) sys.modules[name] = loader result = pickle.loads(temp) except pickle.PicklingError as pe: # pyET must be second, because pyET may be (equal to) ET. human = dict([(ET, "cET"), (pyET, "pyET")]) raise support.TestFailed("Failed to round-trip %r from %r to %r" % (obj, human.get(dumper, dumper), human.get(loader, loader))) from pe finally: sys.modules[name] = save_m return result
Example #5
Source File: test_xml_etree.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def pickleRoundTrip(self, obj, name, dumper, loader, proto): save_m = sys.modules[name] try: sys.modules[name] = dumper temp = pickle.dumps(obj, proto) sys.modules[name] = loader result = pickle.loads(temp) except pickle.PicklingError as pe: # pyET must be second, because pyET may be (equal to) ET. human = dict([(ET, "cET"), (pyET, "pyET")]) raise support.TestFailed("Failed to round-trip %r from %r to %r" % (obj, human.get(dumper, dumper), human.get(loader, loader))) from pe finally: sys.modules[name] = save_m return result
Example #6
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_nameprep(self): from encodings.idna import nameprep for pos, (orig, prepped) in enumerate(nameprep_tests): if orig is None: # Skipped continue # The Unicode strings are given in UTF-8 orig = str(orig, "utf-8", "surrogatepass") if prepped is None: # Input contains prohibited characters self.assertRaises(UnicodeError, nameprep, orig) else: prepped = str(prepped, "utf-8", "surrogatepass") try: self.assertEqual(nameprep(orig), prepped) except Exception as e: raise support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
Example #7
Source File: double_const.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def check_ok(x, x_str): assert x > 0.0 x2 = eval(x_str) assert x2 > 0.0 diff = abs(x - x2) # If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger # than 0.375 ULP, so adding diff/8 to x2 should have no effect. if x2 + (diff / 8.) != x2: raise TestFailed("Manifest const %s lost too much precision " % x_str)
Example #8
Source File: test_doctest2.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_main(): from test import test_doctest2 EXPECTED = 19 f, t = support.run_doctest(test_doctest2) if t != EXPECTED: raise support.TestFailed("expected %d tests to run, not %d" % (EXPECTED, t)) # Pollute the namespace with a bunch of imported functions and classes, # to make sure they don't get tested.
Example #9
Source File: test_richcmp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Number.__cmp__() should not be called")
Example #10
Source File: test_richcmp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Vector.__cmp__() should not be called")
Example #11
Source File: test_ntpath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), str(gotResult))) # then with bytes fn = fn.replace("('", "(b'") fn = fn.replace('("', '(b"') fn = fn.replace("['", "[b'") fn = fn.replace('["', '[b"') fn = fn.replace(", '", ", b'") fn = fn.replace(', "', ', b"') fn = os.fsencode(fn).decode('latin1') fn = fn.encode('ascii', 'backslashreplace').decode('ascii') with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) gotResult = eval(fn) if isinstance(wantResult, str): wantResult = os.fsencode(wantResult) elif isinstance(wantResult, tuple): wantResult = tuple(os.fsencode(r) for r in wantResult) gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), repr(gotResult)))
Example #12
Source File: test_richcmp.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Number.__cmp__() should not be called")
Example #13
Source File: test_doctest2.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_main(): from test import test_doctest2 EXPECTED = 19 f, t = support.run_doctest(test_doctest2) if t != EXPECTED: raise support.TestFailed("expected %d tests to run, not %d" % (EXPECTED, t)) # Pollute the namespace with a bunch of imported functions and classes, # to make sure they don't get tested.
Example #14
Source File: test_richcmp.py From android_universal with MIT License | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Number.__cmp__() should not be called")
Example #15
Source File: test_richcmp.py From android_universal with MIT License | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Vector.__cmp__() should not be called")
Example #16
Source File: test_ntpath.py From android_universal with MIT License | 5 votes |
def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), str(gotResult))) # then with bytes fn = fn.replace("('", "(b'") fn = fn.replace('("', '(b"') fn = fn.replace("['", "[b'") fn = fn.replace('["', '[b"') fn = fn.replace(", '", ", b'") fn = fn.replace(', "', ', b"') fn = os.fsencode(fn).decode('latin1') fn = fn.encode('ascii', 'backslashreplace').decode('ascii') with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) gotResult = eval(fn) if isinstance(wantResult, str): wantResult = os.fsencode(wantResult) elif isinstance(wantResult, tuple): wantResult = tuple(os.fsencode(r) for r in wantResult) gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), repr(gotResult)))
Example #17
Source File: test_format.py From android_universal with MIT License | 5 votes |
def test_str_format(self): testformat("%r", "\u0378", "'\\u0378'") # non printable testformat("%a", "\u0378", "'\\u0378'") # non printable testformat("%r", "\u0374", "'\u0374'") # printable testformat("%a", "\u0374", "'\\u0374'") # printable # Test exception for unknown format characters, etc. if verbose: print('Testing exceptions') test_exc('abc %b', 1, ValueError, "unsupported format character 'b' (0x62) at index 5") #test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError, # "unsupported format character '?' (0x3000) at index 5") test_exc('%g', '1', TypeError, "must be real number, not str") test_exc('no format', '1', TypeError, "not all arguments converted during string formatting") test_exc('%c', -1, OverflowError, "%c arg not in range(0x110000)") test_exc('%c', sys.maxunicode+1, OverflowError, "%c arg not in range(0x110000)") #test_exc('%c', 2**128, OverflowError, "%c arg not in range(0x110000)") test_exc('%c', 3.14, TypeError, "%c requires int or char") test_exc('%c', 'ab', TypeError, "%c requires int or char") test_exc('%c', b'x', TypeError, "%c requires int or char") if maxsize == 2**31-1: # crashes 2.2.1 and earlier: try: "%*d"%(maxsize, -127) except MemoryError: pass else: raise TestFailed('"%*d"%(maxsize, -127) should fail')
Example #18
Source File: double_const.py From ironpython3 with Apache License 2.0 | 5 votes |
def check_ok(x, x_str): assert x > 0.0 x2 = eval(x_str) assert x2 > 0.0 diff = abs(x - x2) # If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger # than 0.375 ULP, so adding diff/8 to x2 should have no effect. if x2 + (diff / 8.) != x2: raise TestFailed("Manifest const %s lost too much precision " % x_str)
Example #19
Source File: test_ntpath.py From ironpython3 with Apache License 2.0 | 5 votes |
def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), str(gotResult))) # then with bytes fn = fn.replace("('", "(b'") fn = fn.replace('("', '(b"') fn = fn.replace("['", "[b'") fn = fn.replace('["', '[b"') fn = fn.replace(", '", ", b'") fn = fn.replace(', "', ', b"') fn = os.fsencode(fn).decode('latin1') fn = fn.encode('ascii', 'backslashreplace').decode('ascii') with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) gotResult = eval(fn) if isinstance(wantResult, str): wantResult = os.fsencode(wantResult) elif isinstance(wantResult, tuple): wantResult = tuple(os.fsencode(r) for r in wantResult) gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), repr(gotResult)))
Example #20
Source File: test_richcmp.py From ironpython3 with Apache License 2.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Vector.__cmp__() should not be called")
Example #21
Source File: test_richcmp.py From ironpython3 with Apache License 2.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Number.__cmp__() should not be called")
Example #22
Source File: test_doctest2.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_main(): from test import test_doctest2 EXPECTED = 19 f, t = support.run_doctest(test_doctest2) if t != EXPECTED: raise support.TestFailed("expected %d tests to run, not %d" % (EXPECTED, t)) # Pollute the namespace with a bunch of imported functions and classes, # to make sure they don't get tested.
Example #23
Source File: double_const.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def check_ok(x, x_str): assert x > 0.0 x2 = eval(x_str) assert x2 > 0.0 diff = abs(x - x2) # If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger # than 0.375 ULP, so adding diff/8 to x2 should have no effect. if x2 + (diff / 8.) != x2: raise TestFailed("Manifest const %s lost too much precision " % x_str)
Example #24
Source File: test_ntpath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), str(gotResult))) # then with bytes fn = fn.replace("('", "(b'") fn = fn.replace('("', '(b"') fn = fn.replace("['", "[b'") fn = fn.replace('["', '[b"') fn = fn.replace(", '", ", b'") fn = fn.replace(', "', ', b"') fn = os.fsencode(fn).decode('latin1') fn = fn.encode('ascii', 'backslashreplace').decode('ascii') with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) gotResult = eval(fn) if isinstance(wantResult, str): wantResult = os.fsencode(wantResult) elif isinstance(wantResult, tuple): wantResult = tuple(os.fsencode(r) for r in wantResult) gotResult = eval(fn) if wantResult != gotResult: raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), repr(gotResult)))
Example #25
Source File: test_richcmp.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def __cmp__(self, other): raise support.TestFailed("Vector.__cmp__() should not be called")
Example #26
Source File: regrtest.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def runtest_inner(ns, test, verbose, quiet, huntrleaks=False, display_failure=True, pgo=False): support.unload(test) test_time = 0.0 refleak = False # True if the test leaked references. try: abstest = get_abs_module(ns, test) clear_caches() with saved_test_environment(test, verbose, quiet, pgo=pgo) as environment: start_time = time.time() the_module = importlib.import_module(abstest) # If the test has a test_main, that will run the appropriate # tests. If not, use normal unittest test loading. test_runner = getattr(the_module, "test_main", None) if test_runner is None: def test_runner(): loader = unittest.TestLoader() tests = loader.loadTestsFromModule(the_module) for error in loader.errors: print(error, file=sys.stderr) if loader.errors: raise Exception("errors while loading tests") support.run_unittest(tests) test_runner() if huntrleaks: refleak = dash_R(the_module, test, test_runner, huntrleaks) test_time = time.time() - start_time except support.ResourceDenied as msg: if not quiet and not pgo: print(test, "skipped --", msg) sys.stdout.flush() return RESOURCE_DENIED, test_time except unittest.SkipTest as msg: if not quiet and not pgo: print(test, "skipped --", msg) sys.stdout.flush() return SKIPPED, test_time except KeyboardInterrupt: raise except support.TestFailed as msg: if not pgo: if display_failure: print("test", test, "failed --", msg, file=sys.stderr) else: print("test", test, "failed", file=sys.stderr) sys.stderr.flush() return FAILED, test_time except: msg = traceback.format_exc() if not pgo: print("test", test, "crashed --", msg, file=sys.stderr) sys.stderr.flush() return FAILED, test_time else: if refleak: return FAILED, test_time if environment.changed: return ENV_CHANGED, test_time return PASSED, test_time
Example #27
Source File: test_ssl.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_main(verbose=False): if support.verbose: plats = { 'Linux': platform.linux_distribution, 'Mac': platform.mac_ver, 'Windows': platform.win32_ver, } for name, func in plats.items(): plat = func() if plat and plat[0]: plat = '%s %r' % (name, plat) break else: plat = repr(platform.platform()) print("test_ssl: testing with %r %r" % (ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)) print(" under %s" % plat) print(" HAS_SNI = %r" % ssl.HAS_SNI) print(" OP_ALL = 0x%8x" % ssl.OP_ALL) try: print(" OP_NO_TLSv1_1 = 0x%8x" % ssl.OP_NO_TLSv1_1) except AttributeError: pass for filename in [ CERTFILE, REMOTE_ROOT_CERT, BYTES_CERTFILE, ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY, SIGNED_CERTFILE, SIGNED_CERTFILE2, SIGNING_CA, BADCERT, BADKEY, EMPTYCERT]: if not os.path.exists(filename): raise support.TestFailed("Can't read certificate file %r" % filename) tests = [ContextTests, BasicSocketTests, SSLErrorTests] if support.is_resource_enabled('network'): tests.append(NetworkedTests) if _have_threads: thread_info = support.threading_setup() if thread_info: tests.append(ThreadedTests) try: support.run_unittest(*tests) finally: if _have_threads: support.threading_cleanup(*thread_info)
Example #28
Source File: test_format.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def test_str_format(self): testformat("%r", "\u0378", "'\\u0378'") # non printable testformat("%a", "\u0378", "'\\u0378'") # non printable testformat("%r", "\u0374", "'\u0374'") # printable testformat("%a", "\u0374", "'\\u0374'") # printable # Test exception for unknown format characters, etc. if verbose: print('Testing exceptions') def test_exc(formatstr, args, exception, excmsg): try: testformat(formatstr, args) except exception as exc: if str(exc) == excmsg: if verbose: print("yes") else: if verbose: print('no') print('Unexpected ', exception, ':', repr(str(exc))) except: if verbose: print('no') print('Unexpected exception') raise else: raise TestFailed('did not get expected exception: %s' % excmsg) test_exc('abc %b', 1, ValueError, "unsupported format character 'b' (0x62) at index 5") #test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError, # "unsupported format character '?' (0x3000) at index 5") test_exc('%d', '1', TypeError, "%d format: a number is required, not str") test_exc('%x', '1', TypeError, "%x format: an integer is required, not str") test_exc('%x', 3.14, TypeError, "%x format: an integer is required, not float") test_exc('%g', '1', TypeError, "a float is required") test_exc('no format', '1', TypeError, "not all arguments converted during string formatting") test_exc('%c', -1, OverflowError, "%c arg not in range(0x110000)") test_exc('%c', sys.maxunicode+1, OverflowError, "%c arg not in range(0x110000)") #test_exc('%c', 2**128, OverflowError, "%c arg not in range(0x110000)") test_exc('%c', 3.14, TypeError, "%c requires int or char") test_exc('%c', 'ab', TypeError, "%c requires int or char") test_exc('%c', b'x', TypeError, "%c requires int or char") if maxsize == 2**31-1: # crashes 2.2.1 and earlier: try: "%*d"%(maxsize, -127) except MemoryError: pass else: raise TestFailed('"%*d"%(maxsize, -127) should fail')
Example #29
Source File: regrtest.py From ironpython3 with Apache License 2.0 | 4 votes |
def runtest_inner(test, verbose, quiet, huntrleaks=False, display_failure=True): support.unload(test) test_time = 0.0 refleak = False # True if the test leaked references. try: if test.startswith('test.'): abstest = test else: # Always import it from the test package abstest = 'test.' + test with saved_test_environment(test, verbose, quiet) as environment: start_time = time.time() the_module = importlib.import_module(abstest) # If the test has a test_main, that will run the appropriate # tests. If not, use normal unittest test loading. test_runner = getattr(the_module, "test_main", None) if test_runner is None: def test_runner(): loader = unittest.TestLoader() tests = loader.loadTestsFromModule(the_module) support.run_unittest(tests) test_runner() if huntrleaks: refleak = dash_R(the_module, test, test_runner, huntrleaks) test_time = time.time() - start_time except support.ResourceDenied as msg: if not quiet: print(test, "skipped --", msg) sys.stdout.flush() return RESOURCE_DENIED, test_time except unittest.SkipTest as msg: if not quiet: print(test, "skipped --", msg) sys.stdout.flush() return SKIPPED, test_time except KeyboardInterrupt: raise except support.TestFailed as msg: if display_failure: print("test", test, "failed --", msg, file=sys.stderr) else: print("test", test, "failed", file=sys.stderr) sys.stderr.flush() return FAILED, test_time except: msg = traceback.format_exc() print("test", test, "crashed --", msg, file=sys.stderr) sys.stderr.flush() return FAILED, test_time else: if refleak: return FAILED, test_time if environment.changed: return ENV_CHANGED, test_time return PASSED, test_time
Example #30
Source File: test_ssl.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def test_main(verbose=False): if support.verbose: import warnings plats = { 'Linux': platform.linux_distribution, 'Mac': platform.mac_ver, 'Windows': platform.win32_ver, } with warnings.catch_warnings(): warnings.filterwarnings( 'ignore', 'dist\(\) and linux_distribution\(\) ' 'functions are deprecated .*', PendingDeprecationWarning, ) for name, func in plats.items(): plat = func() if plat and plat[0]: plat = '%s %r' % (name, plat) break else: plat = repr(platform.platform()) print("test_ssl: testing with %r %r" % (ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)) print(" under %s" % plat) print(" HAS_SNI = %r" % ssl.HAS_SNI) print(" OP_ALL = 0x%8x" % ssl.OP_ALL) try: print(" OP_NO_TLSv1_1 = 0x%8x" % ssl.OP_NO_TLSv1_1) except AttributeError: pass for filename in [ CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE, ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY, SIGNED_CERTFILE, SIGNED_CERTFILE2, SIGNING_CA, BADCERT, BADKEY, EMPTYCERT]: if not os.path.exists(filename): raise support.TestFailed("Can't read certificate file %r" % filename) tests = [ContextTests, BasicSocketTests, SSLErrorTests, MemoryBIOTests] if support.is_resource_enabled('network'): tests.append(NetworkedTests) tests.append(NetworkedBIOTests) if _have_threads: thread_info = support.threading_setup() if thread_info: tests.append(ThreadedTests) try: support.run_unittest(*tests) finally: if _have_threads: support.threading_cleanup(*thread_info)