def test_init_member_bags3(self): # test when the amendment happens to be head-bag conformant self.amendee = os.path.join(self.tempdir, "gooberbag") src = os.path.join(datadir, "samplembag", "data") shutil.copytree(src, self.amendee) bagit.make_bag(self.amendee) amend.make_single_multibag(self.amendment) self.amender = amend.Amender(self.amendee, self.amendment) membagsfile = os.path.join(self.amender._newheaddir, "multibag", "member-bags.tsv") self.assertTrue(os.path.exists(membagsfile)) self.amender._init_member_bags() self.assertTrue(not os.path.exists(membagsfile)) self.assertEqual(self.amender._newhead.member_bag_names, ["gooberbag"])
def test_make_single_multibag(self): mbdir = os.path.join(self.bagdir, "multibag") mbfile = os.path.join(mbdir, 'member-bags.tsv') flfile = os.path.join(mbdir, 'file-lookup.tsv') bagn = os.path.basename(self.bagdir) self.assertTrue(not os.path.exists(mbdir)) amend.make_single_multibag(self.bagdir, "1.5", "doi:XXXX/11111") self.assertTrue(os.path.exists(mbdir)) # test for member-bags.tsv self.assertTrue(os.path.exists(mbfile)) with open(mbfile) as fd: lines = fd.readlines() self.assertEqual(len(lines), 1) parts = lines[0].strip().split("\t") self.assertEqual(parts[0], bagn) self.assertEqual(parts[1], "doi:XXXX/11111") # test for file-lookup.tsv self.assertTrue(os.path.exists(flfile)) with open(flfile) as fd: lines = fd.readlines() self.assertIn("data/trial1.json\t" + bagn + "\n", lines) self.assertIn("data/trial2.json\t" + bagn + "\n", lines) self.assertIn("data/trial3/trial3a.json\t" + bagn + "\n", lines) self.assertNotIn("metadata/pod.json\t" + bagn + "\n", lines) self.assertNotIn("about.txt\t" + bagn + "\n", lines) self.assertEqual(len(lines), 3) # test info tag data bag = bagit.Bag(self.bagdir) self.assertEqual(bag.info.get('Multibag-Version'), amend.CURRENT_VERSION) self.assertEqual(bag.info.get('Multibag-Head-Version'), "1.5") self.assertEqual(bag.info.get('Multibag-Reference'), amend.CURRENT_REFERENCE) self.assertEqual(bag.info.get('Multibag-Tag-Directory'), "multibag") self.assertTrue( isinstance(bag.info.get('Internal-Sender-Description'), list)) self.assertEqual(len(bag.info.get('Internal-Sender-Description')), 2) self.assertIn("Multibag-Reference", bag.info.get('Internal-Sender-Description')[1]) self.assertEqual(bag.info['Bag-Size'], "5.171 kB")
def test_init_file_lookup3(self): # test when the amendment happens to be head-bag conformant self.amendee = os.path.join(self.tempdir, "gooberbag") src = os.path.join(datadir, "samplembag", "data") shutil.copytree(src, self.amendee) bagit.make_bag(self.amendee) amend.make_single_multibag(self.amendment) self.amender = amend.Amender(self.amendee, self.amendment) lufile = os.path.join(self.amender._newheaddir, "multibag", "file-lookup.tsv") self.assertTrue(os.path.exists(lufile)) self.amender._init_file_lookup() self.assertTrue(not os.path.exists(lufile)) self.assertEqual(self.amender._newhead.lookup_file("data/trial1.json"), "gooberbag")