From 26584a2daef6ce8d4a30d9a748efc6f976dfbda5 Mon Sep 17 00:00:00 2001 From: David Baird Date: Fri, 28 Aug 2026 00:05:59 +0000 Subject: [PATCH 1/6] Fix os.ftruncate support in pyfakefs. See [#1331](https://github.com/jmcgeheeiv/pyfakefs/issues/1331) --- .vscode/launch.json | 10 ++++++++++ CHANGES.md | 6 ++++++ pyfakefs/fake_os.py | 7 +++---- pyfakefs/tests/fake_os_test.py | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..9dae3d44 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + + ] +} \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index 7ca209de..4572041b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,9 @@ The released versions correspond to PyPI releases. * fixed a crash if the stack limit was set to a low value (see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313)) +* fixed `os.ftruncate` to inspect the `FakeFileWrapper` returned by + `get_open_file(fd)` + (see [1331][https://github.com/pytest-dev/pyfakefs/issues/1331]) ## [Version 6.2.0](https://pypi.python.org/pypi/pyfakefs/6.2.0) (2026-04-12) @@ -1726,3 +1729,6 @@ There are no release notes for releases 2.6 and below. The following versions ar * [1.1](https://pypi.python.org/pypi/pyfakefs/1.1), [1.2](https://pypi.python.org/pypi/pyfakefs/1.2), [2.0](https://pypi.python.org/pypi/pyfakefs/2.0), [2.1](https://pypi.python.org/pypi/pyfakefs/2.1), [2.2](https://pypi.python.org/pypi/pyfakefs/2.2), [2.3](https://pypi.python.org/pypi/pyfakefs/2.3) and [2.4](https://pypi.python.org/pypi/pyfakefs/2.4) + + +[def]: https://github.com/pytest-dev/pyfakefs/issues/1331 \ No newline at end of file diff --git a/pyfakefs/fake_os.py b/pyfakefs/fake_os.py index 3c3edc03..25764439 100644 --- a/pyfakefs/fake_os.py +++ b/pyfakefs/fake_os.py @@ -1019,11 +1019,10 @@ def ftruncate(self, fd: int, length: int) -> None: Raises: OSError: if the file descriptor is invalid """ - file_object = self.filesystem.get_open_file(fd).get_object() - if isinstance(file_object, FakeFileWrapper): - file_object.size = length - else: + file_handle = self.filesystem.get_open_file(fd) + if not isinstance(file_handle, FakeFileWrapper): self.filesystem.raise_os_error(errno.EBADF) + file_handle.get_object().size = length def access( self, diff --git a/pyfakefs/tests/fake_os_test.py b/pyfakefs/tests/fake_os_test.py index d9232598..104c0e58 100644 --- a/pyfakefs/tests/fake_os_test.py +++ b/pyfakefs/tests/fake_os_test.py @@ -2974,7 +2974,7 @@ def test_ftruncate(self): self.create_file(file_path, contents="0123456789012345") fd = self.os.open(file_path, os.O_RDWR) - self.os.truncate(fd, 10) + self.os.ftruncate(fd, 10) self.assertEqual(10, self.os.stat(file_path).st_size) with self.open(file_path, encoding="utf8") as f: self.assertEqual("0123456789", f.read()) From d67a3f99f8f9325fe168c8bbc714bef36286052a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Aug 2026 00:08:26 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .vscode/launch.json | 4 ++-- CHANGES.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9dae3d44..45157749 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - + ] -} \ No newline at end of file +} diff --git a/CHANGES.md b/CHANGES.md index 4572041b..19af12ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1731,4 +1731,4 @@ There are no release notes for releases 2.6 and below. The following versions ar and [2.4](https://pypi.python.org/pypi/pyfakefs/2.4) -[def]: https://github.com/pytest-dev/pyfakefs/issues/1331 \ No newline at end of file +[def]: https://github.com/pytest-dev/pyfakefs/issues/1331 From 84da0cd0d6734d77a2a7e0262a859ce4f6617535 Mon Sep 17 00:00:00 2001 From: David Baird Date: Thu, 27 Aug 2026 17:14:47 -0700 Subject: [PATCH 3/6] Fix issue number formatting in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 19af12ab..ab7fc97d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,7 +17,7 @@ The released versions correspond to PyPI releases. (see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313)) * fixed `os.ftruncate` to inspect the `FakeFileWrapper` returned by `get_open_file(fd)` - (see [1331][https://github.com/pytest-dev/pyfakefs/issues/1331]) + (see [#1331][https://github.com/pytest-dev/pyfakefs/issues/1331]) ## [Version 6.2.0](https://pypi.python.org/pypi/pyfakefs/6.2.0) (2026-04-12) From 1440e24823e12dfedf0ea9d9403b4d53f13351b3 Mon Sep 17 00:00:00 2001 From: David Baird Date: Thu, 27 Aug 2026 17:16:00 -0700 Subject: [PATCH 4/6] Clean up CHANGES.md by removing blank lines Removed unnecessary blank lines and a reference link from CHANGES.md. --- CHANGES.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ab7fc97d..bc5bafb5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1729,6 +1729,3 @@ There are no release notes for releases 2.6 and below. The following versions ar * [1.1](https://pypi.python.org/pypi/pyfakefs/1.1), [1.2](https://pypi.python.org/pypi/pyfakefs/1.2), [2.0](https://pypi.python.org/pypi/pyfakefs/2.0), [2.1](https://pypi.python.org/pypi/pyfakefs/2.1), [2.2](https://pypi.python.org/pypi/pyfakefs/2.2), [2.3](https://pypi.python.org/pypi/pyfakefs/2.3) and [2.4](https://pypi.python.org/pypi/pyfakefs/2.4) - - -[def]: https://github.com/pytest-dev/pyfakefs/issues/1331 From 4fde59f4946a8162e217b8c637bd87158bdc21cf Mon Sep 17 00:00:00 2001 From: David Baird Date: Thu, 27 Aug 2026 17:18:47 -0700 Subject: [PATCH 5/6] Delete .vscode/launch.json --- .vscode/launch.json | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 45157749..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - - ] -} From de7e17d0f014ed4cf9dd5cd96923aca30d543dfa Mon Sep 17 00:00:00 2001 From: David Baird Date: Thu, 27 Aug 2026 17:22:55 -0700 Subject: [PATCH 6/6] Fix markdown link formatting in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index bc5bafb5..c145fa86 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,7 +17,7 @@ The released versions correspond to PyPI releases. (see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313)) * fixed `os.ftruncate` to inspect the `FakeFileWrapper` returned by `get_open_file(fd)` - (see [#1331][https://github.com/pytest-dev/pyfakefs/issues/1331]) + (see [#1331](https://github.com/pytest-dev/pyfakefs/issues/1331)) ## [Version 6.2.0](https://pypi.python.org/pypi/pyfakefs/6.2.0) (2026-04-12)