Skip to content

Commit 159ebcf

Browse files
committed
add tests for cli bag creation
1 parent 403f4e8 commit 159ebcf

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

test.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,33 @@ def test_valid_full_validate(self):
12601260
)
12611261

12621262
def test_failed_create_bag(self):
1263-
# assert exit code 1
1264-
# assert failure message
1265-
return False
1263+
os.chmod(self.tmpdir, 0)
1264+
1265+
testargs = ["bagit.py", self.tmpdir]
1266+
1267+
with self.assertLogs() as captured:
1268+
with self.assertRaises(SystemExit) as cm:
1269+
with mock.patch.object(sys, 'argv', testargs):
1270+
bagit.main()
1271+
1272+
self.assertEqual(cm.exception.code, 1)
1273+
self.assertIn(
1274+
"Failed to create bag in %s" % self.tmpdir,
1275+
captured.records[-1].getMessage()
1276+
)
12661277

12671278
def test_create_bag(self):
1268-
# assert exit code 0
1269-
# assert creation message
1270-
return False
1279+
testargs = ["bagit.py", self.tmpdir]
1280+
1281+
with self.assertLogs() as captured:
1282+
with self.assertRaises(SystemExit) as cm:
1283+
with mock.patch.object(sys, 'argv', testargs):
1284+
bagit.main()
1285+
1286+
for rec in captured.records:
1287+
print(rec.getMessage())
1288+
1289+
self.assertEqual(cm.exception.code, 0)
12711290

12721291

12731292
class TestUtils(unittest.TestCase):

0 commit comments

Comments
 (0)