summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
Commit message (Collapse)AuthorAgeFilesLines
* [3.8] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96503)Gregory P. Smith2022-09-051-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Correctly pre-check for int-to-str conversion Converting a large enough `int` to a decimal string raises `ValueError` as expected. However, the raise comes _after_ the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. Oops! =) The quick fix: essentially we catch _most_ values that exceed the threshold up front. Those that slip through will still be on the small side (read: sufficiently fast), and will get caught by the existing check so that the limit remains exact. The justification for the current check. The C code check is: ```c max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10 ``` In GitHub markdown math-speak, writing $M$ for `max_str_digits`, $L$ for `PyLong_SHIFT` and $s$ for `size_a`, that check is: $$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$ From this it follows that $$\frac{M}{3L} < \frac{s-1}{10}$$ hence that $$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$ So $$2^{L(s-1)} > 10^M.$$ But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything _below_ the intended limit in the check. <!-- gh-issue-number: gh-95778 --> * Issue: gh-95778 <!-- /gh-issue-number --> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org> Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* [3.8] bpo-41043: Escape literal part of the path for glob(). (GH-20994). ↵Serhiy Storchaka2020-07-021-1/+1
| | | | | (GH-21277) (cherry picked from commit 935586845815f5b4c7814794413f6a812d4bd45f)
* [3.8] bpo-41009: fix requires_OS_version() class decorator (GH-20942) (GH-20948)Christian Heimes2020-06-251-19/+19
| | | | | | | | Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: @tiran. (cherry picked from commit bb6ec14479f18c32e71e43f2785f177aa17aabbd) Co-authored-by: Christian Heimes <christian@python.org>
* bpo-38377: Fix skip_if_broken_multiprocessing_synchronize() on macOS (GH-20984)Miss Islington (bot)2020-06-191-8/+9
| | | | | | | | skip_if_broken_multiprocessing_synchronize() only attempts for create a semaphore on Linux to fix multiprocessing test_resource_tracker_reused() on macOS. (cherry picked from commit 3358da4054b9b0b045eb47dc74dee3d58bfbb1d5) Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-38377: Add support.skip_if_broken_multiprocessing_synchronize() ↵Victor Stinner2020-06-181-0/+23
| | | | | | | | | | | (GH-20944) (GH-20962) (GH-20966) On Linux, skip tests using multiprocessing if the current user cannot create a file in /dev/shm/ directory. Add the skip_if_broken_multiprocessing_synchronize() function to the test.support module. (cherry picked from commit ddbeb2f3e02a510c5784ffd74c5e09e8c70b5881) (cherry picked from commit b1e736113484c99acb57e4acb417b91a9e58e7ff)
* bpo-41003: Fix test_copyreg when numpy is installed (GH-20935) (GH-20945) ↵Victor Stinner2020-06-171-0/+9
| | | | | | | | | | | | | (GH-20946) Fix test_copyreg when numpy is installed: test.pickletester now saves/restores warnings.filters when importing numpy, to ignore filters installed by numpy. Add the save_restore_warnings_filters() function to the test.support.warnings_helper module. (cherry picked from commit 8362893e3fe083df2ec8bb94c28b1a78383eadbf) (cherry picked from commit b39d41ba1b77f7bc51c4d6f6d0e336693192cb3a)
* bpo-40826: Fix test_repl.test_close_stdin() on Windows (GH-20779) (GH-20785) ↵Victor Stinner2020-06-101-16/+34
| | | | | | | | | | | | | | | | (GH-20787) test_repl.test_close_stdin() now calls support.suppress_msvcrt_asserts() to fix the test on Windows. * Move suppress_msvcrt_asserts() from test.libregrtest.setup to test.support. Make its verbose parameter optional: verbose=False by default. * SuppressCrashReport now uses SetErrorMode() of the msvcrt module, rather than using ctypes. * Remove also an unused variable (deadline) in wait_process(). (cherry picked from commit f6e58aefde2e57e4cb11ea7743955da53a3f1e80) (cherry picked from commit 4a4f660cfde8b683634c53e6214a6baa51de43b1)
* bpo-39983: Add test.support.print_warning() (GH-19683) (GH-19687)Victor Stinner2020-04-231-9/+12
| | | | | | | | | Log "Warning -- ..." test warnings into sys.__stderr__ rather than sys.stderr, to ensure to display them even if sys.stderr is captured. test.libregrtest.utils.print_warning() now calls test.support.print_warning(). (cherry picked from commit d663d34685e18588748569468c672763f4c73b3e)
* [3.8] Update libregrtest from master (GH-19516)Victor Stinner2020-04-141-12/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * bpo-37531: regrtest now catchs ProcessLookupError (GH-16827) Fix a warning on a race condition on TestWorkerProcess.kill(): ignore silently ProcessLookupError rather than logging an useless warning. (cherry picked from commit a661392f8fb5ac4fc095aa1845d1eb7a25c4e9be) * bpo-38502: regrtest uses process groups if available (GH-16829) test.regrtest now uses process groups in the multiprocessing mode (-jN command line option) if process groups are available: if os.setsid() and os.killpg() functions are available. (cherry picked from commit ecb035cd14c11521276343397151929a94018a22) * bpo-37957: Allow regrtest to receive a file with test (and subtests) to ignore (GH-16989) When building Python in some uncommon platforms there are some known tests that will fail. Right now, the test suite has the ability to ignore entire tests using the -x option and to receive a filter file using the --matchfile filter. The problem with the --matchfile option is that it receives a file with patterns to accept and when you want to ignore a couple of tests and subtests, is too cumbersome to lists ALL tests that are not the ones that you want to accept and he problem with -x is that is not easy to ignore just a subtests that fail and the whole test needs to be ignored. For these reasons, add a new option to allow to ignore a list of test and subtests for these situations. (cherry picked from commit e0cd8aa70a3ce19c3d3712568940aa0cbd9aa97b) * regrtest: log timeout at startup (GH-19514) Reduce also worker timeout. (cherry picked from commit 4cf65a630a8d45bad3fe5cdc4c2632ec64e7ba27) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38453: Resolve test directories before chdir to them (GH-16723)Miss Islington (bot)2019-10-141-1/+1
| | | | | (cherry picked from commit d83fc2702951f56a7339aa95d62414ed6e0fb40d) Co-authored-by: Steve Dower <steve.dower@python.org>
* [3.8] bpo-38270: More fixes for strict crypto policy (GH-16418) (#16437)Christian Heimes2019-09-301-4/+16
| | | | | | | | | | | | | | | | test_hmac and test_hashlib test built-in hashing implementations and OpenSSL-based hashing implementations. Add more checks to skip OpenSSL implementations when a strict crypto policy is active. Use EVP_DigestInit_ex() instead of EVP_DigestInit() to initialize the EVP context. The EVP_DigestInit() function clears alls flags and breaks usedforsecurity flag again. Signed-off-by: Christian Heimes <christian@python.org> https://bugs.python.org/issue38270. (cherry picked from commit 90558158093c0ad893102158fd3c2dd9f864e82e) Co-authored-by: Christian Heimes <christian@python.org>
* [3.8] bpo-38270: Check for hash digest algorithms and avoid MD5 (GH-16382) ↵Miss Islington (bot)2019-09-251-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | (GH-16393) Make it easier to run and test Python on systems with restrict crypto policies: * add requires_hashdigest to test.support to check if a hash digest algorithm is available and working * avoid MD5 in test_hmac * replace MD5 with SHA256 in test_tarfile * mark network tests that require MD5 for MD5-based digest auth or CRAM-MD5 https://bugs.python.org/issue38270 (cherry picked from commit c64a1a61e6fc542cada40eb069a239317e1af36e) Co-authored-by: Christian Heimes <christian@python.org> https://bugs.python.org/issue38270 Automerge-Triggered-By: @tiran
* bpo-37583: Add err 113 to support.get_socket_conn_refused_errs() (GH-14729)Miss Islington (bot)2019-08-131-0/+3
| | | | | | | Add error number 113 EHOSTUNREACH to get_socket_conn_refused_errs() of test.support. (cherry picked from commit 1ac2a83f30312976502fda042db5ce18d10ceec2) Co-authored-by: Hai Shi <shihai1992@gmail.com>
* bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. ↵Miss Islington (bot)2019-08-041-0/+36
| | | | | | | | | | | (GH-14996) There was a discrepancy between the Python and C implementations. Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support to test mixed type comparison. (cherry picked from commit 17e52649c0e7e9389f1cc2444a53f059e24e6bca) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-37707: Exclude expensive unit tests from PGO task (GH-15009) (#15024)Miss Islington (bot)2019-07-301-0/+10
| | | | | | | | Mark some individual tests to skip when --pgo is used. The tests marked increase the PGO task time significantly and likely don't help improve optimization of the final executable. (cherry picked from commit 52a48e62c6a94577152f9301bbe5f3bc806cfcf1) Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
* [3.8] Fix typos in docs, comments and test assert messages (GH-14872). (#14900)Kyle Stanley2019-07-221-1/+1
| | | | | (cherry picked from commit 96e12d5f4f3c5a20986566038ee763dff3c228a1) Co-authored-by: Min ho Kim <minho42@gmail.com>
* bpo-37552: Skip failing tests in strptime/strftime with UCRT version ↵Miss Islington (bot)2019-07-181-1/+23
| | | | | | | | 17763.615 (GH-14460) A bug in MSVC UCRT version 17763.615 (which has been fixed in newer versions) is causing test failures in some strptime/strftime tests when the default code page is c65001. This change selectively skips the tests affected by this. (cherry picked from commit 9cd39b16e2655f748f7aa8d20bca4812da00ba70) Co-authored-by: Paul Monson <paulmon@users.noreply.github.com>
* bpo-37526: Add support.catch_threading_exception() (GH-14664) (GH-14666)Miss Islington (bot)2019-07-091-0/+57
| | | | | | | Context manager catching threading.Thread exception using threading.excepthook. (cherry picked from commit 91b4f7ab7f9a5e0908b91379ee085ae087a76483) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* Remove unused imports in tests (GH-14518) (GH-14520)Victor Stinner2019-07-011-2/+0
| | | (cherry picked from commit 8f4ef3b019ce380022018587571b0f970e668de3)
* bpo-37199: Fix test failures when IPv6 is unavailable or disabled (GH-14480)Miss Islington (bot)2019-06-301-0/+2
| | | | | (cherry picked from commit c2cda638d63b98f5cf9a8ef13e15aace2b7e3f0b) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-37369: Fix initialization of sys members when launched via an app ↵Steve Dower2019-06-291-0/+79
| | | | | | container (GH-14467) sys._base_executable is now always defined on all platforms, and can be overridden through configuration. Also adds test.support.PythonSymlink to encapsulate platform-specific logic for symlinking sys.executable
* bpo-37261: Document sys.unraisablehook corner cases (GH-14059)Miss Islington (bot)2019-06-141-12/+3
| | | | | | | | | | | | | | Document reference cycle and resurrected objects issues in sys.unraisablehook() and threading.excepthook() documentation. Fix test.support.catch_unraisable_exception(): __exit__() no longer ignores unraisable exceptions. Fix test_io test_writer_close_error_on_close(): use a second catch_unraisable_exception() to catch the BufferedWriter unraisable exception. (cherry picked from commit 212646cae6b7c4ddc8d98c8b9b6d39a5f259e864) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* bpo-37261: Fix support.catch_unraisable_exception() (GH-14052)Miss Islington (bot)2019-06-131-2/+20
| | | | | | | | The __exit__() method of test.support.catch_unraisable_exception context manager now ignores unraisable exception raised when clearing self.unraisable attribute. (cherry picked from commit 6d22cc8e90ccb1e1965b1a4bc79456e2cc1e5a3e) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)Serhiy Storchaka2019-06-011-1/+1
|
* bpo-36829: Document test.support.catch_unraisable_exception() (GH-13554)Victor Stinner2019-05-241-3/+5
| | | | catch_unraisable_exception() now also removes its 'unraisable' attribute at the context manager exit.
* bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490)Victor Stinner2019-05-221-0/+33
| | | | | | * Copy test_exceptions.test_unraisable() to test_sys.UnraisableHookTest(). * Use catch_unraisable_exception() in test_coroutines, test_exceptions, test_generators.
* bpo-36766: Typos in docs and code comments (GH-13116)penguindustin2019-05-061-1/+1
|
* bpo-36465: Make release and debug ABI compatible (GH-12615)Victor Stinner2019-04-241-1/+1
| | | | | | | | | | | | | | Release build and debug build are now ABI compatible: the Py_DEBUG define no longer implies Py_TRACE_REFS define which introduces the only ABI incompatibility. A new "./configure --with-trace-refs" build option is now required to get Py_TRACE_REFS define which adds sys.getobjects() function and PYTHONDUMPREFS environment variable. Changes: * Add ./configure --with-trace-refs * Py_DEBUG no longer implies Py_TRACE_REFS
* bpo-36629: Add support.get_socket_conn_refused_errs() (GH-12834)Victor Stinner2019-04-151-0/+16
| | | | Fix test_imap4_host_default_value() of test_imaplib: catch also errno.ENETUNREACH error.
* bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929)Serhiy Storchaka2019-03-052-35/+30
|
* bpo-36019: Use pythontest.net instead of example.com in network tests (GH-11941)Stéphane Wirtel2019-02-221-0/+4
|
* bpo-35798: Add test.support.check_syntax_warning(). (#11895)Serhiy Storchaka2019-02-191-0/+29
| | | | | | | It checks that a SyntaxWarning is raised when compile specified statement, that it is raised only once, that it is converted to a SyntaxError when raised as exception, and that both warning and exception objects have corresponding attributes.
* Rework tuple hash tests. (GH-10161)Tim Peters2019-02-081-0/+41
| | | Add tooling that will useful in future updates, paying particular attention to difficult cases where only the upper bits on the input vary.
* bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)Dong-hee Na2019-01-171-2/+2
| | | Add a deprecated warning for the threading.Thread.isAlive() method.
* bpo-34897: avoid distutils test error when CXX is not set (GH-9706)Michael Felt2018-12-261-1/+1
| | | | | | Depending on system config, a missing candidate compiler name may be reported as the empty string rather than as None, so adjust the test helper accordingly.
* bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200)Victor Stinner2018-12-171-1/+1
| | | | | Rename test.bisect module to test.bisect_cmd to avoid conflict with bisect module when running directly a test like "./python Lib/test/test_xmlrpc.py".
* bpo-35513: Replace time.time() with time.monotonic() in tests (GH-11182)Victor Stinner2018-12-171-2/+2
| | | | | | | Replace time.time() with time.monotonic() in tests to measure time delta. test_zipfile64: display progress every minute (60 secs) rather than every 5 minutes (5*60 seconds).
* bpo-34279: regrtest consider that skipped tests are ran (GH-11132)Victor Stinner2018-12-141-1/+1
| | | | | | bpo-34279, bpo-35412: support.run_unittest() no longer raises TestDidNotRun if a test result contains skipped tests. The exception is now only raised if no test have been run and no test have been skipped.
* bpo-33709: test_ntpath and test_posixpath fail in Windows with ACP!=1252. ↵native-api2018-12-061-1/+5
| | | | (GH-7278)
* bpo-34279, regrtest: Issue a warning if no tests have been executed (GH-10150)Pablo Galindo2018-11-291-1/+6
|
* bpo-34945: Buffer output in test suite only when creating junit file (GH-10204)Pablo Galindo2018-10-292-14/+16
| | | | | | | | | | | After commit d0f49d2f5085ca68e3dc8725f1fb1c9674bfb5ed, the output of the test suite is always buffered as the test output needs to be included in the JUnit file in same cases (as when a test fails). This has the consequence that printing or using debuggers (like pdb) in the test suite does not result in a good user experience anymore. This commit modifies the test suite runner so it only captures the test output when the JUnit file is requested to fix the regression so prints and debuggers are usable again.
* bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842)Alexey Izbyshev2018-10-201-5/+27
| | | | | | | | | If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1.
* bpo-19756: Prevent test failures due to EADDRNOTAVAIL (GH-9446)Berker Peksag2018-09-201-0/+3
|
* bpo-34582: Adds JUnit XML output for regression tests (GH-9210)Steve Dower2018-09-182-5/+214
|
* Lib/test/support: fix typo in docstring (GH-8506)Daniel Hahler2018-09-111-2/+2
|
* bpo-9372: Deprecate several __getitem__ methods (GH-8609)Berker Peksag2018-08-111-0/+17
| | | | | | The __getitem__ methods of DOMEventStream, FileInput, and FileWrapper classes ignore their 'index' parameters and return the next item instead.
* Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" (GH-7919)Victor Stinner2018-06-261-33/+20
| | | This reverts commit 8fbbdf0c3107c3052659e166f73990b466eacbb0.
* bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)Victor Stinner2018-06-221-20/+33
| | | | | | | | * Add support.MS_WINDOWS: True if Python is running on Microsoft Windows. * Add support.MACOS: True if Python is running on Apple macOS. * Replace support.is_android with support.ANDROID * Replace support.is_jython with support.JYTHON * Cleanup code to initialize unix_shell
* bpo-33773: Fix test.support.fd_count() on Linux/FreBSD (GH-7421)Victor Stinner2018-06-061-8/+10
| | | | | | | | | Substract one because listdir() opens internally a file descriptor to list the content of the /proc/self/fd/ directory. Add test_support.test_fd_count(). Move also MAXFD code before msvcrt.CrtSetReportMode(), to make sure that the report mode is always restored on failure.
* test.support.SaveSignals: fix typo (GH-7448)Victor Stinner2018-06-061-1/+1
| | | an => and