003 File Manager
Current Path:
/usr/local/lib/python3.8/test
usr
/
local
/
lib
/
python3.8
/
test
/
📁
..
📄
Sine-1000Hz-300ms.aif
(60.25 KB)
📄
__init__.py
(47 B)
📄
__main__.py
(41 B)
📁
__pycache__
📄
_test_multiprocessing.py
(183.09 KB)
📄
allsans.pem
(9.87 KB)
📄
ann_module.py
(1.08 KB)
📄
ann_module2.py
(519 B)
📄
ann_module3.py
(448 B)
📁
audiodata
📄
audiotest.au
(27.48 KB)
📄
audiotests.py
(12.46 KB)
📄
audit-tests.py
(8.9 KB)
📄
autotest.py
(209 B)
📄
bad_coding.py
(24 B)
📄
bad_coding2.py
(30 B)
📄
bad_getattr.py
(61 B)
📄
bad_getattr2.py
(77 B)
📄
bad_getattr3.py
(139 B)
📄
badcert.pem
(1.88 KB)
📄
badkey.pem
(2.11 KB)
📄
badsyntax_3131.py
(32 B)
📄
badsyntax_future10.py
(95 B)
📄
badsyntax_future3.py
(172 B)
📄
badsyntax_future4.py
(153 B)
📄
badsyntax_future5.py
(184 B)
📄
badsyntax_future6.py
(161 B)
📄
badsyntax_future7.py
(196 B)
📄
badsyntax_future8.py
(122 B)
📄
badsyntax_future9.py
(142 B)
📄
badsyntax_pep3120.py
(14 B)
📄
bisect_cmd.py
(4.85 KB)
📄
bytecode_helper.py
(1.56 KB)
📁
capath
📄
cfgparser.1
(67 B)
📄
cfgparser.2
(19.02 KB)
📄
cfgparser.3
(1.55 KB)
📁
cjkencodings
📄
clinic.test
(94.65 KB)
📄
cmath_testcases.txt
(141.05 KB)
📄
coding20731.py
(22 B)
📄
curses_tests.py
(1.22 KB)
📁
data
📄
dataclass_module_1.py
(837 B)
📄
dataclass_module_1_str.py
(835 B)
📄
dataclass_module_2.py
(756 B)
📄
dataclass_module_2_str.py
(754 B)
📄
dataclass_textanno.py
(126 B)
📄
datetimetester.py
(239.84 KB)
📁
decimaltestdata
📄
dis_module.py
(76 B)
📄
doctest_aliases.py
(240 B)
📄
double_const.py
(1.18 KB)
📁
dtracedata
📁
eintrdata
📄
empty.vbs
(70 B)
📁
encoded_modules
📄
exception_hierarchy.txt
(1.78 KB)
📄
ffdh3072.pem
(2.16 KB)
📄
final_a.py
(411 B)
📄
final_b.py
(411 B)
📄
floating_points.txt
(15.92 KB)
📄
fork_wait.py
(2.53 KB)
📄
formatfloat_testcases.txt
(7.45 KB)
📄
future_test1.py
(229 B)
📄
future_test2.py
(149 B)
📄
gdb_sample.py
(153 B)
📄
good_getattr.py
(198 B)
📄
idnsans.pem
(9.71 KB)
📄
ieee754.txt
(3.21 KB)
📁
imghdrdata
📄
imp_dummy.py
(63 B)
📄
inspect_fodder.py
(1.88 KB)
📄
inspect_fodder2.py
(2.06 KB)
📄
keycert.passwd.pem
(4.13 KB)
📄
keycert.pem
(3.96 KB)
📄
keycert2.pem
(3.98 KB)
📄
keycert3.pem
(9.23 KB)
📄
keycert4.pem
(9.24 KB)
📄
keycertecc.pem
(5.5 KB)
📁
libregrtest
📄
list_tests.py
(16.54 KB)
📄
lock_tests.py
(28.26 KB)
📄
mailcap.txt
(1.24 KB)
📄
make_ssl_certs.py
(9.25 KB)
📄
mapping_tests.py
(21.75 KB)
📄
math_testcases.txt
(23.19 KB)
📄
memory_watchdog.py
(859 B)
📄
mime.types
(47.37 KB)
📄
mock_socket.py
(3.53 KB)
📄
mod_generics_cache.py
(1.13 KB)
📄
mp_fork_bomb.py
(448 B)
📄
mp_preload.py
(351 B)
📄
multibytecodec_support.py
(14.17 KB)
📄
nokia.pem
(1.88 KB)
📄
nosan.pem
(7.54 KB)
📄
nullbytecert.pem
(5.31 KB)
📄
nullcert.pem
(0 B)
📄
outstanding_bugs.py
(370 B)
📄
pickletester.py
(135.99 KB)
📄
profilee.py
(2.97 KB)
📄
pstats.pck
(65.05 KB)
📄
pycacert.pem
(5.53 KB)
📄
pycakey.pem
(2.43 KB)
📄
pyclbr_input.py
(648 B)
📄
pydoc_mod.py
(713 B)
📄
pydocfodder.py
(6.18 KB)
📄
pythoninfo.py
(20.34 KB)
📄
randv2_32.pck
(7.34 KB)
📄
randv2_64.pck
(7.19 KB)
📄
randv3.pck
(7.82 KB)
📄
re_tests.py
(25.93 KB)
📄
recursion.tar
(516 B)
📄
regrtest.py
(1.34 KB)
📄
relimport.py
(27 B)
📄
reperf.py
(538 B)
📄
revocation.crl
(800 B)
📄
sample_doctest.py
(1.02 KB)
📄
sample_doctest_no_docstrings.py
(227 B)
📄
sample_doctest_no_doctests.py
(269 B)
📄
secp384r1.pem
(256 B)
📄
selfsigned_pythontestdotnet.pem
(2.08 KB)
📄
seq_tests.py
(14.18 KB)
📄
sgml_input.html
(8.1 KB)
📄
signalinterproctester.py
(2.7 KB)
📁
sndhdrdata
📄
sortperf.py
(4.69 KB)
📄
ssl_cert.pem
(1.53 KB)
📄
ssl_key.passwd.pem
(2.59 KB)
📄
ssl_key.pem
(2.43 KB)
📄
ssl_servers.py
(7.04 KB)
📄
ssltests.py
(1.03 KB)
📄
string_tests.py
(64.65 KB)
📁
subprocessdata
📁
support
📄
talos-2019-0758.pem
(1.3 KB)
📄
test___all__.py
(4.12 KB)
📄
test___future__.py
(2.36 KB)
📄
test__locale.py
(7.83 KB)
📄
test__opcode.py
(3.03 KB)
📄
test__osx_support.py
(13.66 KB)
📄
test__xxsubinterpreters.py
(68.7 KB)
📄
test_abc.py
(18 KB)
📄
test_abstract_numbers.py
(1.49 KB)
📄
test_aifc.py
(17.68 KB)
📄
test_argparse.py
(172.67 KB)
📄
test_array.py
(52.57 KB)
📄
test_asdl_parser.py
(4.15 KB)
📄
test_ast.py
(88.53 KB)
📄
test_asyncgen.py
(31.44 KB)
📄
test_asynchat.py
(9.28 KB)
📁
test_asyncio
📄
test_asyncore.py
(25.81 KB)
📄
test_atexit.py
(5.81 KB)
📄
test_audioop.py
(28.24 KB)
📄
test_audit.py
(4.05 KB)
📄
test_augassign.py
(7.68 KB)
📄
test_base64.py
(30.17 KB)
📄
test_baseexception.py
(6.86 KB)
📄
test_bdb.py
(41.55 KB)
📄
test_bigaddrspace.py
(2.92 KB)
📄
test_bigmem.py
(44.88 KB)
📄
test_binascii.py
(18 KB)
📄
test_binhex.py
(1.79 KB)
📄
test_binop.py
(14.14 KB)
📄
test_bisect.py
(13.63 KB)
📄
test_bool.py
(12.48 KB)
📄
test_buffer.py
(160.04 KB)
📄
test_bufio.py
(2.54 KB)
📄
test_builtin.py
(78.38 KB)
📄
test_bytes.py
(72.23 KB)
📄
test_bz2.py
(36.76 KB)
📄
test_c_locale_coercion.py
(18.82 KB)
📄
test_calendar.py
(48.71 KB)
📄
test_call.py
(20.88 KB)
📄
test_capi.py
(30.46 KB)
📄
test_cgi.py
(22.15 KB)
📄
test_cgitb.py
(2.5 KB)
📄
test_charmapcodec.py
(1.68 KB)
📄
test_class.py
(17.42 KB)
📄
test_clinic.py
(21.71 KB)
📄
test_cmath.py
(24.07 KB)
📄
test_cmd.py
(6.1 KB)
📄
test_cmd_line.py
(33.72 KB)
📄
test_cmd_line_script.py
(31.46 KB)
📄
test_code.py
(13.66 KB)
📄
test_code_module.py
(5.51 KB)
📄
test_codeccallbacks.py
(40.97 KB)
📄
test_codecencodings_cn.py
(3.86 KB)
📄
test_codecencodings_hk.py
(701 B)
📄
test_codecencodings_iso2022.py
(1.36 KB)
📄
test_codecencodings_jp.py
(4.79 KB)
📄
test_codecencodings_kr.py
(2.96 KB)
📄
test_codecencodings_tw.py
(681 B)
📄
test_codecmaps_cn.py
(746 B)
📄
test_codecmaps_hk.py
(386 B)
📄
test_codecmaps_jp.py
(1.7 KB)
📄
test_codecmaps_kr.py
(1.16 KB)
📄
test_codecmaps_tw.py
(705 B)
📄
test_codecs.py
(129.38 KB)
📄
test_codeop.py
(7.97 KB)
📄
test_collections.py
(83.93 KB)
📄
test_colorsys.py
(3.83 KB)
📄
test_compare.py
(3.82 KB)
📄
test_compile.py
(36.48 KB)
📄
test_compileall.py
(26.7 KB)
📄
test_complex.py
(30.24 KB)
📄
test_concurrent_futures.py
(44.93 KB)
📄
test_configparser.py
(84.93 KB)
📄
test_contains.py
(3.49 KB)
📄
test_context.py
(29.33 KB)
📄
test_contextlib.py
(32.54 KB)
📄
test_contextlib_async.py
(14.82 KB)
📄
test_copy.py
(25.81 KB)
📄
test_copyreg.py
(4.39 KB)
📄
test_coroutines.py
(62.52 KB)
📄
test_cprofile.py
(6.33 KB)
📄
test_crashers.py
(1.17 KB)
📄
test_crypt.py
(3.97 KB)
📄
test_csv.py
(47.77 KB)
📄
test_ctypes.py
(184 B)
📄
test_curses.py
(45.47 KB)
📄
test_dataclasses.py
(108.8 KB)
📄
test_datetime.py
(2.15 KB)
📄
test_dbm.py
(6.45 KB)
📄
test_dbm_dumb.py
(10.61 KB)
📄
test_dbm_gnu.py
(6.22 KB)
📄
test_dbm_ndbm.py
(5.05 KB)
📄
test_decimal.py
(206.63 KB)
📄
test_decorators.py
(9.48 KB)
📄
test_defaultdict.py
(5.88 KB)
📄
test_deque.py
(34.46 KB)
📄
test_descr.py
(190.58 KB)
📄
test_descrtut.py
(11.53 KB)
📄
test_devpoll.py
(4.5 KB)
📄
test_dict.py
(45 KB)
📄
test_dict_version.py
(5.88 KB)
📄
test_dictcomps.py
(4.42 KB)
📄
test_dictviews.py
(11.68 KB)
📄
test_difflib.py
(19.64 KB)
📄
test_difflib_expect.html
(100.85 KB)
📄
test_dis.py
(48.4 KB)
📄
test_distutils.py
(375 B)
📄
test_doctest.py
(98.67 KB)
📄
test_doctest.txt
(300 B)
📄
test_doctest2.py
(2.3 KB)
📄
test_doctest2.txt
(392 B)
📄
test_doctest3.txt
(82 B)
📄
test_doctest4.txt
(244 B)
📄
test_docxmlrpc.py
(8.67 KB)
📄
test_dtrace.py
(5.23 KB)
📄
test_dummy_thread.py
(9.69 KB)
📄
test_dummy_threading.py
(1.7 KB)
📄
test_dynamic.py
(4.29 KB)
📄
test_dynamicclassattribute.py
(9.57 KB)
📄
test_eintr.py
(1.32 KB)
📁
test_email
📄
test_embed.py
(49.23 KB)
📄
test_ensurepip.py
(9.83 KB)
📄
test_enum.py
(113.68 KB)
📄
test_enumerate.py
(8.46 KB)
📄
test_eof.py
(1.94 KB)
📄
test_epoll.py
(9.03 KB)
📄
test_errno.py
(1.04 KB)
📄
test_exception_hierarchy.py
(7.43 KB)
📄
test_exception_variations.py
(3.86 KB)
📄
test_exceptions.py
(49.81 KB)
📄
test_extcall.py
(13.49 KB)
📄
test_faulthandler.py
(28.13 KB)
📄
test_fcntl.py
(6.21 KB)
📄
test_file.py
(11.02 KB)
📄
test_file_eintr.py
(10.6 KB)
📄
test_filecmp.py
(8.69 KB)
📄
test_fileinput.py
(37.33 KB)
📄
test_fileio.py
(19.96 KB)
📄
test_finalization.py
(14.66 KB)
📄
test_float.py
(63.41 KB)
📄
test_flufl.py
(1.32 KB)
📄
test_fnmatch.py
(5.07 KB)
📄
test_fork1.py
(3.67 KB)
📄
test_format.py
(22.58 KB)
📄
test_fractions.py
(29.83 KB)
📄
test_frame.py
(5.67 KB)
📄
test_frozen.py
(943 B)
📄
test_fstring.py
(46.16 KB)
📄
test_ftplib.py
(39.71 KB)
📄
test_funcattrs.py
(13.54 KB)
📄
test_functools.py
(90.59 KB)
📄
test_future.py
(11.9 KB)
📄
test_future3.py
(490 B)
📄
test_future4.py
(222 B)
📄
test_future5.py
(510 B)
📄
test_gc.py
(40.49 KB)
📄
test_gdb.py
(40.88 KB)
📄
test_generator_stop.py
(943 B)
📄
test_generators.py
(58.51 KB)
📄
test_genericclass.py
(9.28 KB)
📄
test_genericpath.py
(21.7 KB)
📄
test_genexps.py
(7.12 KB)
📄
test_getargs2.py
(50 KB)
📄
test_getopt.py
(6.75 KB)
📄
test_getpass.py
(6.29 KB)
📄
test_gettext.py
(41.38 KB)
📄
test_glob.py
(13.03 KB)
📄
test_global.py
(1.31 KB)
📄
test_grammar.py
(57.5 KB)
📄
test_grp.py
(3.54 KB)
📄
test_gzip.py
(29.9 KB)
📄
test_hash.py
(11.45 KB)
📄
test_hashlib.py
(39.43 KB)
📄
test_heapq.py
(16.4 KB)
📄
test_hmac.py
(22.24 KB)
📄
test_html.py
(4.23 KB)
📄
test_htmlparser.py
(33.19 KB)
📄
test_http_cookiejar.py
(78.36 KB)
📄
test_http_cookies.py
(18.71 KB)
📄
test_httplib.py
(76.98 KB)
📄
test_httpservers.py
(45.24 KB)
📄
test_idle.py
(825 B)
📄
test_imaplib.py
(38.95 KB)
📄
test_imghdr.py
(4.66 KB)
📄
test_imp.py
(17.73 KB)
📁
test_import
📁
test_importlib
📄
test_index.py
(8.37 KB)
📄
test_inspect.py
(151.79 KB)
📄
test_int.py
(20.8 KB)
📄
test_int_literal.py
(6.89 KB)
📄
test_io.py
(163.94 KB)
📄
test_ioctl.py
(3.2 KB)
📄
test_ipaddress.py
(90.98 KB)
📄
test_isinstance.py
(10.25 KB)
📄
test_iter.py
(31.81 KB)
📄
test_iterlen.py
(7.1 KB)
📄
test_itertools.py
(101.41 KB)
📁
test_json
📄
test_keyword.py
(1.23 KB)
📄
test_keywordonlyarg.py
(6.85 KB)
📄
test_kqueue.py
(8.76 KB)
📄
test_largefile.py
(6.83 KB)
📄
test_lib2to3.py
(101 B)
📄
test_linecache.py
(7.79 KB)
📄
test_list.py
(7.4 KB)
📄
test_listcomps.py
(3.76 KB)
📄
test_lltrace.py
(1012 B)
📄
test_locale.py
(23.87 KB)
📄
test_logging.py
(182.43 KB)
📄
test_long.py
(53.21 KB)
📄
test_longexp.py
(233 B)
📄
test_lzma.py
(87.92 KB)
📄
test_mailbox.py
(91.92 KB)
📄
test_mailcap.py
(9.88 KB)
📄
test_marshal.py
(20.57 KB)
📄
test_math.py
(82.18 KB)
📄
test_memoryio.py
(31.48 KB)
📄
test_memoryview.py
(17.78 KB)
📄
test_metaclass.py
(6.2 KB)
📄
test_mimetypes.py
(12.14 KB)
📄
test_minidom.py
(66.95 KB)
📄
test_mmap.py
(29.04 KB)
📄
test_module.py
(10.3 KB)
📄
test_modulefinder.py
(12.2 KB)
📄
test_msilib.py
(5.06 KB)
📄
test_multibytecodec.py
(15.04 KB)
📄
test_multiprocessing_fork.py
(477 B)
📄
test_multiprocessing_forkserver.py
(392 B)
📄
test_multiprocessing_main_handling.py
(11.45 KB)
📄
test_multiprocessing_spawn.py
(277 B)
📄
test_named_expressions.py
(16.51 KB)
📄
test_netrc.py
(5.96 KB)
📄
test_nis.py
(1.13 KB)
📄
test_nntplib.py
(61.7 KB)
📄
test_normalization.py
(3.66 KB)
📄
test_ntpath.py
(35.08 KB)
📄
test_numeric_tower.py
(7.18 KB)
📄
test_opcodes.py
(3.61 KB)
📄
test_openpty.py
(600 B)
📄
test_operator.py
(23.54 KB)
📄
test_optparse.py
(60.99 KB)
📄
test_ordered_dict.py
(30.22 KB)
📄
test_os.py
(150.53 KB)
📄
test_ossaudiodev.py
(7.06 KB)
📄
test_osx_env.py
(1.3 KB)
📄
test_parser.py
(35.72 KB)
📄
test_pathlib.py
(97.12 KB)
📄
test_pdb.py
(55.36 KB)
📄
test_peepholer.py
(19.41 KB)
📄
test_pickle.py
(19.16 KB)
📄
test_picklebuffer.py
(4.96 KB)
📄
test_pickletools.py
(4.33 KB)
📄
test_pipes.py
(6.59 KB)
📄
test_pkg.py
(9.59 KB)
📄
test_pkgimport.py
(2.67 KB)
📄
test_pkgutil.py
(19.25 KB)
📄
test_platform.py
(14.31 KB)
📄
test_plistlib.py
(41.43 KB)
📄
test_poll.py
(7.23 KB)
📄
test_popen.py
(1.98 KB)
📄
test_poplib.py
(16.97 KB)
📄
test_positional_only_arg.py
(17.5 KB)
📄
test_posix.py
(75.76 KB)
📄
test_posixpath.py
(29.19 KB)
📄
test_pow.py
(5.44 KB)
📄
test_pprint.py
(43.85 KB)
📄
test_print.py
(7.37 KB)
📄
test_profile.py
(8.72 KB)
📄
test_property.py
(8.77 KB)
📄
test_pstats.py
(3.04 KB)
📄
test_pty.py
(11.97 KB)
📄
test_pulldom.py
(12.66 KB)
📄
test_pwd.py
(4.17 KB)
📄
test_py_compile.py
(10.78 KB)
📄
test_pyclbr.py
(10 KB)
📄
test_pydoc.py
(56.98 KB)
📄
test_pyexpat.py
(26.54 KB)
📄
test_queue.py
(20.36 KB)
📄
test_quopri.py
(7.78 KB)
📄
test_raise.py
(12.86 KB)
📄
test_random.py
(45.59 KB)
📄
test_range.py
(23.35 KB)
📄
test_re.py
(106.41 KB)
📄
test_readline.py
(12.95 KB)
📄
test_regrtest.py
(46.36 KB)
📄
test_repl.py
(3.96 KB)
📄
test_reprlib.py
(15.12 KB)
📄
test_resource.py
(7.02 KB)
📄
test_richcmp.py
(11.91 KB)
📄
test_rlcompleter.py
(6.3 KB)
📄
test_robotparser.py
(10.69 KB)
📄
test_runpy.py
(33.86 KB)
📄
test_sax.py
(46.9 KB)
📄
test_sched.py
(6.41 KB)
📄
test_scope.py
(19.7 KB)
📄
test_script_helper.py
(5.78 KB)
📄
test_secrets.py
(4.28 KB)
📄
test_select.py
(2.69 KB)
📄
test_selectors.py
(17.79 KB)
📄
test_set.py
(64.41 KB)
📄
test_setcomps.py
(3.7 KB)
📄
test_shelve.py
(6.24 KB)
📄
test_shlex.py
(13.29 KB)
📄
test_shutil.py
(101.55 KB)
📄
test_signal.py
(46.62 KB)
📄
test_site.py
(24.71 KB)
📄
test_slice.py
(8.25 KB)
📄
test_smtpd.py
(40.14 KB)
📄
test_smtplib.py
(56.51 KB)
📄
test_smtpnet.py
(2.87 KB)
📄
test_sndhdr.py
(1.43 KB)
📄
test_socket.py
(232.71 KB)
📄
test_socketserver.py
(17.7 KB)
📄
test_sort.py
(13.42 KB)
📄
test_source_encoding.py
(7.89 KB)
📄
test_spwd.py
(2.71 KB)
📄
test_sqlite.py
(948 B)
📄
test_ssl.py
(203.3 KB)
📄
test_startfile.py
(1.29 KB)
📄
test_stat.py
(8.3 KB)
📄
test_statistics.py
(106.5 KB)
📄
test_strftime.py
(7.54 KB)
📄
test_string.py
(19.8 KB)
📄
test_string_literals.py
(9.88 KB)
📄
test_stringprep.py
(3.04 KB)
📄
test_strptime.py
(34.42 KB)
📄
test_strtod.py
(20.06 KB)
📄
test_struct.py
(34.41 KB)
📄
test_structmembers.py
(4.7 KB)
📄
test_structseq.py
(3.87 KB)
📄
test_subclassinit.py
(8.12 KB)
📄
test_subprocess.py
(142.64 KB)
📄
test_sunau.py
(6.07 KB)
📄
test_sundry.py
(2.07 KB)
📄
test_super.py
(9.6 KB)
📄
test_support.py
(24.12 KB)
📄
test_symbol.py
(2.06 KB)
📄
test_symtable.py
(9.13 KB)
📄
test_syntax.py
(25.75 KB)
📄
test_sys.py
(55.24 KB)
📄
test_sys_setprofile.py
(12.31 KB)
📄
test_sys_settrace.py
(43.08 KB)
📄
test_sysconfig.py
(17.01 KB)
📄
test_syslog.py
(1.15 KB)
📄
test_tabnanny.py
(13.44 KB)
📄
test_tarfile.py
(98.31 KB)
📄
test_tcl.py
(30.74 KB)
📄
test_telnetlib.py
(12.7 KB)
📄
test_tempfile.py
(52.57 KB)
📄
test_textwrap.py
(38.84 KB)
📄
test_thread.py
(8.41 KB)
📄
test_threaded_import.py
(8.9 KB)
📄
test_threadedtempfile.py
(1.85 KB)
📄
test_threading.py
(47.52 KB)
📄
test_threading_local.py
(6.09 KB)
📄
test_threadsignals.py
(10.09 KB)
📄
test_time.py
(38.43 KB)
📄
test_timeit.py
(14.8 KB)
📄
test_timeout.py
(11.19 KB)
📄
test_tix.py
(756 B)
📄
test_tk.py
(362 B)
📄
test_tokenize.py
(63.18 KB)
📁
test_tools
📄
test_trace.py
(19.89 KB)
📄
test_traceback.py
(46.97 KB)
📄
test_tracemalloc.py
(37.41 KB)
📄
test_ttk_guionly.py
(746 B)
📄
test_ttk_textonly.py
(299 B)
📄
test_tuple.py
(18.85 KB)
📄
test_turtle.py
(12.79 KB)
📄
test_type_comments.py
(10.13 KB)
📄
test_typechecks.py
(2.55 KB)
📄
test_types.py
(58 KB)
📄
test_typing.py
(122.05 KB)
📄
test_ucn.py
(9.35 KB)
📄
test_unary.py
(1.63 KB)
📄
test_unicode.py
(129.94 KB)
📄
test_unicode_file.py
(5.74 KB)
📄
test_unicode_file_functions.py
(6.84 KB)
📄
test_unicode_identifiers.py
(891 B)
📄
test_unicodedata.py
(12.7 KB)
📄
test_unittest.py
(286 B)
📄
test_univnewlines.py
(3.83 KB)
📄
test_unpack.py
(3.01 KB)
📄
test_unpack_ex.py
(8.73 KB)
📄
test_urllib.py
(71.24 KB)
📄
test_urllib2.py
(76.95 KB)
📄
test_urllib2_localnet.py
(24.24 KB)
📄
test_urllib2net.py
(12.39 KB)
📄
test_urllib_response.py
(1.69 KB)
📄
test_urllibnet.py
(8.9 KB)
📄
test_urlparse.py
(64.87 KB)
📄
test_userdict.py
(7.64 KB)
📄
test_userlist.py
(1.97 KB)
📄
test_userstring.py
(2.4 KB)
📄
test_utf8_mode.py
(9.22 KB)
📄
test_utf8source.py
(1.15 KB)
📄
test_uu.py
(8.02 KB)
📄
test_uuid.py
(35.74 KB)
📄
test_venv.py
(20.46 KB)
📄
test_wait3.py
(1.16 KB)
📄
test_wait4.py
(1.15 KB)
📁
test_warnings
📄
test_wave.py
(6.57 KB)
📄
test_weakref.py
(69.47 KB)
📄
test_weakset.py
(15.03 KB)
📄
test_webbrowser.py
(10.47 KB)
📄
test_winconsoleio.py
(6.14 KB)
📄
test_winreg.py
(21.38 KB)
📄
test_winsound.py
(4.57 KB)
📄
test_with.py
(25.78 KB)
📄
test_wsgiref.py
(30.1 KB)
📄
test_xdrlib.py
(2.17 KB)
📄
test_xml_dom_minicompat.py
(4.18 KB)
📄
test_xml_etree.py
(147.87 KB)
📄
test_xml_etree_c.py
(8.06 KB)
📄
test_xmlrpc.py
(55.96 KB)
📄
test_xmlrpc_net.py
(1015 B)
📄
test_xxtestfuzz.py
(670 B)
📄
test_yield_from.py
(30.01 KB)
📄
test_zipapp.py
(15.92 KB)
📄
test_zipfile.py
(115.45 KB)
📄
test_zipfile64.py
(5.8 KB)
📄
test_zipimport.py
(29.28 KB)
📄
test_zipimport_support.py
(10.44 KB)
📄
test_zlib.py
(34.48 KB)
📄
testcodec.py
(1.02 KB)
📄
testtar.tar
(425 KB)
📄
tf_inherit_check.py
(714 B)
📄
threaded_import_hangers.py
(1.45 KB)
📄
time_hashlib.py
(2.87 KB)
📄
tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt
(443 B)
📄
tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt
(302 B)
📄
tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt
(421 B)
📄
tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
(326 B)
📄
tokenize_tests.txt
(2.65 KB)
📁
tracedmodules
📄
win_console_handler.py
(1.38 KB)
📁
xmltestdata
📄
xmltests.py
(499 B)
📄
zip_cp437_header.zip
(270 B)
📄
zipdir.zip
(374 B)
📁
ziptestdata
Editing: test_gc.py
import unittest from test.support import (verbose, refcount_test, run_unittest, strip_python_stderr, cpython_only, start_threads, temp_dir, requires_type_collecting, TESTFN, unlink, import_module) from test.support.script_helper import assert_python_ok, make_script import gc import sys import sysconfig import textwrap import threading import time import weakref try: from _testcapi import with_tp_del except ImportError: def with_tp_del(cls): class C(object): def __new__(cls, *args, **kwargs): raise TypeError('requires _testcapi.with_tp_del') return C ### Support code ############################################################################### # Bug 1055820 has several tests of longstanding bugs involving weakrefs and # cyclic gc. # An instance of C1055820 has a self-loop, so becomes cyclic trash when # unreachable. class C1055820(object): def __init__(self, i): self.i = i self.loop = self class GC_Detector(object): # Create an instance I. Then gc hasn't happened again so long as # I.gc_happened is false. def __init__(self): self.gc_happened = False def it_happened(ignored): self.gc_happened = True # Create a piece of cyclic trash that triggers it_happened when # gc collects it. self.wr = weakref.ref(C1055820(666), it_happened) @with_tp_del class Uncollectable(object): """Create a reference cycle with multiple __del__ methods. An object in a reference cycle will never have zero references, and so must be garbage collected. If one or more objects in the cycle have __del__ methods, the gc refuses to guess an order, and leaves the cycle uncollected.""" def __init__(self, partner=None): if partner is None: self.partner = Uncollectable(partner=self) else: self.partner = partner def __tp_del__(self): pass if sysconfig.get_config_vars().get('PY_CFLAGS', ''): BUILD_WITH_NDEBUG = ('-DNDEBUG' in sysconfig.get_config_vars()['PY_CFLAGS']) else: # Usually, sys.gettotalrefcount() is only present if Python has been # compiled in debug mode. If it's missing, expect that Python has # been released in release mode: with NDEBUG defined. BUILD_WITH_NDEBUG = (not hasattr(sys, 'gettotalrefcount')) ### Tests ############################################################################### class GCTests(unittest.TestCase): def test_list(self): l = [] l.append(l) gc.collect() del l self.assertEqual(gc.collect(), 1) def test_dict(self): d = {} d[1] = d gc.collect() del d self.assertEqual(gc.collect(), 1) def test_tuple(self): # since tuples are immutable we close the loop with a list l = [] t = (l,) l.append(t) gc.collect() del t del l self.assertEqual(gc.collect(), 2) def test_class(self): class A: pass A.a = A gc.collect() del A self.assertNotEqual(gc.collect(), 0) def test_newstyleclass(self): class A(object): pass gc.collect() del A self.assertNotEqual(gc.collect(), 0) def test_instance(self): class A: pass a = A() a.a = a gc.collect() del a self.assertNotEqual(gc.collect(), 0) @requires_type_collecting def test_newinstance(self): class A(object): pass a = A() a.a = a gc.collect() del a self.assertNotEqual(gc.collect(), 0) class B(list): pass class C(B, A): pass a = C() a.a = a gc.collect() del a self.assertNotEqual(gc.collect(), 0) del B, C self.assertNotEqual(gc.collect(), 0) A.a = A() del A self.assertNotEqual(gc.collect(), 0) self.assertEqual(gc.collect(), 0) def test_method(self): # Tricky: self.__init__ is a bound method, it references the instance. class A: def __init__(self): self.init = self.__init__ a = A() gc.collect() del a self.assertNotEqual(gc.collect(), 0) @cpython_only def test_legacy_finalizer(self): # A() is uncollectable if it is part of a cycle, make sure it shows up # in gc.garbage. @with_tp_del class A: def __tp_del__(self): pass class B: pass a = A() a.a = a id_a = id(a) b = B() b.b = b gc.collect() del a del b self.assertNotEqual(gc.collect(), 0) for obj in gc.garbage: if id(obj) == id_a: del obj.a break else: self.fail("didn't find obj in garbage (finalizer)") gc.garbage.remove(obj) @cpython_only def test_legacy_finalizer_newclass(self): # A() is uncollectable if it is part of a cycle, make sure it shows up # in gc.garbage. @with_tp_del class A(object): def __tp_del__(self): pass class B(object): pass a = A() a.a = a id_a = id(a) b = B() b.b = b gc.collect() del a del b self.assertNotEqual(gc.collect(), 0) for obj in gc.garbage: if id(obj) == id_a: del obj.a break else: self.fail("didn't find obj in garbage (finalizer)") gc.garbage.remove(obj) def test_function(self): # Tricky: f -> d -> f, code should call d.clear() after the exec to # break the cycle. d = {} exec("def f(): pass\n", d) gc.collect() del d self.assertEqual(gc.collect(), 2) @refcount_test def test_frame(self): def f(): frame = sys._getframe() gc.collect() f() self.assertEqual(gc.collect(), 1) def test_saveall(self): # Verify that cyclic garbage like lists show up in gc.garbage if the # SAVEALL option is enabled. # First make sure we don't save away other stuff that just happens to # be waiting for collection. gc.collect() # if this fails, someone else created immortal trash self.assertEqual(gc.garbage, []) L = [] L.append(L) id_L = id(L) debug = gc.get_debug() gc.set_debug(debug | gc.DEBUG_SAVEALL) del L gc.collect() gc.set_debug(debug) self.assertEqual(len(gc.garbage), 1) obj = gc.garbage.pop() self.assertEqual(id(obj), id_L) def test_del(self): # __del__ methods can trigger collection, make this to happen thresholds = gc.get_threshold() gc.enable() gc.set_threshold(1) class A: def __del__(self): dir(self) a = A() del a gc.disable() gc.set_threshold(*thresholds) def test_del_newclass(self): # __del__ methods can trigger collection, make this to happen thresholds = gc.get_threshold() gc.enable() gc.set_threshold(1) class A(object): def __del__(self): dir(self) a = A() del a gc.disable() gc.set_threshold(*thresholds) # The following two tests are fragile: # They precisely count the number of allocations, # which is highly implementation-dependent. # For example, disposed tuples are not freed, but reused. # To minimize variations, though, we first store the get_count() results # and check them at the end. @refcount_test def test_get_count(self): gc.collect() a, b, c = gc.get_count() x = [] d, e, f = gc.get_count() self.assertEqual((b, c), (0, 0)) self.assertEqual((e, f), (0, 0)) # This is less fragile than asserting that a equals 0. self.assertLess(a, 5) # Between the two calls to get_count(), at least one object was # created (the list). self.assertGreater(d, a) @refcount_test def test_collect_generations(self): gc.collect() # This object will "trickle" into generation N + 1 after # each call to collect(N) x = [] gc.collect(0) # x is now in gen 1 a, b, c = gc.get_count() gc.collect(1) # x is now in gen 2 d, e, f = gc.get_count() gc.collect(2) # x is now in gen 3 g, h, i = gc.get_count() # We don't check a, d, g since their exact values depends on # internal implementation details of the interpreter. self.assertEqual((b, c), (1, 0)) self.assertEqual((e, f), (0, 1)) self.assertEqual((h, i), (0, 0)) def test_trashcan(self): class Ouch: n = 0 def __del__(self): Ouch.n = Ouch.n + 1 if Ouch.n % 17 == 0: gc.collect() # "trashcan" is a hack to prevent stack overflow when deallocating # very deeply nested tuples etc. It works in part by abusing the # type pointer and refcount fields, and that can yield horrible # problems when gc tries to traverse the structures. # If this test fails (as it does in 2.0, 2.1 and 2.2), it will # most likely die via segfault. # Note: In 2.3 the possibility for compiling without cyclic gc was # removed, and that in turn allows the trashcan mechanism to work # via much simpler means (e.g., it never abuses the type pointer or # refcount fields anymore). Since it's much less likely to cause a # problem now, the various constants in this expensive (we force a lot # of full collections) test are cut back from the 2.2 version. gc.enable() N = 150 for count in range(2): t = [] for i in range(N): t = [t, Ouch()] u = [] for i in range(N): u = [u, Ouch()] v = {} for i in range(N): v = {1: v, 2: Ouch()} gc.disable() def test_trashcan_threads(self): # Issue #13992: trashcan mechanism should be thread-safe NESTING = 60 N_THREADS = 2 def sleeper_gen(): """A generator that releases the GIL when closed or dealloc'ed.""" try: yield finally: time.sleep(0.000001) class C(list): # Appending to a list is atomic, which avoids the use of a lock. inits = [] dels = [] def __init__(self, alist): self[:] = alist C.inits.append(None) def __del__(self): # This __del__ is called by subtype_dealloc(). C.dels.append(None) # `g` will release the GIL when garbage-collected. This # helps assert subtype_dealloc's behaviour when threads # switch in the middle of it. g = sleeper_gen() next(g) # Now that __del__ is finished, subtype_dealloc will proceed # to call list_dealloc, which also uses the trashcan mechanism. def make_nested(): """Create a sufficiently nested container object so that the trashcan mechanism is invoked when deallocating it.""" x = C([]) for i in range(NESTING): x = [C([x])] del x def run_thread(): """Exercise make_nested() in a loop.""" while not exit: make_nested() old_switchinterval = sys.getswitchinterval() sys.setswitchinterval(1e-5) try: exit = [] threads = [] for i in range(N_THREADS): t = threading.Thread(target=run_thread) threads.append(t) with start_threads(threads, lambda: exit.append(1)): time.sleep(1.0) finally: sys.setswitchinterval(old_switchinterval) gc.collect() self.assertEqual(len(C.inits), len(C.dels)) def test_boom(self): class Boom: def __getattr__(self, someattribute): del self.attr raise AttributeError a = Boom() b = Boom() a.attr = b b.attr = a gc.collect() garbagelen = len(gc.garbage) del a, b # a<->b are in a trash cycle now. Collection will invoke # Boom.__getattr__ (to see whether a and b have __del__ methods), and # __getattr__ deletes the internal "attr" attributes as a side effect. # That causes the trash cycle to get reclaimed via refcounts falling to # 0, thus mutating the trash graph as a side effect of merely asking # whether __del__ exists. This used to (before 2.3b1) crash Python. # Now __getattr__ isn't called. self.assertEqual(gc.collect(), 4) self.assertEqual(len(gc.garbage), garbagelen) def test_boom2(self): class Boom2: def __init__(self): self.x = 0 def __getattr__(self, someattribute): self.x += 1 if self.x > 1: del self.attr raise AttributeError a = Boom2() b = Boom2() a.attr = b b.attr = a gc.collect() garbagelen = len(gc.garbage) del a, b # Much like test_boom(), except that __getattr__ doesn't break the # cycle until the second time gc checks for __del__. As of 2.3b1, # there isn't a second time, so this simply cleans up the trash cycle. # We expect a, b, a.__dict__ and b.__dict__ (4 objects) to get # reclaimed this way. self.assertEqual(gc.collect(), 4) self.assertEqual(len(gc.garbage), garbagelen) def test_boom_new(self): # boom__new and boom2_new are exactly like boom and boom2, except use # new-style classes. class Boom_New(object): def __getattr__(self, someattribute): del self.attr raise AttributeError a = Boom_New() b = Boom_New() a.attr = b b.attr = a gc.collect() garbagelen = len(gc.garbage) del a, b self.assertEqual(gc.collect(), 4) self.assertEqual(len(gc.garbage), garbagelen) def test_boom2_new(self): class Boom2_New(object): def __init__(self): self.x = 0 def __getattr__(self, someattribute): self.x += 1 if self.x > 1: del self.attr raise AttributeError a = Boom2_New() b = Boom2_New() a.attr = b b.attr = a gc.collect() garbagelen = len(gc.garbage) del a, b self.assertEqual(gc.collect(), 4) self.assertEqual(len(gc.garbage), garbagelen) def test_get_referents(self): alist = [1, 3, 5] got = gc.get_referents(alist) got.sort() self.assertEqual(got, alist) atuple = tuple(alist) got = gc.get_referents(atuple) got.sort() self.assertEqual(got, alist) adict = {1: 3, 5: 7} expected = [1, 3, 5, 7] got = gc.get_referents(adict) got.sort() self.assertEqual(got, expected) got = gc.get_referents([1, 2], {3: 4}, (0, 0, 0)) got.sort() self.assertEqual(got, [0, 0] + list(range(5))) self.assertEqual(gc.get_referents(1, 'a', 4j), []) def test_is_tracked(self): # Atomic built-in types are not tracked, user-defined objects and # mutable containers are. # NOTE: types with special optimizations (e.g. tuple) have tests # in their own test files instead. self.assertFalse(gc.is_tracked(None)) self.assertFalse(gc.is_tracked(1)) self.assertFalse(gc.is_tracked(1.0)) self.assertFalse(gc.is_tracked(1.0 + 5.0j)) self.assertFalse(gc.is_tracked(True)) self.assertFalse(gc.is_tracked(False)) self.assertFalse(gc.is_tracked(b"a")) self.assertFalse(gc.is_tracked("a")) self.assertFalse(gc.is_tracked(bytearray(b"a"))) self.assertFalse(gc.is_tracked(type)) self.assertFalse(gc.is_tracked(int)) self.assertFalse(gc.is_tracked(object)) self.assertFalse(gc.is_tracked(object())) class UserClass: pass class UserInt(int): pass # Base class is object; no extra fields. class UserClassSlots: __slots__ = () # Base class is fixed size larger than object; no extra fields. class UserFloatSlots(float): __slots__ = () # Base class is variable size; no extra fields. class UserIntSlots(int): __slots__ = () self.assertTrue(gc.is_tracked(gc)) self.assertTrue(gc.is_tracked(UserClass)) self.assertTrue(gc.is_tracked(UserClass())) self.assertTrue(gc.is_tracked(UserInt())) self.assertTrue(gc.is_tracked([])) self.assertTrue(gc.is_tracked(set())) self.assertTrue(gc.is_tracked(UserClassSlots())) self.assertTrue(gc.is_tracked(UserFloatSlots())) self.assertTrue(gc.is_tracked(UserIntSlots())) def test_bug1055820b(self): # Corresponds to temp2b.py in the bug report. ouch = [] def callback(ignored): ouch[:] = [wr() for wr in WRs] Cs = [C1055820(i) for i in range(2)] WRs = [weakref.ref(c, callback) for c in Cs] c = None gc.collect() self.assertEqual(len(ouch), 0) # Make the two instances trash, and collect again. The bug was that # the callback materialized a strong reference to an instance, but gc # cleared the instance's dict anyway. Cs = None gc.collect() self.assertEqual(len(ouch), 2) # else the callbacks didn't run for x in ouch: # If the callback resurrected one of these guys, the instance # would be damaged, with an empty __dict__. self.assertEqual(x, None) def test_bug21435(self): # This is a poor test - its only virtue is that it happened to # segfault on Tim's Windows box before the patch for 21435 was # applied. That's a nasty bug relying on specific pieces of cyclic # trash appearing in exactly the right order in finalize_garbage()'s # input list. # But there's no reliable way to force that order from Python code, # so over time chances are good this test won't really be testing much # of anything anymore. Still, if it blows up, there's _some_ # problem ;-) gc.collect() class A: pass class B: def __init__(self, x): self.x = x def __del__(self): self.attr = None def do_work(): a = A() b = B(A()) a.attr = b b.attr = a do_work() gc.collect() # this blows up (bad C pointer) when it fails @cpython_only def test_garbage_at_shutdown(self): import subprocess code = """if 1: import gc import _testcapi @_testcapi.with_tp_del class X: def __init__(self, name): self.name = name def __repr__(self): return "<X %%r>" %% self.name def __tp_del__(self): pass x = X('first') x.x = x x.y = X('second') del x gc.set_debug(%s) """ def run_command(code): p = subprocess.Popen([sys.executable, "-Wd", "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() p.stdout.close() p.stderr.close() self.assertEqual(p.returncode, 0) self.assertEqual(stdout.strip(), b"") return strip_python_stderr(stderr) stderr = run_command(code % "0") self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at " b"shutdown; use", stderr) self.assertNotIn(b"<X 'first'>", stderr) # With DEBUG_UNCOLLECTABLE, the garbage list gets printed stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE") self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at " b"shutdown", stderr) self.assertTrue( (b"[<X 'first'>, <X 'second'>]" in stderr) or (b"[<X 'second'>, <X 'first'>]" in stderr), stderr) # With DEBUG_SAVEALL, no additional message should get printed # (because gc.garbage also contains normally reclaimable cyclic # references, and its elements get printed at runtime anyway). stderr = run_command(code % "gc.DEBUG_SAVEALL") self.assertNotIn(b"uncollectable objects at shutdown", stderr) @requires_type_collecting def test_gc_main_module_at_shutdown(self): # Create a reference cycle through the __main__ module and check # it gets collected at interpreter shutdown. code = """if 1: class C: def __del__(self): print('__del__ called') l = [C()] l.append(l) """ rc, out, err = assert_python_ok('-c', code) self.assertEqual(out.strip(), b'__del__ called') @requires_type_collecting def test_gc_ordinary_module_at_shutdown(self): # Same as above, but with a non-__main__ module. with temp_dir() as script_dir: module = """if 1: class C: def __del__(self): print('__del__ called') l = [C()] l.append(l) """ code = """if 1: import sys sys.path.insert(0, %r) import gctest """ % (script_dir,) make_script(script_dir, 'gctest', module) rc, out, err = assert_python_ok('-c', code) self.assertEqual(out.strip(), b'__del__ called') @requires_type_collecting def test_global_del_SystemExit(self): code = """if 1: class ClassWithDel: def __del__(self): print('__del__ called') a = ClassWithDel() a.link = a raise SystemExit(0)""" self.addCleanup(unlink, TESTFN) with open(TESTFN, 'w') as script: script.write(code) rc, out, err = assert_python_ok(TESTFN) self.assertEqual(out.strip(), b'__del__ called') def test_get_stats(self): stats = gc.get_stats() self.assertEqual(len(stats), 3) for st in stats: self.assertIsInstance(st, dict) self.assertEqual(set(st), {"collected", "collections", "uncollectable"}) self.assertGreaterEqual(st["collected"], 0) self.assertGreaterEqual(st["collections"], 0) self.assertGreaterEqual(st["uncollectable"], 0) # Check that collection counts are incremented correctly if gc.isenabled(): self.addCleanup(gc.enable) gc.disable() old = gc.get_stats() gc.collect(0) new = gc.get_stats() self.assertEqual(new[0]["collections"], old[0]["collections"] + 1) self.assertEqual(new[1]["collections"], old[1]["collections"]) self.assertEqual(new[2]["collections"], old[2]["collections"]) gc.collect(2) new = gc.get_stats() self.assertEqual(new[0]["collections"], old[0]["collections"] + 1) self.assertEqual(new[1]["collections"], old[1]["collections"]) self.assertEqual(new[2]["collections"], old[2]["collections"] + 1) def test_freeze(self): gc.freeze() self.assertGreater(gc.get_freeze_count(), 0) gc.unfreeze() self.assertEqual(gc.get_freeze_count(), 0) def test_get_objects(self): gc.collect() l = [] l.append(l) self.assertTrue( any(l is element for element in gc.get_objects(generation=0)) ) self.assertFalse( any(l is element for element in gc.get_objects(generation=1)) ) self.assertFalse( any(l is element for element in gc.get_objects(generation=2)) ) gc.collect(generation=0) self.assertFalse( any(l is element for element in gc.get_objects(generation=0)) ) self.assertTrue( any(l is element for element in gc.get_objects(generation=1)) ) self.assertFalse( any(l is element for element in gc.get_objects(generation=2)) ) gc.collect(generation=1) self.assertFalse( any(l is element for element in gc.get_objects(generation=0)) ) self.assertFalse( any(l is element for element in gc.get_objects(generation=1)) ) self.assertTrue( any(l is element for element in gc.get_objects(generation=2)) ) gc.collect(generation=2) self.assertFalse( any(l is element for element in gc.get_objects(generation=0)) ) self.assertFalse( any(l is element for element in gc.get_objects(generation=1)) ) self.assertTrue( any(l is element for element in gc.get_objects(generation=2)) ) del l gc.collect() def test_get_objects_arguments(self): gc.collect() self.assertEqual(len(gc.get_objects()), len(gc.get_objects(generation=None))) self.assertRaises(ValueError, gc.get_objects, 1000) self.assertRaises(ValueError, gc.get_objects, -1000) self.assertRaises(TypeError, gc.get_objects, "1") self.assertRaises(TypeError, gc.get_objects, 1.234) def test_38379(self): # When a finalizer resurrects objects, stats were reporting them as # having been collected. This affected both collect()'s return # value and the dicts returned by get_stats(). N = 100 class A: # simple self-loop def __init__(self): self.me = self class Z(A): # resurrecting __del__ def __del__(self): zs.append(self) zs = [] def getstats(): d = gc.get_stats()[-1] return d['collected'], d['uncollectable'] gc.collect() gc.disable() # No problems if just collecting A() instances. oldc, oldnc = getstats() for i in range(N): A() t = gc.collect() c, nc = getstats() self.assertEqual(t, 2*N) # instance object & its dict self.assertEqual(c - oldc, 2*N) self.assertEqual(nc - oldnc, 0) # But Z() is not actually collected. oldc, oldnc = c, nc Z() # Nothing is collected - Z() is merely resurrected. t = gc.collect() c, nc = getstats() #self.assertEqual(t, 2) # before self.assertEqual(t, 0) # after #self.assertEqual(c - oldc, 2) # before self.assertEqual(c - oldc, 0) # after self.assertEqual(nc - oldnc, 0) # Unfortunately, a Z() prevents _anything_ from being collected. # It should be possible to collect the A instances anyway, but # that will require non-trivial code changes. oldc, oldnc = c, nc for i in range(N): A() Z() # Z() prevents anything from being collected. t = gc.collect() c, nc = getstats() #self.assertEqual(t, 2*N + 2) # before self.assertEqual(t, 0) # after #self.assertEqual(c - oldc, 2*N + 2) # before self.assertEqual(c - oldc, 0) # after self.assertEqual(nc - oldnc, 0) # But the A() trash is reclaimed on the next run. oldc, oldnc = c, nc t = gc.collect() c, nc = getstats() self.assertEqual(t, 2*N) self.assertEqual(c - oldc, 2*N) self.assertEqual(nc - oldnc, 0) gc.enable() class GCCallbackTests(unittest.TestCase): def setUp(self): # Save gc state and disable it. self.enabled = gc.isenabled() gc.disable() self.debug = gc.get_debug() gc.set_debug(0) gc.callbacks.append(self.cb1) gc.callbacks.append(self.cb2) self.othergarbage = [] def tearDown(self): # Restore gc state del self.visit gc.callbacks.remove(self.cb1) gc.callbacks.remove(self.cb2) gc.set_debug(self.debug) if self.enabled: gc.enable() # destroy any uncollectables gc.collect() for obj in gc.garbage: if isinstance(obj, Uncollectable): obj.partner = None del gc.garbage[:] del self.othergarbage gc.collect() def preclean(self): # Remove all fluff from the system. Invoke this function # manually rather than through self.setUp() for maximum # safety. self.visit = [] gc.collect() garbage, gc.garbage[:] = gc.garbage[:], [] self.othergarbage.append(garbage) self.visit = [] def cb1(self, phase, info): self.visit.append((1, phase, dict(info))) def cb2(self, phase, info): self.visit.append((2, phase, dict(info))) if phase == "stop" and hasattr(self, "cleanup"): # Clean Uncollectable from garbage uc = [e for e in gc.garbage if isinstance(e, Uncollectable)] gc.garbage[:] = [e for e in gc.garbage if not isinstance(e, Uncollectable)] for e in uc: e.partner = None def test_collect(self): self.preclean() gc.collect() # Algorithmically verify the contents of self.visit # because it is long and tortuous. # Count the number of visits to each callback n = [v[0] for v in self.visit] n1 = [i for i in n if i == 1] n2 = [i for i in n if i == 2] self.assertEqual(n1, [1]*2) self.assertEqual(n2, [2]*2) # Count that we got the right number of start and stop callbacks. n = [v[1] for v in self.visit] n1 = [i for i in n if i == "start"] n2 = [i for i in n if i == "stop"] self.assertEqual(n1, ["start"]*2) self.assertEqual(n2, ["stop"]*2) # Check that we got the right info dict for all callbacks for v in self.visit: info = v[2] self.assertTrue("generation" in info) self.assertTrue("collected" in info) self.assertTrue("uncollectable" in info) def test_collect_generation(self): self.preclean() gc.collect(2) for v in self.visit: info = v[2] self.assertEqual(info["generation"], 2) @cpython_only def test_collect_garbage(self): self.preclean() # Each of these cause four objects to be garbage: Two # Uncollectables and their instance dicts. Uncollectable() Uncollectable() C1055820(666) gc.collect() for v in self.visit: if v[1] != "stop": continue info = v[2] self.assertEqual(info["collected"], 2) self.assertEqual(info["uncollectable"], 8) # We should now have the Uncollectables in gc.garbage self.assertEqual(len(gc.garbage), 4) for e in gc.garbage: self.assertIsInstance(e, Uncollectable) # Now, let our callback handle the Uncollectable instances self.cleanup=True self.visit = [] gc.garbage[:] = [] gc.collect() for v in self.visit: if v[1] != "stop": continue info = v[2] self.assertEqual(info["collected"], 0) self.assertEqual(info["uncollectable"], 4) # Uncollectables should be gone self.assertEqual(len(gc.garbage), 0) @unittest.skipIf(BUILD_WITH_NDEBUG, 'built with -NDEBUG') def test_refcount_errors(self): self.preclean() # Verify the "handling" of objects with broken refcounts # Skip the test if ctypes is not available import_module("ctypes") import subprocess code = textwrap.dedent(''' from test.support import gc_collect, SuppressCrashReport a = [1, 2, 3] b = [a] # Avoid coredump when Py_FatalError() calls abort() SuppressCrashReport().__enter__() # Simulate the refcount of "a" being too low (compared to the # references held on it by live data), but keeping it above zero # (to avoid deallocating it): import ctypes ctypes.pythonapi.Py_DecRef(ctypes.py_object(a)) # The garbage collector should now have a fatal error # when it reaches the broken object gc_collect() ''') p = subprocess.Popen([sys.executable, "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() p.stdout.close() p.stderr.close() # Verify that stderr has a useful error message: self.assertRegex(stderr, br'gcmodule\.c:[0-9]+: gc_decref: Assertion "gc_get_refs\(g\) > 0" failed.') self.assertRegex(stderr, br'refcount is too small') # "address : 0x7fb5062efc18" # "address : 7FB5062EFC18" address_regex = br'[0-9a-fA-Fx]+' self.assertRegex(stderr, br'object address : ' + address_regex) self.assertRegex(stderr, br'object refcount : 1') self.assertRegex(stderr, br'object type : ' + address_regex) self.assertRegex(stderr, br'object type name: list') self.assertRegex(stderr, br'object repr : \[1, 2, 3\]') class GCTogglingTests(unittest.TestCase): def setUp(self): gc.enable() def tearDown(self): gc.disable() def test_bug1055820c(self): # Corresponds to temp2c.py in the bug report. This is pretty # elaborate. c0 = C1055820(0) # Move c0 into generation 2. gc.collect() c1 = C1055820(1) c1.keep_c0_alive = c0 del c0.loop # now only c1 keeps c0 alive c2 = C1055820(2) c2wr = weakref.ref(c2) # no callback! ouch = [] def callback(ignored): ouch[:] = [c2wr()] # The callback gets associated with a wr on an object in generation 2. c0wr = weakref.ref(c0, callback) c0 = c1 = c2 = None # What we've set up: c0, c1, and c2 are all trash now. c0 is in # generation 2. The only thing keeping it alive is that c1 points to # it. c1 and c2 are in generation 0, and are in self-loops. There's a # global weakref to c2 (c2wr), but that weakref has no callback. # There's also a global weakref to c0 (c0wr), and that does have a # callback, and that callback references c2 via c2wr(). # # c0 has a wr with callback, which references c2wr # ^ # | # | Generation 2 above dots #. . . . . . . .|. . . . . . . . . . . . . . . . . . . . . . . . # | Generation 0 below dots # | # | # ^->c1 ^->c2 has a wr but no callback # | | | | # <--v <--v # # So this is the nightmare: when generation 0 gets collected, we see # that c2 has a callback-free weakref, and c1 doesn't even have a # weakref. Collecting generation 0 doesn't see c0 at all, and c0 is # the only object that has a weakref with a callback. gc clears c1 # and c2. Clearing c1 has the side effect of dropping the refcount on # c0 to 0, so c0 goes away (despite that it's in an older generation) # and c0's wr callback triggers. That in turn materializes a reference # to c2 via c2wr(), but c2 gets cleared anyway by gc. # We want to let gc happen "naturally", to preserve the distinction # between generations. junk = [] i = 0 detector = GC_Detector() while not detector.gc_happened: i += 1 if i > 10000: self.fail("gc didn't happen after 10000 iterations") self.assertEqual(len(ouch), 0) junk.append([]) # this will eventually trigger gc self.assertEqual(len(ouch), 1) # else the callback wasn't invoked for x in ouch: # If the callback resurrected c2, the instance would be damaged, # with an empty __dict__. self.assertEqual(x, None) def test_bug1055820d(self): # Corresponds to temp2d.py in the bug report. This is very much like # test_bug1055820c, but uses a __del__ method instead of a weakref # callback to sneak in a resurrection of cyclic trash. ouch = [] class D(C1055820): def __del__(self): ouch[:] = [c2wr()] d0 = D(0) # Move all the above into generation 2. gc.collect() c1 = C1055820(1) c1.keep_d0_alive = d0 del d0.loop # now only c1 keeps d0 alive c2 = C1055820(2) c2wr = weakref.ref(c2) # no callback! d0 = c1 = c2 = None # What we've set up: d0, c1, and c2 are all trash now. d0 is in # generation 2. The only thing keeping it alive is that c1 points to # it. c1 and c2 are in generation 0, and are in self-loops. There's # a global weakref to c2 (c2wr), but that weakref has no callback. # There are no other weakrefs. # # d0 has a __del__ method that references c2wr # ^ # | # | Generation 2 above dots #. . . . . . . .|. . . . . . . . . . . . . . . . . . . . . . . . # | Generation 0 below dots # | # | # ^->c1 ^->c2 has a wr but no callback # | | | | # <--v <--v # # So this is the nightmare: when generation 0 gets collected, we see # that c2 has a callback-free weakref, and c1 doesn't even have a # weakref. Collecting generation 0 doesn't see d0 at all. gc clears # c1 and c2. Clearing c1 has the side effect of dropping the refcount # on d0 to 0, so d0 goes away (despite that it's in an older # generation) and d0's __del__ triggers. That in turn materializes # a reference to c2 via c2wr(), but c2 gets cleared anyway by gc. # We want to let gc happen "naturally", to preserve the distinction # between generations. detector = GC_Detector() junk = [] i = 0 while not detector.gc_happened: i += 1 if i > 10000: self.fail("gc didn't happen after 10000 iterations") self.assertEqual(len(ouch), 0) junk.append([]) # this will eventually trigger gc self.assertEqual(len(ouch), 1) # else __del__ wasn't invoked for x in ouch: # If __del__ resurrected c2, the instance would be damaged, with an # empty __dict__. self.assertEqual(x, None) def test_main(): enabled = gc.isenabled() gc.disable() assert not gc.isenabled() debug = gc.get_debug() gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak try: gc.collect() # Delete 2nd generation garbage run_unittest(GCTests, GCTogglingTests, GCCallbackTests) finally: gc.set_debug(debug) # test gc.enable() even if GC is disabled by default if verbose: print("restoring automatic collection") # make sure to always test gc.enable() gc.enable() assert gc.isenabled() if not enabled: gc.disable() if __name__ == "__main__": test_main()
Upload File
Create Folder