Lines Matching full:sys
3 import sys, io, os
23 self.orig_stdout = sys.stdout
24 self.orig_stderr = sys.stderr
25 self.orig_displayhook = sys.displayhook
28 sys.stdout = self.orig_stdout
29 sys.stderr = self.orig_stderr
30 sys.displayhook = self.orig_displayhook
36 sys.stdout = out
38 dh = sys.__displayhook__
51 del sys.stdout
55 del sys.displayhook
62 sys.displayhook = baddisplayhook
68 sys.stderr = err
70 eh = sys.__excepthook__
76 eh(*sys.exc_info())
82 sys.excepthook(1, '1', 1)
91 self.assertRaises(TypeError, sys.exit, 42, 42)
95 sys.exit()
98 rc, out, err = assert_python_ok('-c', 'import sys; sys.exit()')
105 sys.exit(42)
111 sys.exit((42,))
116 sys.exit("exit")
121 sys.exit((17, 23))
140 r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")',
146 r'import sys; sys.exit("surrogates:\uDCFF")',
152 r'import sys; sys.exit("h\xe9")',
156 self.assertRaises(TypeError, sys.getdefaultencoding, 42)
158 self.assertIsInstance(sys.getdefaultencoding(), str)
160 # testing sys.settrace() is done in test_sys_settrace.py
161 # testing sys.setprofile() is done in test_sys_setprofile.py
166 self.assertRaises(TypeError, sys.setcheckinterval)
167 orig = sys.getcheckinterval()
169 sys.setcheckinterval(n)
170 self.assertEqual(sys.getcheckinterval(), n)
173 self.assertRaises(TypeError, sys.setswitchinterval)
174 self.assertRaises(TypeError, sys.setswitchinterval, "a")
175 self.assertRaises(ValueError, sys.setswitchinterval, -1.0)
176 self.assertRaises(ValueError, sys.setswitchinterval, 0.0)
177 orig = sys.getswitchinterval()
182 sys.setswitchinterval(n)
183 self.assertAlmostEqual(sys.getswitchinterval(), n)
185 sys.setswitchinterval(orig)
188 self.assertRaises(TypeError, sys.getrecursionlimit, 42)
189 oldlimit = sys.getrecursionlimit()
190 self.assertRaises(TypeError, sys.setrecursionlimit)
191 self.assertRaises(ValueError, sys.setrecursionlimit, -42)
192 sys.setrecursionlimit(10000)
193 self.assertEqual(sys.getrecursionlimit(), 10000)
194 sys.setrecursionlimit(oldlimit)
197 if hasattr(sys, 'gettrace') and sys.gettrace():
200 oldlimit = sys.getrecursionlimit()
206 sys.setrecursionlimit(depth)
217 sys.setrecursionlimit(oldlimit)
232 sys.setrecursionlimit(limit)
240 oldlimit = sys.getrecursionlimit()
242 sys.setrecursionlimit(1000)
252 sys.setrecursionlimit(oldlimit)
258 import sys
266 sys.setrecursionlimit(%d)
270 sub = subprocess.Popen([sys.executable, '-c', code % i],
279 # Raise SkipTest if sys doesn't have getwindowsversion attribute
280 test.support.get_attribute(sys, "getwindowsversion")
281 v = sys.getwindowsversion()
306 maj, min, buildno, plat, csd = sys.getwindowsversion()
309 self.assertRaises(TypeError, sys.call_tracing, type, 2)
311 @unittest.skipUnless(hasattr(sys, "setdlopenflags"),
312 'test needs sys.setdlopenflags()')
314 self.assertTrue(hasattr(sys, "getdlopenflags"))
315 self.assertRaises(TypeError, sys.getdlopenflags, 42)
316 oldflags = sys.getdlopenflags()
317 self.assertRaises(TypeError, sys.setdlopenflags)
318 sys.setdlopenflags(oldflags+1)
319 self.assertEqual(sys.getdlopenflags(), oldflags+1)
320 sys.setdlopenflags(oldflags)
329 self.assertRaises(TypeError, sys.getrefcount)
330 c = sys.getrefcount(None)
332 self.assertEqual(sys.getrefcount(None), c+1)
334 self.assertEqual(sys.getrefcount(None), c)
335 if hasattr(sys, "gettotalrefcount"):
336 self.assertIsInstance(sys.gettotalrefcount(), int)
339 self.assertRaises(TypeError, sys._getframe, 42, 42)
340 self.assertRaises(ValueError, sys._getframe, 2000000000)
343 is sys._getframe().f_code
346 # sys._current_frames() is a CPython-only gimmick.
353 # thread does sys._current_frames(), and verifies that the frames
377 d = sys._current_frames()
388 self.assertTrue(frame is sys._getframe())
413 self.assertIsInstance(sys.api_version, int)
414 self.assertIsInstance(sys.argv, list)
415 self.assertIn(sys.byteorder, ("little", "big"))
416 self.assertIsInstance(sys.builtin_module_names, tuple)
417 self.assertIsInstance(sys.copyright, str)
418 self.assertIsInstance(sys.exec_prefix, str)
419 self.assertIsInstance(sys.base_exec_prefix, str)
420 self.assertIsInstance(sys.executable, str)
421 self.assertEqual(len(sys.float_info), 11)
422 self.assertEqual(sys.float_info.radix, 2)
423 self.assertEqual(len(sys.int_info), 2)
424 self.assertTrue(sys.int_info.bits_per_digit % 5 == 0)
425 self.assertTrue(sys.int_info.sizeof_digit >= 1)
426 self.assertEqual(type(sys.int_info.bits_per_digit), int)
427 self.assertEqual(type(sys.int_info.sizeof_digit), int)
428 self.assertIsInstance(sys.hexversion, int)
430 self.assertEqual(len(sys.hash_info), 9)
431 self.assertLess(sys.hash_info.modulus, 2**sys.hash_info.width)
432 # sys.hash_info.modulus should be a prime; we do a quick
437 pow(x, sys.hash_info.modulus-1, sys.hash_info.modulus),
439 "sys.hash_info.modulus {} is a non-prime".format(
440 sys.hash_info.modulus)
442 self.assertIsInstance(sys.hash_info.inf, int)
443 self.assertIsInstance(sys.hash_info.nan, int)
444 self.assertIsInstance(sys.hash_info.imag, int)
446 if sys.hash_info.algorithm in {"fnv", "siphash24"}:
447 self.assertIn(sys.hash_info.hash_bits, {32, 64})
448 self.assertIn(sys.hash_info.seed_bits, {32, 64, 128})
451 self.assertEqual(sys.hash_info.algorithm, "siphash24")
453 self.assertEqual(sys.hash_info.algorithm, "fnv")
455 self.assertIn(sys.hash_info.algorithm, {"fnv", "siphash24"})
459 self.assertGreaterEqual(sys.hash_info.cutoff, 0)
460 self.assertLess(sys.hash_info.cutoff, 8)
462 self.assertIsInstance(sys.maxsize, int)
463 self.assertIsInstance(sys.maxunicode, int)
464 self.assertEqual(sys.maxunicode, 0x10FFFF)
465 self.assertIsInstance(sys.platform, str)
466 self.assertIsInstance(sys.prefix, str)
467 self.assertIsInstance(sys.base_prefix, str)
468 self.assertIsInstance(sys.version, str)
469 vi = sys.version_info
488 self.assertIsInstance(sys.float_repr_style, str)
489 self.assertIn(sys.float_repr_style, ('short', 'legacy'))
490 if not sys.platform.startswith('win'):
491 self.assertIsInstance(sys.abiflags, str)
494 info = sys.thread_info
500 # Can't use sys.stdout, as this is a StringIO object when
502 self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
507 self.assertRaises(TypeError, sys.intern)
509 self.assertTrue(sys.intern(s) is s)
511 self.assertTrue(sys.intern(s2) is s)
522 self.assertRaises(TypeError, sys.intern, S("abc"))
525 self.assertTrue(sys.flags)
532 self.assertTrue(hasattr(sys.flags, attr), attr)
534 self.assertEqual(type(getattr(sys.flags, attr)), attr_type, attr)
535 self.assertTrue(repr(sys.flags))
536 self.assertEqual(len(sys.flags), len(attrs))
538 self.assertIn(sys.flags.utf8_mode, {0, 1, 2})
542 # sys.flags, sys.version_info, and sys.getwindowsversion.
550 self.assert_raise_on_new_sys_type(sys.flags)
553 self.assert_raise_on_new_sys_type(sys.version_info)
557 test.support.get_attribute(sys, "getwindowsversion")
558 self.assert_raise_on_new_sys_type(sys.getwindowsversion())
562 sys._clear_type_cache()
571 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
578 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
584 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
593 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
602 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xdcbd))'],
609 @unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False),
615 p = subprocess.Popen([sys.executable, "-c",
621 @unittest.skipIf(sys.base_prefix != sys.prefix,
624 # sys.executable should be absolute
625 self.assertEqual(os.path.abspath(sys.executable), sys.executable)
627 # Issue #7774: Ensure that sys.executable is an empty string if argv[0]
633 python_dir = os.path.dirname(os.path.realpath(sys.executable))
636 'import sys; print(sys.executable.encode("ascii", "backslashreplace"))'],
637 executable=sys.executable, stdout=subprocess.PIPE, cwd=python_dir)
641 self.assertIn(executable, ["b''", repr(sys.executable.encode("ascii", "backslashreplace"))])
650 fs_encoding = sys.getfilesystemencoding()
651 if sys.platform == 'darwin':
663 'import sys',
665 ' std = getattr(sys, name)',
671 args = [sys.executable, "-c", code]
735 self.assertTrue(hasattr(sys.implementation, 'name'))
736 self.assertTrue(hasattr(sys.implementation, 'version'))
737 self.assertTrue(hasattr(sys.implementation, 'hexversion'))
738 self.assertTrue(hasattr(sys.implementation, 'cache_tag'))
740 version = sys.implementation.version
746 self.assertEqual(sys.implementation.hexversion, hexversion)
749 self.assertEqual(sys.implementation.name,
750 sys.implementation.name.lower())
754 # Test sys._debugmallocstats()
756 args = ['-c', 'import sys; sys._debugmallocstats()']
761 self.assertRaises(TypeError, sys._debugmallocstats, True)
763 @unittest.skipUnless(hasattr(sys, "getallocatedblocks"),
764 "sys.getallocatedblocks unavailable on this build")
775 a = sys.getallocatedblocks()
788 self.assertLess(a, sys.gettotalrefcount())
793 b = sys.getallocatedblocks()
796 c = sys.getallocatedblocks()
801 self.assertIs(sys.is_finalizing(), False)
805 import sys
808 is_finalizing = sys.is_finalizing
821 @unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
822 'need sys.getandroidapilevel()')
824 level = sys.getandroidapilevel()
830 import sys
835 sys.tracebacklimit = %r
839 p = subprocess.Popen([sys.executable, '-c', code % tracebacklimit],
862 self.assertEqual(len(sys.meta_path), len(set(sys.meta_path)))
870 self.longdigit = sys.int_info.sizeof_digit
881 self.assertEqual(sys.getsizeof(True), vsize('') + self.longdigit)
883 self.assertEqual(sys.getsizeof([]), vsize('Pn') + gc_header_size)
889 self.assertRaises(ValueError, sys.getsizeof, BadSizeof())
894 self.assertRaises(TypeError, sys.getsizeof, InvalidSizeof())
896 self.assertIs(sys.getsizeof(InvalidSizeof(), sentinel), sentinel)
901 self.assertRaises(TypeError, sys.getsizeof, FloatSizeof())
902 self.assertIs(sys.getsizeof(FloatSizeof(), sentinel), sentinel)
907 self.assertEqual(sys.getsizeof(OverflowSizeof(sys.maxsize)),
908 sys.maxsize + self.gc_headsize)
910 sys.getsizeof(OverflowSizeof(sys.maxsize + 1))
912 sys.getsizeof(OverflowSizeof(-1))
914 sys.getsizeof(OverflowSizeof(-sys.maxsize - 1))
918 self.assertEqual(sys.getsizeof(True), size('') + self.longdigit)
919 self.assertEqual(sys.getsizeof(True, -1), size('') + self.longdigit)
952 self.assertGreaterEqual(sys.getsizeof(a), expected_size)
1017 # sys.floatinfo
1018 check(sys.float_info, vsize('') + self.P * len(sys.float_info))
1066 PyLong_BASE = 2**sys.int_info.bits_per_digit
1126 if hasattr(sys, 'getcounts'):
1188 expected = sys.getsizeof(base) + struct.calcsize(extra)
1191 self.assertEqual(sys.getsizeof(obj), expected)
1228 tb = sys.exc_info()[2]
1234 # sys.flags
1235 check(sys.flags, vsize('') + self.P * len(sys.flags))
1238 old = sys.get_asyncgen_hooks()
1243 sys.set_asyncgen_hooks(firstiter=firstiter)
1244 hooks = sys.get_asyncgen_hooks()
1251 sys.set_asyncgen_hooks(finalizer=finalizer)
1252 hooks = sys.get_asyncgen_hooks()
1258 sys.set_asyncgen_hooks(*old)
1259 cur = sys.get_asyncgen_hooks()