Commit Graph

145 Commits

Author SHA1 Message Date
Miss Islington (bot) 1dc7fcd803
[3.13] gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (GH-119065) (GH-119087)
(cherry picked from commit 0152dc4ff5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-05-16 10:51:18 +03:00
Steve Dower 81939dad77
gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488) 2024-05-02 15:20:43 +01:00
Serhiy Storchaka b2923a61a1
gh-79325: Fix recursion error in TemporaryDirectory cleanup on Windows (GH-112762) 2023-12-07 17:21:36 +00:00
Søren Løvborg 81c16cd94e
gh-91133: tempfile.TemporaryDirectory: fix symlink bug in cleanup (GH-99930)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-12-07 18:04:06 +02:00
Ken Jin 8cdfee1bb9
bpo-43153: Don't mask `PermissionError` with `NotADirectoryError` during tempdirectory cleanup (GH-29940)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-12-05 15:30:59 +02:00
Victor Stinner cd2ef21b07
gh-108962: Skip test_tempfile.test_flags() if not supported (#108964)
Skip test_tempfile.test_flags() if chflags() fails with "OSError:
[Errno 45] Operation not supported" (ex: on FreeBSD 13).
2023-09-05 21:59:40 +00:00
Samuel Sloniker 32bea69b89
gh-51574: Make tempfile.mkdtemp() always return absolute paths (#94612)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-04-25 16:05:59 +00:00
JakobDev d9305f8e9d
Fix typos in test_tempfile.py (#102841) 2023-04-09 13:43:40 +05:30
JakobDev 64cb1a4f0f
gh-100131: Add optional delete parameter to tempfile.TemporaryDirectory() (#100132)
Add optional delete parameter to tempfile.TemporaryDirectory().

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-03-24 14:52:06 -07:00
Ev2geny 743453a554
gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile (GH-97015) 2022-10-04 23:37:33 +01:00
Serhiy Storchaka d4792ce916
gh-83499: Fix closing file descriptors in tempfile (GH-93874) 2022-06-26 10:58:28 +03:00
Christian Heimes 22fed605e0
gh-90473: Make chmod a dummy on WASI, skip chmod tests (GH-93534)
WASI does not have the ``chmod(2)`` syscall yet.
2022-06-06 19:24:11 +02:00
Serhiy Storchaka 086c6b1b0f
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase.
Add method enterAsyncContext() in IsolatedAsyncioTestCase.
Add function enterModuleContext().
2022-05-08 17:49:09 +03:00
Christian Heimes 49fda0cc51
gh-70363: Emscripten cannot fstat renamed spool file (GH-92354) 2022-05-06 01:10:37 +02:00
Carey Metcalfe 78e70be331
gh-70363: Implement `io.IOBase` interface for `SpooledTemporaryFile` (GH-29560)
Since the underlying file-like objects (either `io.BytesIO`,
or a true file object) all implement the `io.IOBase`
interface, the `SpooledTemporaryFile` should as well.

Additionally, since the underlying file object will either be an
instance of an `io.BufferedIOBase` (for binary mode) or an
`io.TextIOBase` (for text mode), methods for these classes were also
implemented.

In every case, the required methods and properties are simply delegated
to the underlying file object.

Co-authored-by: Gary Fernie <Gary.Fernie@skyscanner.net>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2022-05-03 21:18:18 +09:00
Christian Heimes ef1327e3b6
bpo-40280: Skip more tests on Emscripten (GH-31947)
- lchmod, lchown are not fully implemented
- skip umask tests
- cannot fstat unlinked or renamed files yet
- ignore musl libc issues that affect Emscripten
2022-03-17 12:09:57 +01:00
Christian Heimes 91e33ac3d0
bpo-40280: Add requires_fork test helper (GH-30622) 2022-01-16 22:52:43 +01:00
Kyungmin Lee 6270d3eeaf
bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323)
An object implementing the os.PathLike protocol can represent a file
system path as a str or bytes object.
Therefore, _infer_return_type function should infer os.PathLike[str]
object as str type and os.PathLike[bytes] object as bytes type.
2021-10-20 21:54:41 +02:00
Christian Clauss 745c9d9dfc
Fix typos in the Lib directory (GH-28775)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-10-06 16:13:48 -07:00
Serhiy Storchaka 2a8127cafe
bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005) 2021-08-29 14:04:40 +03:00
CAM Gerlach bd2fa3c416
bpo-29982: Add "ignore_cleanup_errors" param to tempfile.TemporaryDirectory() (GH-24793) 2021-03-14 11:06:56 -07:00
Eric L 9c7927400c
bpo-40701: tempfile mixes str and bytes in an inconsistent manner (GH-20442)
The case of tempfile.tempdir variable being bytes is now handled consistently.
The getters return the right type and no more error of mixing str and bytes unless explicitly caused by the user.

Adds a regression test.

Expands the documentation to clarify the behavior.

Co-authored-by: Eric L <ewl+git@lavar.de>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2021-03-03 12:36:22 -08:00
Inada Naoki d2810054c7
tempfile: Use random.choises() instead of choise() (GH-23068) 2020-11-01 20:02:03 +09:00
Inada Naoki 43ca084c88
Revert "bpo-42160: tempfile: Reduce overhead of pid check. (GH-22997)"
`_RandomNameSequence` is not true singleton so using `os.register_at_fork` doesn't make sense unlike `random._inst`.

This reverts commit 8e409cebad.
2020-10-31 11:15:38 +09:00
Eric W 8e409cebad
bpo-42160: tempfile: Reduce overhead of pid check. (GH-22997)
The _RandomSequence class in tempfile used to check the current pid every time its rng property was used.
This commit replaces this code with `os.register_at_fork` to reduce the overhead.
2020-10-30 13:56:28 +09:00
Hai Shi 0c4f0f3b29
bpo-40275: Use new test.support helper submodules in tests (GH-21169) 2020-06-30 15:46:31 +02:00
Victor Stinner 57572b103e
bpo-40443: Remove unused imports in tests (GH-19805) 2020-04-30 01:48:37 +02:00
Inada Naoki 485e715cb1
bpo-40287: Fix SpooledTemporaryFile.seek() return value (GH-19540)
It has not returned the file position after the seek.
2020-04-17 15:56:35 +09:00
Guido van Rossum 48b069a003
bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.

There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
2020-04-07 09:50:06 -07:00
Victor Stinner 278c1e159c
bpo-40094: Add test.support.wait_process() (GH-19254)
Moreover, the following tests now check the child process exit code:

* test_os.PtyTests
* test_mailbox.test_lock_conflict()
* test_tempfile.test_process_awareness()
* test_uuid.testIssue8621()
* multiprocessing resource tracker tests
2020-03-31 20:08:12 +02:00
Batuhan Taşkaya 09c482fad1 bpo-39019: Implement missing __class_getitem__ for SpooledTemporaryFile (GH-17560) 2019-12-30 16:08:08 +00:00
Inada Naoki ea9835c5d1
bpo-26730: Fix SpooledTemporaryFile data corruption (GH-17400)
SpooledTemporaryFile.rollback() might cause data corruption
when it is in text mode.

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
2019-11-27 22:22:06 +09:00
Anthony Sottile 370138ba9c bpo-35803: Document and test dir=PathLike for tempfile (GH-11644)
Co-Authored-By: Ammar Askar <ammar_askar@hotmail.com>
2019-09-09 10:54:34 -05:00
Serhiy Storchaka e9b51c0ad8
bpo-26660, bpo-35144: Fix permission errors in TemporaryDirectory cleanup. (GH-10320)
TemporaryDirectory.cleanup() failed when non-writeable or non-searchable
files or directories were created inside a temporary directory.
2019-05-31 11:30:37 +03:00
Serhiy Storchaka 5b10b98247
bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929) 2019-03-05 10:06:26 +02:00
Anthony Sottile 8377cd4fcd Clean up code which checked presence of os.{stat,lstat,chmod} (#11643) 2019-02-25 23:32:27 +01:00
sth 825aab95fd bpo-27300: Add the errors parameter to tempfile classes. (GH-6696) 2018-05-23 08:07:01 +03:00
Victor Stinner 6c8c2943d9 bpo-31160: test_tempfile: Fix reap_children() warning (#3056)
TestRandomNameSequence.test_process_awareness() now calls
os.waitpid() to avoid leaking a zombie process.
2017-08-10 13:05:06 +02:00
Serhiy Storchaka d1a1def7bf bpo-30197: Enhance functions swap_attr() and swap_item() in test.support. (#1341)
* bpo-30197: Enhance functions swap_attr() and swap_item() in test.support.

They now work when delete replaced attribute or item inside the with
statement.  The old value of the attribute or item (or None if it doesn't
exist) now will be assigned to the target of the "as" clause, if there is
one.

* Update docstrings.
2017-04-28 18:17:26 +02:00
Victor Stinner 1e62bf145b bpo-30030: Revert f50354ad (tempfile) (#1187)
Revert f50354adaaafebe95ad09d09b825804a686ea843: it introduced a
regression in test_threadedtempfile.
2017-04-19 22:59:51 +02:00
Serhiy Storchaka f50354adaa Reimplement tempfile._RandomNameSequence using a generator function. (#1075) 2017-04-11 22:45:59 +03:00
Martin Panter 7869a22779 Issue #26385: Cleanup NamedTemporaryFile if open() fails, by SilentGhost 2016-02-28 05:22:20 +00:00
Gregory P. Smith ad577b938b Issue 24230: The tempfile module now accepts bytes for prefix, suffix and dir
parameters and returns bytes in such situations (matching the os module APIs).
2015-05-22 16:18:14 -07:00
Serhiy Storchaka 492f027793 Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again
when a directory with the chosen name already exists on Windows as well as
on Unix.  tempfile.mkstemp() now fails early if parent directory is not
valid (not exists or is a file) on Windows.
2015-05-20 00:14:00 +03:00
Serhiy Storchaka 5d6b7b1cb7 Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again
when a directory with the chosen name already exists on Windows as well as
on Unix.  tempfile.mkstemp() now fails early if parent directory is not
valid (not exists or is a file) on Windows.
2015-05-20 00:11:48 +03:00
Berker Peksag ce643913a9 Issue #9517: Move script_helper to the support package.
Patch by Christie Wilson.
2015-05-06 06:33:17 +03:00
Zachary Ware 38c707e7e0 Issue #21741: Update 147 test modules to use test discovery.
I have compared output between pre- and post-patch runs of these tests
to make sure there's nothing missing and nothing broken, on both
Windows and Linux.  The only differences I found were actually tests
that were previously *not* run.
2015-04-13 15:00:43 -05:00
Serhiy Storchaka 56cefa69ee Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to
NamedTemporaryFile instance.  Patch by Bohuslav Kabrda.
2015-03-19 15:23:15 +02:00
Serhiy Storchaka 5e193ac0bd Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
2014-09-24 13:26:25 +03:00
Victor Stinner c61c170b41 Issue #18174: Fix leak of file descriptor in test_tempfile 2014-07-29 01:13:39 +02:00