Skip to content

Commit

Permalink
NPI-3501 updated unit tests for path2bytes, adding a test for empty f…
Browse files Browse the repository at this point in the history
…ile exceptions (which was the initial motivation for this whole branch).
  • Loading branch information
treefern committed Sep 11, 2024
1 parent 20daa6d commit a913e01
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ 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")

# 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")
Expand Down

0 comments on commit a913e01

Please sign in to comment.