From a913e014f70cbce5e4308ff9e836a738b9ef659f Mon Sep 17 00:00:00 2001 From: Nathan <95725385+treefern@users.noreply.github.com> Date: Wed, 11 Sep 2024 06:27:17 +0000 Subject: [PATCH] NPI-3501 updated unit tests for path2bytes, adding a test for empty file exceptions (which was the initial motivation for this whole branch). --- tests/test_common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_common.py b/tests/test_common.py index fc0a237..01ccd82 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -38,7 +38,7 @@ def setUp(self): self.setUpPyfakefs() def test_file_not_found_and_file_read(self): - # Create a file, but not the one we're looking for + # Create a mock file, but not the one we're looking for self.fs.create_file("testfile.txt", contents=b"hello") with self.assertRaises(FileNotFoundError): path2bytes("nonexistent.txt") @@ -46,6 +46,13 @@ def test_file_not_found_and_file_read(self): # Now open the file that does exist and check the contents self.assertEqual(path2bytes("testfile.txt"), b"hello") + def test_empty_file_exception(self): + # Create a mock empty file + self.fs.create_file("emptyfile.txt", contents=b"") + # We raise EOFError for empty files, and (valid) compressed files that expand to a zero-length output + with self.assertRaises(EOFError): + path2bytes("emptyfile.txt") + def test_invalid_archive_expand_exception(self): # Test that trying to unpack an archive file which isn't valid archive data, raises an exception self.fs.create_file("invalidarchive.gz", contents=b"hello")