Lines Matching refs:sys

9 import sys
31 dh = sys.__displayhook__
47 # sys.displayhook() requires arguments
50 stdout = sys.stdout
52 del sys.stdout
55 sys.stdout = stdout
58 displayhook = sys.displayhook
60 del sys.displayhook
64 sys.displayhook = displayhook
70 with support.swap_attr(sys, 'displayhook', baddisplayhook):
76 self.assertEqual(sys.exc_info(), (None, None, None))
79 self.assertEqual(sys.exception(), None)
89 exc_info = sys.exc_info()
104 exc_info = sys.exc_info()
119 exc = sys.exception()
132 exc = sys.exception()
145 sys.__excepthook__(*sys.exc_info())
149 self.assertRaises(TypeError, sys.__excepthook__)
152 # bpo-37467: sys.excepthook() must not crash if a filename
161 sys.__excepthook__(*sys.exc_info())
170 sys.excepthook(1, '1', 1)
185 self.assertRaises(TypeError, sys.exit, 42, 42)
189 sys.exit()
192 rc, out, err = assert_python_ok('-c', 'import sys; sys.exit()')
199 sys.exit(42)
205 sys.exit((42,))
210 sys.exit("exit")
215 sys.exit((17, 23))
234 r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")',
240 r'import sys; sys.exit("surrogates:\uDCFF")',
246 r'import sys; sys.exit("h\xe9")',
250 self.assertRaises(TypeError, sys.getdefaultencoding, 42)
252 self.assertIsInstance(sys.getdefaultencoding(), str)
254 # testing sys.settrace() is done in test_sys_settrace.py
255 # testing sys.setprofile() is done in test_sys_setprofile.py
258 self.assertRaises(TypeError, sys.setswitchinterval)
259 self.assertRaises(TypeError, sys.setswitchinterval, "a")
260 self.assertRaises(ValueError, sys.setswitchinterval, -1.0)
261 self.assertRaises(ValueError, sys.setswitchinterval, 0.0)
262 orig = sys.getswitchinterval()
267 sys.setswitchinterval(n)
268 self.assertAlmostEqual(sys.getswitchinterval(), n)
270 sys.setswitchinterval(orig)
273 self.assertRaises(TypeError, sys.getrecursionlimit, 42)
274 oldlimit = sys.getrecursionlimit()
275 self.assertRaises(TypeError, sys.setrecursionlimit)
276 self.assertRaises(ValueError, sys.setrecursionlimit, -42)
277 sys.setrecursionlimit(10000)
278 self.assertEqual(sys.getrecursionlimit(), 10000)
279 sys.setrecursionlimit(oldlimit)
282 if hasattr(sys, 'gettrace') and sys.gettrace():
285 oldlimit = sys.getrecursionlimit()
291 sys.setrecursionlimit(depth)
304 sys.setrecursionlimit(oldlimit)
317 sys.setrecursionlimit(limit)
325 oldlimit = sys.getrecursionlimit()
327 sys.setrecursionlimit(1000)
332 sys.setrecursionlimit(oldlimit)
335 # Raise SkipTest if sys doesn't have getwindowsversion attribute
336 test.support.get_attribute(sys, "getwindowsversion")
337 v = sys.getwindowsversion()
362 maj, min, buildno, plat, csd = sys.getwindowsversion()
365 self.assertRaises(TypeError, sys.call_tracing, type, 2)
367 @unittest.skipUnless(hasattr(sys, "setdlopenflags"),
368 'test needs sys.setdlopenflags()')
370 self.assertTrue(hasattr(sys, "getdlopenflags"))
371 self.assertRaises(TypeError, sys.getdlopenflags, 42)
372 oldflags = sys.getdlopenflags()
373 self.assertRaises(TypeError, sys.setdlopenflags)
374 sys.setdlopenflags(oldflags+1)
375 self.assertEqual(sys.getdlopenflags(), oldflags+1)
376 sys.setdlopenflags(oldflags)
385 self.assertRaises(TypeError, sys.getrefcount)
386 c = sys.getrefcount(None)
388 self.assertEqual(sys.getrefcount(None), c+1)
390 self.assertEqual(sys.getrefcount(None), c)
391 if hasattr(sys, "gettotalrefcount"):
392 self.assertIsInstance(sys.gettotalrefcount(), int)
395 self.assertRaises(TypeError, sys._getframe, 42, 42)
396 self.assertRaises(ValueError, sys._getframe, 2000000000)
399 is sys._getframe().f_code
402 # sys._current_frames() is a CPython-only gimmick.
410 # thread does sys._current_frames(), and verifies that the frames
434 d = sys._current_frames()
445 self.assertTrue(frame is sys._getframe())
476 # thread does sys._current_frames(), and verifies that the frames
505 d = sys._current_exceptions()
538 self.assertIsInstance(sys.api_version, int)
539 self.assertIsInstance(sys.argv, list)
540 for arg in sys.argv:
542 self.assertIsInstance(sys.orig_argv, list)
543 for arg in sys.orig_argv:
545 self.assertIn(sys.byteorder, ("little", "big"))
546 self.assertIsInstance(sys.builtin_module_names, tuple)
547 self.assertIsInstance(sys.copyright, str)
548 self.assertIsInstance(sys.exec_prefix, str)
549 self.assertIsInstance(sys.base_exec_prefix, str)
550 self.assertIsInstance(sys.executable, str)
551 self.assertEqual(len(sys.float_info), 11)
552 self.assertEqual(sys.float_info.radix, 2)
553 self.assertEqual(len(sys.int_info), 4)
554 self.assertTrue(sys.int_info.bits_per_digit % 5 == 0)
555 self.assertTrue(sys.int_info.sizeof_digit >= 1)
556 self.assertGreaterEqual(sys.int_info.default_max_str_digits, 500)
557 self.assertGreaterEqual(sys.int_info.str_digits_check_threshold, 100)
558 self.assertGreater(sys.int_info.default_max_str_digits,
559 sys.int_info.str_digits_check_threshold)
560 self.assertEqual(type(sys.int_info.bits_per_digit), int)
561 self.assertEqual(type(sys.int_info.sizeof_digit), int)
562 self.assertIsInstance(sys.int_info.default_max_str_digits, int)
563 self.assertIsInstance(sys.int_info.str_digits_check_threshold, int)
564 self.assertIsInstance(sys.hexversion, int)
566 self.assertEqual(len(sys.hash_info), 9)
567 self.assertLess(sys.hash_info.modulus, 2**sys.hash_info.width)
568 # sys.hash_info.modulus should be a prime; we do a quick
573 pow(x, sys.hash_info.modulus-1, sys.hash_info.modulus),
575 "sys.hash_info.modulus {} is a non-prime".format(
576 sys.hash_info.modulus)
578 self.assertIsInstance(sys.hash_info.inf, int)
579 self.assertIsInstance(sys.hash_info.nan, int)
580 self.assertIsInstance(sys.hash_info.imag, int)
582 if sys.hash_info.algorithm in {"fnv", "siphash13", "siphash24"}:
583 self.assertIn(sys.hash_info.hash_bits, {32, 64})
584 self.assertIn(sys.hash_info.seed_bits, {32, 64, 128})
587 self.assertEqual(sys.hash_info.algorithm, "siphash24")
589 self.assertEqual(sys.hash_info.algorithm, "fnv")
591 self.assertEqual(sys.hash_info.algorithm, "siphash13")
593 self.assertIn(sys.hash_info.algorithm, {"fnv", "siphash13", "siphash24"})
597 self.assertGreaterEqual(sys.hash_info.cutoff, 0)
598 self.assertLess(sys.hash_info.cutoff, 8)
600 self.assertIsInstance(sys.maxsize, int)
601 self.assertIsInstance(sys.maxunicode, int)
602 self.assertEqual(sys.maxunicode, 0x10FFFF)
603 self.assertIsInstance(sys.platform, str)
604 self.assertIsInstance(sys.prefix, str)
605 self.assertIsInstance(sys.base_prefix, str)
606 self.assertIsInstance(sys.platlibdir, str)
607 self.assertIsInstance(sys.version, str)
608 vi = sys.version_info
627 self.assertIsInstance(sys.float_repr_style, str)
628 self.assertIn(sys.float_repr_style, ('short', 'legacy'))
629 if not sys.platform.startswith('win'):
630 self.assertIsInstance(sys.abiflags, str)
633 info = sys.thread_info
637 if sys.platform.startswith(("linux", "freebsd")):
639 elif sys.platform == "win32":
641 elif sys.platform == "emscripten":
643 elif sys.platform == "wasi":
648 self.assertEqual(len(sys._emscripten_info), 4)
649 self.assertIsInstance(sys._emscripten_info.emscripten_version, tuple)
650 self.assertIsInstance(sys._emscripten_info.runtime, (str, type(None)))
651 self.assertIsInstance(sys._emscripten_info.pthreads, bool)
652 self.assertIsInstance(sys._emscripten_info.shared_memory, bool)
655 # Can't use sys.stdout, as this is a StringIO object when
657 self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
662 self.assertRaises(TypeError, sys.intern)
664 self.assertTrue(sys.intern(s) is s)
666 self.assertTrue(sys.intern(s2) is s)
677 self.assertRaises(TypeError, sys.intern, S("abc"))
680 self.assertTrue(sys.flags)
688 self.assertTrue(hasattr(sys.flags, attr), attr)
690 self.assertEqual(type(getattr(sys.flags, attr)), attr_type, attr)
691 self.assertTrue(repr(sys.flags))
692 self.assertEqual(len(sys.flags), len(attrs))
694 self.assertIn(sys.flags.utf8_mode, {0, 1, 2})
698 # sys.flags, sys.version_info, and sys.getwindowsversion.
707 self.assert_raise_on_new_sys_type(sys.flags)
710 self.assert_raise_on_new_sys_type(sys.version_info)
714 test.support.get_attribute(sys, "getwindowsversion")
715 self.assert_raise_on_new_sys_type(sys.getwindowsversion())
719 sys._clear_type_cache()
729 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
736 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
742 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
751 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
760 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xdcbd))'],
767 @unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False),
774 p = subprocess.Popen([sys.executable, "-c",
780 @unittest.skipIf(sys.base_prefix != sys.prefix,
784 # sys.executable should be absolute
785 self.assertEqual(os.path.abspath(sys.executable), sys.executable)
787 # Issue #7774: Ensure that sys.executable is an empty string if argv[0]
793 python_dir = os.path.dirname(os.path.realpath(sys.executable))
796 'import sys; print(sys.executable.encode("ascii", "backslashreplace"))'],
797 executable=sys.executable, stdout=subprocess.PIPE, cwd=python_dir)
801 self.assertIn(executable, ["b''", repr(sys.executable.encode("ascii", "backslashreplace"))])
810 fs_encoding = sys.getfilesystemencoding()
811 if sys.platform == 'darwin':
823 'import sys',
825 ' std = getattr(sys, name)',
831 args = [sys.executable, "-X", "utf8=0", "-c", code]
897 self.assertTrue(hasattr(sys.implementation, 'name'))
898 self.assertTrue(hasattr(sys.implementation, 'version'))
899 self.assertTrue(hasattr(sys.implementation, 'hexversion'))
900 self.assertTrue(hasattr(sys.implementation, 'cache_tag'))
902 version = sys.implementation.version
908 self.assertEqual(sys.implementation.hexversion, hexversion)
911 self.assertEqual(sys.implementation.name,
912 sys.implementation.name.lower())
916 # Test sys._debugmallocstats()
918 args = ['-c', 'import sys; sys._debugmallocstats()']
921 # Output of sys._debugmallocstats() depends on configure flags.
923 if sys.platform != "win32":
934 self.assertRaises(TypeError, sys._debugmallocstats, True)
936 @unittest.skipUnless(hasattr(sys, "getallocatedblocks"),
937 "sys.getallocatedblocks unavailable on this build")
953 a = sys.getallocatedblocks()
966 self.assertLess(a, sys.gettotalrefcount())
971 b = sys.getallocatedblocks()
974 c = sys.getallocatedblocks()
978 self.assertIs(sys.is_finalizing(), False)
982 import sys
985 is_finalizing = sys.is_finalizing
999 # sys.flags and sys.float_info were wiped during shutdown.
1001 import sys
1003 def __del__(self, sys=sys):
1004 print(sys.flags)
1005 print(sys.float_info)
1010 self.assertIn(b'sys.flags', out[0])
1011 self.assertIn(b'sys.float_info', out[1])
1015 import struct, sys
1023 sys.x = C()
1030 @unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
1031 'need sys.getandroidapilevel()')
1033 level = sys.getandroidapilevel()
1040 import sys
1045 sys.tracebacklimit = %r
1049 p = subprocess.Popen([sys.executable, '-c', code % tracebacklimit],
1072 self.assertEqual(len(sys.meta_path), len(set(sys.meta_path)))
1074 @unittest.skipUnless(hasattr(sys, "_enablelegacywindowsfsencoding"),
1075 'needs sys._enablelegacywindowsfsencoding()')
1077 code = ('import sys',
1078 'sys._enablelegacywindowsfsencoding()',
1079 'print(sys.getfilesystemencoding(), sys.getfilesystemencodeerrors())')
1087 import sys
1088 print(sys.argv)
1089 print(sys.orig_argv)
1091 args = [sys.executable, '-I', '-X', 'utf8', '-c', code, 'arg']
1094 repr(['-c', 'arg']), # sys.argv
1095 repr(args), # sys.orig_argv
1101 self.assertIsInstance(sys.stdlib_module_names, frozenset)
1102 for name in sys.stdlib_module_names:
1111 self.assertEqual(os.path.normpath(sys._stdlib_dir),
1138 with test.support.swap_attr(sys, 'unraisablehook',
1139 sys.__unraisablehook__):
1172 test.support.swap_attr(sys, 'unraisablehook',
1173 sys.__unraisablehook__):
1204 sys, 'unraisablehook', sys.__unraisablehook__
1218 with test.support.swap_attr(sys, 'unraisablehook',
1219 sys.__unraisablehook__):
1221 sys.unraisablehook(exc)
1232 with test.support.swap_attr(sys, 'unraisablehook', hook_func):
1249 with test.support.swap_attr(sys, 'unraisablehook', hook_func):
1254 self.assertIn(f'Exception ignored in sys.unraisablehook: '
1266 self.longdigit = sys.int_info.sizeof_digit
1277 self.assertEqual(sys.getsizeof(True), vsize('') + self.longdigit)
1279 self.assertEqual(sys.getsizeof([]), vsize('Pn') + gc_header_size)
1285 self.assertRaises(ValueError, sys.getsizeof, BadSizeof())
1290 self.assertRaises(TypeError, sys.getsizeof, InvalidSizeof())
1292 self.assertIs(sys.getsizeof(InvalidSizeof(), sentinel), sentinel)
1297 self.assertRaises(TypeError, sys.getsizeof, FloatSizeof())
1298 self.assertIs(sys.getsizeof(FloatSizeof(), sentinel), sentinel)
1303 self.assertEqual(sys.getsizeof(OverflowSizeof(sys.maxsize)),
1304 sys.maxsize + self.gc_headsize)
1306 sys.getsizeof(OverflowSizeof(sys.maxsize + 1))
1308 sys.getsizeof(OverflowSizeof(-1))
1310 sys.getsizeof(OverflowSizeof(-sys.maxsize - 1))
1314 self.assertEqual(sys.getsizeof(True), size('') + self.longdigit)
1315 self.assertEqual(sys.getsizeof(True, -1), size('') + self.longdigit)
1349 self.assertGreaterEqual(sys.getsizeof(a), expected_size)
1420 # sys.floatinfo
1421 check(sys.float_info, vsize('') + self.P * len(sys.float_info))
1424 return sys._getframe()
1466 PyLong_BASE = 2**sys.int_info.bits_per_digit
1590 expected = sys.getsizeof(base) + struct.calcsize(extra)
1593 self.assertEqual(sys.getsizeof(obj), expected)
1630 tb = sys.exc_info()[2]
1636 # sys.flags
1637 check(sys.flags, vsize('') + self.P * len(sys.flags))
1640 old = sys.get_asyncgen_hooks()
1645 sys.set_asyncgen_hooks(firstiter=firstiter)
1646 hooks = sys.get_asyncgen_hooks()
1653 sys.set_asyncgen_hooks(finalizer=finalizer)
1654 hooks = sys.get_asyncgen_hooks()
1660 sys.set_asyncgen_hooks(*old)
1661 cur = sys.get_asyncgen_hooks()
1667 # to sys.stderr the following code can crash. See bpo-43660
1670 import sys
1673 sys.stderr = None
1674 sys.stderr = MyStderr()