From 9762c9e30eeb6adc6815b25ad619432f707d4632 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 17 Feb 2025 20:20:02 +1100 Subject: [PATCH 1/4] Test unexpected end of tar file --- Tests/test_file_tar.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index 49220a8b6..d1a4ca9de 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -1,6 +1,7 @@ from __future__ import annotations import warnings +from pathlib import Path import pytest @@ -29,6 +30,16 @@ def test_sanity(codec: str, test_path: str, format: str) -> None: assert im.format == format +def test_unexpected_end(tmp_path: Path) -> None: + tmpfile = str(tmp_path / "temp.tar") + with open(tmpfile, "w"): + pass + + with pytest.raises(OSError): + with TarIO.TarIO(tmpfile, "test"): + pass + + @pytest.mark.skipif(is_pypy(), reason="Requires CPython") def test_unclosed_file() -> None: with pytest.warns(ResourceWarning): From 152d982644f4474d14597b4cba878903db400a67 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 17 Feb 2025 20:20:45 +1100 Subject: [PATCH 2/4] Test missing subfile --- Tests/test_file_tar.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index d1a4ca9de..e1a6a55d7 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -40,6 +40,12 @@ def test_unexpected_end(tmp_path: Path) -> None: pass +def test_cannot_find_subfile(tmp_path: Path) -> None: + with pytest.raises(OSError): + with TarIO.TarIO(TEST_TAR_FILE, "test"): + pass + + @pytest.mark.skipif(is_pypy(), reason="Requires CPython") def test_unclosed_file() -> None: with pytest.warns(ResourceWarning): From 017b16b803347bceb19361230c751267fab6e660 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Mon, 17 Feb 2025 21:48:09 +1100 Subject: [PATCH 3/4] Removed argument Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Tests/test_file_tar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index e1a6a55d7..9fc3edcd7 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -40,7 +40,7 @@ def test_unexpected_end(tmp_path: Path) -> None: pass -def test_cannot_find_subfile(tmp_path: Path) -> None: +def test_cannot_find_subfile() -> None: with pytest.raises(OSError): with TarIO.TarIO(TEST_TAR_FILE, "test"): pass From 19010bb301e559dd6c9b255c9e3134bbde31297f Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Mon, 17 Feb 2025 21:49:08 +1100 Subject: [PATCH 4/4] Use match Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Tests/test_file_tar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index 9fc3edcd7..084d0f288 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -35,13 +35,13 @@ def test_unexpected_end(tmp_path: Path) -> None: with open(tmpfile, "w"): pass - with pytest.raises(OSError): + with pytest.raises(OSError, match="unexpected end of tar file"): with TarIO.TarIO(tmpfile, "test"): pass def test_cannot_find_subfile() -> None: - with pytest.raises(OSError): + with pytest.raises(OSError, match="cannot find subfile"): with TarIO.TarIO(TEST_TAR_FILE, "test"): pass