summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." ↵Miss Islington (bot)2023-07-261-0/+12
| | | | | | | | | | | (GH-107014) (#107315) gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." (GH-107014) It makes sense to raise an Error because ".." can not be resolved and the current working directory is unknown. (cherry picked from commit e7e6e4b035f51ab4a962b45a957254859f264f4f) Co-authored-by: János Kukovecz <kukoveczjanos@gmail.com>
* [3.12] GH-106330: Fix matching of empty path in `pathlib.PurePath.match()` ↵Barney Gale2023-07-041-0/+4
| | | | | | | | (GH-106331) (GH-106372) We match paths using the `_lines` attribute, which is derived from the path's string representation. The bug arises because an empty path's string representation is `'.'` (not `''`), which is matched by the `'*'` wildcard. (cherry picked from commit b4efdf8cda8fbbd0ca53b457d5f6e46a59348caf)
* [3.12] gh-102613: Bump recursion limit to fix running test_pathlib under ↵Miss Islington (bot)2023-06-131-1/+1
| | | | | | | | Coverage (GH-105744) (#105749) gh-102613: Bump recursion limit to fix running test_pathlib under Coverage (GH-105744) (cherry picked from commit 4e80082723b768df124f77d2b73b3ba6b584a735) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* [3.12] GH-103631: Fix `PurePosixPath(PureWindowsPath(...))` separator ↵Miss Islington (bot)2023-05-261-0/+6
| | | | | | | | | | | | handling (GH-104949) (GH-104991) For backwards compatibility, accept backslashes as path separators in `PurePosixPath` if an instance of `PureWindowsPath` is supplied. This restores behaviour from Python 3.11. (cherry picked from commit 328422ce6162eb18735a2c0de12f8a696be97d0c) Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* [3.12] GH-104947: Make pathlib.PureWindowsPath comparisons consistent across ↵Miss Islington (bot)2023-05-261-0/+1
| | | | | | | | | | | platforms (GH-104948) (GH-104990) Use `str.lower()` rather than `ntpath.normcase()` to normalize case of Windows paths. This restores behaviour from Python 3.11. (cherry picked from commit ad0be361c9922a918c7c3eaf83e1d8f2b019279c) Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* GH-104484: Add case_sensitive argument to `pathlib.PurePath.match()` (GH-104565)thirumurugan2023-05-181-1/+6
| | | Co-authored-by: Barney Gale <barney.gale@gmail.com>
* GH-102613: Fix recursion error from `pathlib.Path.glob()` (GH-104373)Barney Gale2023-05-151-0/+11
| | | | Use `Path.walk()` to implement the recursive wildcard `**`. This method uses an iterative (rather than recursive) walk - see GH-100282.
* GH-90208: Suppress OSError exceptions from `pathlib.Path.glob()` (GH-104141)Barney Gale2023-05-111-26/+12
| | | | | | | | | | | `pathlib.Path.glob()` now suppresses all OSError exceptions, except those raised from calling `is_dir()` on the top-level path. Previously, `glob()` suppressed ENOENT, ENOTDIR, EBADF and ELOOP errors and their Windows equivalents. PermissionError was also suppressed unless it occurred when calling `is_dir()` on the top-level path. However, the selector would abort prematurely if a PermissionError was raised, and so `glob()` could return incomplete results.
* GH-87695: Fix OSError from `pathlib.Path.glob()` (GH-104292)Barney Gale2023-05-101-0/+9
| | | | Fix issue where `pathlib.Path.glob()` raised `OSError` when it encountered a symlink to an overly long path.
* GH-102613: Improve performance of `pathlib.Path.rglob()` (GH-104244)Barney Gale2023-05-071-1/+5
| | | | | | | | | | Stop de-duplicating results in `_RecursiveWildcardSelector`. A new `_DoubleRecursiveWildcardSelector` class is introduced which performs de-duplication, but this is used _only_ for patterns with multiple non-adjacent `**` segments, such as `path.glob('**/foo/**')`. By avoiding the use of a set, `PurePath.__hash__()` is not called, and so paths do not need to be stringified and case-normalised. Also merge adjacent '**' segments in patterns.
* GH-100479: Fix pathlib test failure on WASI (#104215)Barney Gale2023-05-071-1/+2
|
* GH-100479: Add `pathlib.PurePath.with_segments()` (GH-103975)Barney Gale2023-05-051-15/+37
| | | | | Add `pathlib.PurePath.with_segments()`, which creates a path object from arguments. This method is called whenever a derivative path is created, such as from `pathlib.PurePath.parent`. Subclasses may override this method to share information between path objects. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* GH-81079: Add case_sensitive argument to `pathlib.Path.glob()` (GH-102710)Barney Gale2023-05-041-0/+12
| | | | | | This argument allows case-sensitive matching to be enabled on Windows, and case-insensitive matching to be enabled on Posix. Co-authored-by: Steve Dower <steve.dower@microsoft.com>
* GH-104114: Fix `pathlib.WindowsPath.glob()` use of literal pattern segment ↵Barney Gale2023-05-031-2/+2
| | | | | | | | | case (GH-104116) We now use `_WildcardSelector` to evaluate literal pattern segments, which allows us to retrieve the real filesystem case. This change is necessary in order to implement a *case_sensitive* argument (see GH-81079) and a *follow_symlinks* argument (see GH-77609).
* GH-89769: `pathlib.Path.glob()`: do not follow symlinks when checking for ↵andrei kulakov2023-05-031-0/+4
| | | | | precise match (GH-29655) Co-authored-by: Barney Gale <barney.gale@gmail.com>
* GH-104102: Optimize `pathlib.Path.glob()` handling of `../` pattern segments ↵Barney Gale2023-05-021-0/+5
| | | | | | | | (GH-104103) These segments do not require a `stat()` call, as the selector's `_select_from()` method is called after we've established that the parent is a directory.
* GH-103525: Improve exception message from `pathlib.PurePath()` (GH-103526)Barney Gale2023-05-021-2/+2
| | | | | | | | Check that arguments are strings before calling `os.path.join()`. Also improve performance of `PurePath(PurePath(...))` while we're in the area: we now use the *unnormalized* string path of such arguments. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* GH-103517: Improve tests for `pathlib.Path.walk()` (GH-103518)Barney Gale2023-04-151-32/+45
|
* GH-78079: Fix UNC device path root normalization in pathlib (GH-102003)Barney Gale2023-04-141-0/+24
| | | | | | | We no longer add a root to device paths such as `//./PhysicalDrive0`, `//?/BootPartition` and `//./c:` while normalizing. We also avoid adding a root to incomplete UNC share paths, like `//`, `//a` and `//a/`. Co-authored-by: Eryk Sun <eryksun@gmail.com>
* GH-101362: Omit path anchor from `pathlib.PurePath()._parts` (GH-102476)Barney Gale2023-04-091-2/+0
| | | Improve performance of path construction by skipping the addition of the path anchor (`drive + root`) to the internal `_parts` list. Rename this attribute to `_tail` for clarity.
* GH-103379: Fix up old tests for `pathlib.PurePath._parse_path` (GH-103380)Barney Gale2023-04-091-110/+97
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* GH-76846, GH-85281: Call `__new__()` and `__init__()` on pathlib subclasses ↵Barney Gale2023-04-031-1/+26
| | | | | | | | | (GH-102789) Fix an issue where `__new__()` and `__init__()` were not called on subclasses of `pathlib.PurePath` and `Path` in some circumstances. Paths are now normalized on-demand. This speeds up path construction, `p.joinpath(q)`, and `p / q`. Co-authored-by: Steve Dower <steve.dower@microsoft.com>
* GH-89727: Fix pathlib.Path.walk RecursionError on deep trees (GH-100282)Stanislav Zmiev2023-03-221-0/+13
| | | | | | Use a stack to implement `pathlib.Path.walk()` iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees. Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Brett Cannon <brett@python.org>
* GH-80486: Fix handling of NTFS alternate data streams in pathlib (GH-102454)Barney Gale2023-03-101-1/+27
| | | Co-authored-by: Maor Kleinberger <kmaork@gmail.com>
* Remove or update bitbucket links (GH-101963)sblondon2023-03-081-1/+1
| | | | | | Since Mercurial removal from bitbucket.org, some links are broken. They are replaced by github.com or webarchive.org links if available. Otherwise, they are removed. Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* GH-101362: Optimise PurePath(PurePath(...)) (GH-101667)Barney Gale2023-03-051-0/+27
| | | | | | | The previous `_parse_args()` method pulled the `_parts` out of any supplied `PurePath` objects; these were subsequently joined in `_from_parts()` using `os.path.join()`. This is actually a slower form of joining than calling `fspath()` on the path object, because it doesn't take advantage of the fact that the contents of `_parts` is normalized! This reduces the time taken to run `PurePath("foo", "bar")` by ~20%, and the time taken to run `PurePath(p, "cheese")`, where `p = PurePath("/foo", "bar", "baz")`, by ~40%. Automerge-Triggered-By: GH:AlexWaygood
* gh-100809: Fix handling of drive-relative paths in pathlib.Path.absolute() ↵Barney Gale2023-02-171-0/+20
| | | | | (GH-100812) Resolving the drive independently uses the OS API, which ensures it starts from the current directory on that drive.
* gh-101360: Fix anchor matching in pathlib.PureWindowsPath.match() (GH-101363)Barney Gale2023-02-171-3/+6
| | | | Use `fnmatch` to match path and pattern anchors, just as we do for other path parts. This allows patterns such as `'*:/Users/*'` to be matched.
* gh-101000: Add os.path.splitroot() (#101002)Barney Gale2023-01-271-37/+0
| | | | Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632)Yurii Karabas2023-01-141-0/+5
| | | | | Fix a bug where `Path` takes and ignores `**kwargs` by adding to `PurePath` class `__init__` method which can take only positional arguments. Automerge-Triggered-By: GH:brettcannon
* gh-68320, gh-88302 - Allow for private `pathlib.Path` subclassing (GH-31691)Barney Gale2022-12-231-30/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | Users may wish to define subclasses of `pathlib.Path` to add or modify existing methods. Before this change, attempting to instantiate a subclass raised an exception like: AttributeError: type object 'PPath' has no attribute '_flavour' Previously the `_flavour` attribute was assigned as follows: PurePath._flavour = xxx not set!! xxx PurePosixPath._flavour = _PosixFlavour() PureWindowsPath._flavour = _WindowsFlavour() This change replaces it with a `_pathmod` attribute, set as follows: PurePath._pathmod = os.path PurePosixPath._pathmod = posixpath PureWindowsPath._pathmod = ntpath Functionality from `_PosixFlavour` and `_WindowsFlavour` is moved into `PurePath` as underscored-prefixed classmethods. Flavours are removed. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Brett Cannon <brett@python.org> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Eryk Sun <eryksun@gmail.com>
* gh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` ↵Barney Gale2022-12-171-3/+5
| | | | | | | (GH-94469) This brings `relative_to()` and `is_relative_to()` more in line with other pathlib methods like `rename()` and `symlink_to()`. Resolves #78707.
* gh-99029: Fix handling of `PureWindowsPath('C:\<blah>').relative_to('C:')` ↵Barney Gale2022-11-251-9/+5
| | | | | | | (GH-99031) `relative_to()` now treats naked drive paths as relative. This brings its behaviour in line with other parts of pathlib, and with `ntpath.relpath()`, and so allows us to factor out the pathlib-specific implementation.
* gh-99547: Add isjunction methods for checking if a path is a junction (GH-99548)Charles Machalow2022-11-221-0/+7
|
* gh-84538: add strict argument to pathlib.PurePath.relative_to (GH-19813)domragusa2022-10-281-0/+82
| | | | | | | | | | | | | | | | | | | | | | | By default, :meth:`pathlib.PurePath.relative_to` doesn't deal with paths that are not a direct prefix of the other, raising an exception in that instance. This change adds a *walk_up* parameter that can be set to allow for using ``..`` to calculate the relative path. example: ``` >>> p = PurePosixPath('/etc/passwd') >>> p.relative_to('/etc') PurePosixPath('passwd') >>> p.relative_to('/usr') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pathlib.py", line 940, in relative_to raise ValueError(error_message.format(str(self), str(formatted))) ValueError: '/etc/passwd' does not start with '/usr' >>> p.relative_to('/usr', strict=False) PurePosixPath('../etc/passwd') ``` https://bugs.python.org/issue40358 Automerge-Triggered-By: GH:brettcannon
* gh-94909: fix joining of absolute and relative Windows paths in pathlib ↵Barney Gale2022-08-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | (GH-95450) Have pathlib use `os.path.join()` to join arguments to the `PurePath` initialiser, which fixes a minor bug when handling relative paths with drives. Previously: ```python >>> from pathlib import PureWindowsPath >>> a = 'C:/a/b' >>> b = 'C:x/y' >>> PureWindowsPath(a, b) PureWindowsPath('C:x/y') ``` Now: ```python >>> PureWindowsPath(a, b) PureWindowsPath('C:/a/b/x/y') ```
* gh-86943: implement `pathlib.WindowsPath.is_mount()` (GH-31458)Barney Gale2022-08-051-4/+5
| | | | | | Have `pathlib.WindowsPath.is_mount()` call `ntpath.ismount()`. Previously it raised `NotImplementedError` unconditionally. https://bugs.python.org/issue42777
* gh-90385: Add skip_unless_symlink decorator to test_walk_symlink_location ↵Christian Heimes2022-07-231-0/+1
| | | | (GH-95182)
* gh-90385: Add `pathlib.Path.walk()` method (GH-92517)Stanislav Zmiev2022-07-221-0/+197
| | | Automerge-Triggered-By: GH:brettcannon
* gh-90473: Make chmod a dummy on WASI, skip chmod tests (GH-93534)Christian Heimes2022-06-061-0/+3
| | | WASI does not have the ``chmod(2)`` syscall yet.
* gh-93156 - fix negative indexing into absolute `pathlib.PurePath().parents` ↵Barney Gale2022-06-031-0/+5
| | | | | | | | | | | (GH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices.
* gh-90473: Skip and document more failing tests on WASI (GH-93436)Christian Heimes2022-06-021-0/+3
| | | | | | | - Mark more ``umask()`` cases - ``dup()`` is not supported - ``/dev/null`` is not available - document missing features - mark more modules as not available
* gh-90473: Misc test fixes for WASI (GH-93218)Christian Heimes2022-05-251-3/+6
| | | | | | | | * ``sys.executable`` is not set * WASI does not support subprocess * ``pwd`` module is not available * WASI checks ``open`` syscall flags more strict, needs r, w, rw flag. * ``umask`` is not available * ``/dev/null`` may not be accessible
* gh-92550: Fix pathlib.Path.rglob() for empty pattern (GH-92604)Serhiy Storchaka2022-05-111-0/+5
|
* Revert "gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)" ↵Serhiy Storchaka2022-05-111-0/+17
| | | | | (GH-92598) This reverts commit dcdf250d2de1428f7d8b4e9ecf51d2fd8200e21a.
* gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)Gregory P. Smith2022-05-101-23/+1
| | | Co-authored-by: Barney Gale <barney.gale@gmail.com>
* gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)Barney Gale2022-05-101-17/+0
| | | | | | | We could try to remedy this by taking a slice, but we then run into an issue where the empty string will match altsep on POSIX. That rabbit hole could keep getting deeper. A proper fix for the original issue involves making pathlib's path normalisation more configurable - in this case we want to retain trailing slashes, but in other we might want to preserve `./` prefixes, or elide `../` segments when we're sure we won't encounter symlinks. This reverts commit ea2f5bcda1a392804487e6883be89fbad38a01a5.
* bpo-22276: Change pathlib.Path.glob not to ignore trailing path separator ↵Eisuke Kawashima2022-04-281-0/+17
| | | | | | | (GH-10349) Now pathlib.Path.glob() **only** matches directories when the pattern ends in a path separator. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-91616: re module, fix .fullmatch() mismatch when using Atomic Grouping or ↵Ma Lin2022-04-191-1/+8
| | | | | | | | | Possessive Quantifiers (GH-91681) These jumps should use DO_JUMP0() instead of DO_JUMP(): - JUMP_POSS_REPEAT_1 - JUMP_POSS_REPEAT_2 - JUMP_ATOMIC_GROUP
* bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-31791)Christian Heimes2022-03-101-0/+11
| | | | | | | - fd inheritance can't be modified because Emscripten doesn't support subprocesses anyway. - setpriority always fails - geteuid no longer causes problems with latest emsdk - umask is a stub - geteuid / getuid always return 0, but process cannot chown to random uid.