Skip to content

Commit 59fafee

Browse files
committed
Update exception messages in tests
1 parent 46745d0 commit 59fafee

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

test.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,44 +641,62 @@ def test_make_bag_with_unreadable_source(self):
641641
bagit.make_bag(self.tmpdir, checksum=["sha256"])
642642

643643
self.assertEqual(
644-
"Missing permissions to move all files and directories",
644+
"Cannot read the source directory %s. Read permissions are "
645+
"required to find files" % self.tmpdir,
645646
str(error_catcher.exception),
646647
)
647648

648649
def test_make_bag_with_unreadable_subdirectory(self):
649650
# We'll set this write-only to exercise the second permission check in make_bag:
650-
os.chmod(j(self.tmpdir, "loc"), 0o200)
651+
dir_path = j(self.tmpdir, "loc")
652+
os.chmod(dir_path, 0o200)
651653

652654
with self.assertRaises(bagit.BagError) as error_catcher:
653655
bagit.make_bag(self.tmpdir, checksum=["sha256"])
654656

655657
self.assertEqual(
656-
"Read permissions are required to calculate file fixities",
658+
"Cannot read the sub-directory %s. Read permissions are required "
659+
"to find files" % dir_path,
657660
str(error_catcher.exception),
658661
)
659662

660663
def test_make_bag_with_unwritable_source(self):
661-
path_suffixes = ("", "loc")
664+
# 500 is write + execute
665+
os.chmod(self.tmpdir, 0o500)
662666

663-
for path_suffix in reversed(path_suffixes):
664-
os.chmod(j(self.tmpdir, path_suffix), 0o500)
667+
with self.assertRaises(bagit.BagError) as error_catcher:
668+
bagit.make_bag(self.tmpdir, checksum=["sha256"])
669+
670+
self.assertEqual(
671+
"Cannot write to the source directory %s. Write permissions "
672+
"are required to move files within the bag" % self.tmpdir,
673+
str(error_catcher.exception),
674+
)
675+
676+
def test_make_bag_with_unwritable_subdirectory(self):
677+
# 400 is read-only
678+
dir_path = j(self.tmpdir, "loc")
679+
os.chmod(dir_path, 0o400)
665680

666681
with self.assertRaises(bagit.BagError) as error_catcher:
667682
bagit.make_bag(self.tmpdir, checksum=["sha256"])
668683

669684
self.assertEqual(
670-
"Missing permissions to move all files and directories",
685+
"Cannot write to the sub-directory %s. Write permissions are "
686+
"required to move files within the bag" % dir_path,
671687
str(error_catcher.exception),
672688
)
673689

674690
def test_make_bag_with_unreadable_file(self):
675-
os.chmod(j(self.tmpdir, "loc", "2478433644_2839c5e8b8_o_d.jpg"), 0)
691+
file_path = j(self.tmpdir, "loc", "2478433644_2839c5e8b8_o_d.jpg")
692+
os.chmod(file_path, 0)
676693

677694
with self.assertRaises(bagit.BagError) as error_catcher:
678695
bagit.make_bag(self.tmpdir, checksum=["sha256"])
679696

680697
self.assertEqual(
681-
"Read permissions are required to calculate file fixities",
698+
"Cannot read the file %s. Read permissions are required to "
699+
"calculate file fixities" % file_path,
682700
str(error_catcher.exception),
683701
)
684702

@@ -834,13 +852,15 @@ def test_save_bag_to_unwritable_directory(self):
834852
def test_save_bag_with_unwritable_file(self):
835853
bag = bagit.make_bag(self.tmpdir, checksum=["sha256"])
836854

837-
os.chmod(os.path.join(self.tmpdir, "bag-info.txt"), 0)
855+
file_path = j(self.tmpdir, "bag-info.txt")
856+
os.chmod(file_path, 0)
838857

839858
with self.assertRaises(bagit.BagError) as error_catcher:
840859
bag.save()
841860

842861
self.assertEqual(
843-
"Read permissions are required to calculate file fixities",
862+
"Cannot read the file %s. Read permissions are required to "
863+
"calculate file fixities" % file_path,
844864
str(error_catcher.exception),
845865
)
846866

0 commit comments

Comments
 (0)