• Home
  • Raw
  • Download

Lines Matching full:sys

9 import sys
29 dh = sys.__displayhook__
45 # sys.displayhook() requires arguments
48 stdout = sys.stdout
50 del sys.stdout
53 sys.stdout = stdout
56 displayhook = sys.displayhook
58 del sys.displayhook
62 sys.displayhook = displayhook
68 with support.swap_attr(sys, 'displayhook', baddisplayhook):
80 sys.__excepthook__(*sys.exc_info())
84 self.assertRaises(TypeError, sys.__excepthook__)
87 # bpo-37467: sys.excepthook() must not crash if a filename
96 sys.__excepthook__(*sys.exc_info())
105 sys.excepthook(1, '1', 1)
120 self.assertRaises(TypeError, sys.exit, 42, 42)
124 sys.exit()
127 rc, out, err = assert_python_ok('-c', 'import sys; sys.exit()')
134 sys.exit(42)
140 sys.exit((42,))
145 sys.exit("exit")
150 sys.exit((17, 23))
169 r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")',
175 r'import sys; sys.exit("surrogates:\uDCFF")',
181 r'import sys; sys.exit("h\xe9")',
185 self.assertRaises(TypeError, sys.getdefaultencoding, 42)
187 self.assertIsInstance(sys.getdefaultencoding(), str)
189 # testing sys.settrace() is done in test_sys_settrace.py
190 # testing sys.setprofile() is done in test_sys_setprofile.py
193 self.assertRaises(TypeError, sys.setswitchinterval)
194 self.assertRaises(TypeError, sys.setswitchinterval, "a")
195 self.assertRaises(ValueError, sys.setswitchinterval, -1.0)
196 self.assertRaises(ValueError, sys.setswitchinterval, 0.0)
197 orig = sys.getswitchinterval()
202 sys.setswitchinterval(n)
203 self.assertAlmostEqual(sys.getswitchinterval(), n)
205 sys.setswitchinterval(orig)
208 self.assertRaises(TypeError, sys.getrecursionlimit, 42)
209 oldlimit = sys.getrecursionlimit()
210 self.assertRaises(TypeError, sys.setrecursionlimit)
211 self.assertRaises(ValueError, sys.setrecursionlimit, -42)
212 sys.setrecursionlimit(10000)
213 self.assertEqual(sys.getrecursionlimit(), 10000)
214 sys.setrecursionlimit(oldlimit)
217 if hasattr(sys, 'gettrace') and sys.gettrace():
220 oldlimit = sys.getrecursionlimit()
226 sys.setrecursionlimit(depth)
239 sys.setrecursionlimit(oldlimit)
252 sys.setrecursionlimit(limit)
260 oldlimit = sys.getrecursionlimit()
262 sys.setrecursionlimit(1000)
267 sys.setrecursionlimit(oldlimit)
270 # Raise SkipTest if sys doesn't have getwindowsversion attribute
271 test.support.get_attribute(sys, "getwindowsversion")
272 v = sys.getwindowsversion()
297 maj, min, buildno, plat, csd = sys.getwindowsversion()
300 self.assertRaises(TypeError, sys.call_tracing, type, 2)
302 @unittest.skipUnless(hasattr(sys, "setdlopenflags"),
303 'test needs sys.setdlopenflags()')
305 self.assertTrue(hasattr(sys, "getdlopenflags"))
306 self.assertRaises(TypeError, sys.getdlopenflags, 42)
307 oldflags = sys.getdlopenflags()
308 self.assertRaises(TypeError, sys.setdlopenflags)
309 sys.setdlopenflags(oldflags+1)
310 self.assertEqual(sys.getdlopenflags(), oldflags+1)
311 sys.setdlopenflags(oldflags)
320 self.assertRaises(TypeError, sys.getrefcount)
321 c = sys.getrefcount(None)
323 self.assertEqual(sys.getrefcount(None), c+1)
325 self.assertEqual(sys.getrefcount(None), c)
326 if hasattr(sys, "gettotalrefcount"):
327 self.assertIsInstance(sys.gettotalrefcount(), int)
330 self.assertRaises(TypeError, sys._getframe, 42, 42)
331 self.assertRaises(ValueError, sys._getframe, 2000000000)
334 is sys._getframe().f_code
337 # sys._current_frames() is a CPython-only gimmick.
344 # thread does sys._current_frames(), and verifies that the frames
368 d = sys._current_frames()
379 self.assertTrue(frame is sys._getframe())
409 # thread does sys._current_frames(), and verifies that the frames
438 d = sys._current_exceptions()
471 self.assertIsInstance(sys.api_version, int)
472 self.assertIsInstance(sys.argv, list)
473 for arg in sys.argv:
475 self.assertIsInstance(sys.orig_argv, list)
476 for arg in sys.orig_argv:
478 self.assertIn(sys.byteorder, ("little", "big"))
479 self.assertIsInstance(sys.builtin_module_names, tuple)
480 self.assertIsInstance(sys.copyright, str)
481 self.assertIsInstance(sys.exec_prefix, str)
482 self.assertIsInstance(sys.base_exec_prefix, str)
483 self.assertIsInstance(sys.executable, str)
484 self.assertEqual(len(sys.float_info), 11)
485 self.assertEqual(sys.float_info.radix, 2)
486 self.assertEqual(len(sys.int_info), 2)
487 self.assertTrue(sys.int_info.bits_per_digit % 5 == 0)
488 self.assertTrue(sys.int_info.sizeof_digit >= 1)
489 self.assertEqual(type(sys.int_info.bits_per_digit), int)
490 self.assertEqual(type(sys.int_info.sizeof_digit), int)
491 self.assertIsInstance(sys.hexversion, int)
493 self.assertEqual(len(sys.hash_info), 9)
494 self.assertLess(sys.hash_info.modulus, 2**sys.hash_info.width)
495 # sys.hash_info.modulus should be a prime; we do a quick
500 pow(x, sys.hash_info.modulus-1, sys.hash_info.modulus),
502 "sys.hash_info.modulus {} is a non-prime".format(
503 sys.hash_info.modulus)
505 self.assertIsInstance(sys.hash_info.inf, int)
506 self.assertIsInstance(sys.hash_info.nan, int)
507 self.assertIsInstance(sys.hash_info.imag, int)
509 if sys.hash_info.algorithm in {"fnv", "siphash24"}:
510 self.assertIn(sys.hash_info.hash_bits, {32, 64})
511 self.assertIn(sys.hash_info.seed_bits, {32, 64, 128})
514 self.assertEqual(sys.hash_info.algorithm, "siphash24")
516 self.assertEqual(sys.hash_info.algorithm, "fnv")
518 self.assertIn(sys.hash_info.algorithm, {"fnv", "siphash24"})
522 self.assertGreaterEqual(sys.hash_info.cutoff, 0)
523 self.assertLess(sys.hash_info.cutoff, 8)
525 self.assertIsInstance(sys.maxsize, int)
526 self.assertIsInstance(sys.maxunicode, int)
527 self.assertEqual(sys.maxunicode, 0x10FFFF)
528 self.assertIsInstance(sys.platform, str)
529 self.assertIsInstance(sys.prefix, str)
530 self.assertIsInstance(sys.base_prefix, str)
531 self.assertIsInstance(sys.platlibdir, str)
532 self.assertIsInstance(sys.version, str)
533 vi = sys.version_info
552 self.assertIsInstance(sys.float_repr_style, str)
553 self.assertIn(sys.float_repr_style, ('short', 'legacy'))
554 if not sys.platform.startswith('win'):
555 self.assertIsInstance(sys.abiflags, str)
558 info = sys.thread_info
564 # Can't use sys.stdout, as this is a StringIO object when
566 self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
571 self.assertRaises(TypeError, sys.intern)
573 self.assertTrue(sys.intern(s) is s)
575 self.assertTrue(sys.intern(s2) is s)
586 self.assertRaises(TypeError, sys.intern, S("abc"))
589 self.assertTrue(sys.flags)
597 self.assertTrue(hasattr(sys.flags, attr), attr)
599 self.assertEqual(type(getattr(sys.flags, attr)), attr_type, attr)
600 self.assertTrue(repr(sys.flags))
601 self.assertEqual(len(sys.flags), len(attrs))
603 self.assertIn(sys.flags.utf8_mode, {0, 1, 2})
607 # sys.flags, sys.version_info, and sys.getwindowsversion.
616 self.assert_raise_on_new_sys_type(sys.flags)
619 self.assert_raise_on_new_sys_type(sys.version_info)
623 test.support.get_attribute(sys, "getwindowsversion")
624 self.assert_raise_on_new_sys_type(sys.getwindowsversion())
628 sys._clear_type_cache()
637 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
644 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
650 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
659 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
668 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xdcbd))'],
675 @unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False),
681 p = subprocess.Popen([sys.executable, "-c",
687 @unittest.skipIf(sys.base_prefix != sys.prefix,
690 # sys.executable should be absolute
691 self.assertEqual(os.path.abspath(sys.executable), sys.executable)
693 # Issue #7774: Ensure that sys.executable is an empty string if argv[0]
699 python_dir = os.path.dirname(os.path.realpath(sys.executable))
702 'import sys; print(sys.executable.encode("ascii", "backslashreplace"))'],
703 executable=sys.executable, stdout=subprocess.PIPE, cwd=python_dir)
707 self.assertIn(executable, ["b''", repr(sys.executable.encode("ascii", "backslashreplace"))])
716 fs_encoding = sys.getfilesystemencoding()
717 if sys.platform == 'darwin':
729 'import sys',
731 ' std = getattr(sys, name)',
737 args = [sys.executable, "-X", "utf8=0", "-c", code]
801 self.assertTrue(hasattr(sys.implementation, 'name'))
802 self.assertTrue(hasattr(sys.implementation, 'version'))
803 self.assertTrue(hasattr(sys.implementation, 'hexversion'))
804 self.assertTrue(hasattr(sys.implementation, 'cache_tag'))
806 version = sys.implementation.version
812 self.assertEqual(sys.implementation.hexversion, hexversion)
815 self.assertEqual(sys.implementation.name,
816 sys.implementation.name.lower())
820 # Test sys._debugmallocstats()
822 args = ['-c', 'import sys; sys._debugmallocstats()']
827 self.assertRaises(TypeError, sys._debugmallocstats, True)
829 @unittest.skipUnless(hasattr(sys, "getallocatedblocks"),
830 "sys.getallocatedblocks unavailable on this build")
846 a = sys.getallocatedblocks()
859 self.assertLess(a, sys.gettotalrefcount())
864 b = sys.getallocatedblocks()
867 c = sys.getallocatedblocks()
871 self.assertIs(sys.is_finalizing(), False)
875 import sys
878 is_finalizing = sys.is_finalizing
892 # sys.flags and sys.float_info were wiped during shutdown.
894 import sys
896 def __del__(self, sys=sys):
897 print(sys.flags)
898 print(sys.float_info)
903 self.assertIn(b'sys.flags', out[0])
904 self.assertIn(b'sys.float_info', out[1])
908 import struct, sys
916 sys.x = C()
923 @unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
924 'need sys.getandroidapilevel()')
926 level = sys.getandroidapilevel()
932 import sys
937 sys.tracebacklimit = %r
941 p = subprocess.Popen([sys.executable, '-c', code % tracebacklimit],
964 self.assertEqual(len(sys.meta_path), len(set(sys.meta_path)))
966 @unittest.skipUnless(hasattr(sys, "_enablelegacywindowsfsencoding"),
967 'needs sys._enablelegacywindowsfsencoding()')
969 code = ('import sys',
970 'sys._enablelegacywindowsfsencoding()',
971 'print(sys.getfilesystemencoding(), sys.getfilesystemencodeerrors())')
978 import sys
979 print(sys.argv)
980 print(sys.orig_argv)
982 args = [sys.executable, '-I', '-X', 'utf8', '-c', code, 'arg']
985 repr(['-c', 'arg']), # sys.argv
986 repr(args), # sys.orig_argv
992 self.assertIsInstance(sys.stdlib_module_names, frozenset)
993 for name in sys.stdlib_module_names:
1020 with test.support.swap_attr(sys, 'unraisablehook',
1021 sys.__unraisablehook__):
1054 test.support.swap_attr(sys, 'unraisablehook',
1055 sys.__unraisablehook__):
1079 test.support.swap_attr(sys, 'unraisablehook',
1080 sys.__unraisablehook__):
1089 with test.support.swap_attr(sys, 'unraisablehook',
1090 sys.__unraisablehook__):
1092 sys.unraisablehook(exc)
1103 with test.support.swap_attr(sys, 'unraisablehook', hook_func):
1120 with test.support.swap_attr(sys, 'unraisablehook', hook_func):
1125 self.assertIn(f'Exception ignored in sys.unraisablehook: '
1137 self.longdigit = sys.int_info.sizeof_digit
1148 self.assertEqual(sys.getsizeof(True), vsize('') + self.longdigit)
1150 self.assertEqual(sys.getsizeof([]), vsize('Pn') + gc_header_size)
1156 self.assertRaises(ValueError, sys.getsizeof, BadSizeof())
1161 self.assertRaises(TypeError, sys.getsizeof, InvalidSizeof())
1163 self.assertIs(sys.getsizeof(InvalidSizeof(), sentinel), sentinel)
1168 self.assertRaises(TypeError, sys.getsizeof, FloatSizeof())
1169 self.assertIs(sys.getsizeof(FloatSizeof(), sentinel), sentinel)
1174 self.assertEqual(sys.getsizeof(OverflowSizeof(sys.maxsize)),
1175 sys.maxsize + self.gc_headsize)
1177 sys.getsizeof(OverflowSizeof(sys.maxsize + 1))
1179 sys.getsizeof(OverflowSizeof(-1))
1181 sys.getsizeof(OverflowSizeof(-sys.maxsize - 1))
1185 self.assertEqual(sys.getsizeof(True), size('') + self.longdigit)
1186 self.assertEqual(sys.getsizeof(True, -1), size('') + self.longdigit)
1219 self.assertGreaterEqual(sys.getsizeof(a), expected_size)
1286 # sys.floatinfo
1287 check(sys.float_info, vsize('') + self.P * len(sys.float_info))
1335 PyLong_BASE = 2**sys.int_info.bits_per_digit
1455 expected = sys.getsizeof(base) + struct.calcsize(extra)
1458 self.assertEqual(sys.getsizeof(obj), expected)
1495 tb = sys.exc_info()[2]
1501 # sys.flags
1502 check(sys.flags, vsize('') + self.P * len(sys.flags))
1505 old = sys.get_asyncgen_hooks()
1510 sys.set_asyncgen_hooks(firstiter=firstiter)
1511 hooks = sys.get_asyncgen_hooks()
1518 sys.set_asyncgen_hooks(finalizer=finalizer)
1519 hooks = sys.get_asyncgen_hooks()
1525 sys.set_asyncgen_hooks(*old)
1526 cur = sys.get_asyncgen_hooks()
1532 # to sys.stderr the following code can crash. See bpo-43660
1535 import sys
1538 sys.stderr = None
1539 sys.stderr = MyStderr()